Tag Info

New answers tagged

0

It turns out that the scaling was being corrupted/altered elsewhere, so it was unrelated to the problem I believed it to be. The code above is, for all intents and purposes, correct.


0

sizeof(T*) is the size of a pointer, not the size of whatever sequence of objects it points to. If you want the number of elements of an array, either use a macro at the place where it's still an array, use a more friendly array type (std::array), or template it: template <typename T, size_t N> size_t array_count(T const (&)[N]) { return N; }


0

Well if you don't want to use A* for some reason, try "Dijkstra’s algorithm" or "Greedy best first search".


7

A* would work fine for this task, but since your map is small, Breadth First Search would work too, and it's even simpler than A*. These are “graph search” algorithms, which require you to tell them what the allowed moves are. They are not limited to grids. In your case you would tell it that the allowed moves from (x,y) are to (x+1,y-1), (x+1,y), and ...


0

First of all Do not use that deprecated library ( unless you know why you r using it eg. For assignments) You want fast graphics but the problem here is the old drivers used on a modern machine. For the fast rendering you should prefer either directx(only on windows) or opengl(available on multiple platforms). If you choose to use opengl then go to ...


0

a* will work fine. In the selection of neighbor cells consider forward, forward_up, forward_down


1

A* will certainly work for this. Linked below is an excellent tutorial on how to implement it. 1) Add the starting square (or node) to the open list. 2) Repeat the following: a) Look for the lowest F cost square on the open list. We refer to this as the current square. b) Switch it to the closed list. c) For each of the 8 squares adjacent to this ...


-2

I came up with this now: atomic<bool> ready; // true when thread is done atomic<bool> swap; // true when buffers are swapped void thread(){ while(1){ // calculate stuff here ready = true; while(ready); } } void mainloop(){ while(1){ // draw stuff here if(ready){ swap = !swap; ...


1

You could try putpixel (void putpixel(int x, int y, int color)) Although I'm not really sure that's going to be fast enough. You're using <graphics.h> which is a very old library designed for when many computers were running DOS and had resolutions like 320x200 - a quarter of your target. On Windows it would be using GDI under the hood, not exactly ...


0

Lets say player is at origin, and you have (any convex shape should work) your inner-most hexagon defined as array vec2 shape[6]. The simplest algorithm would be: int windingsNo; //=some value const int vertexCount = 6; vec2 shape[vertexCount]; float scale = 1.f; for(int w = 0; w < windingsNo; w++) { for(int v = 0; v < vertexCount; v++) { ...


5

Best practices: One central loop in main / rendering thread which also handles sound, network buffering etc. - basically, this centralises communication with OS and other threads. All processor-intensive tasks (for example, mesh building, AI, physics) may be submitted ad-hoc, in bite-sized work units, to existing worker threads. These threads are kept ...


2

I've been implementing some very similar collide-and-slide collision detection and resolution. http://metareal.net/blog/wp-content/uploads/2015/08/2015-08-21.jpg The main key I found was to handle X and Y separately. So, your code might be modified something like this (a little freeform but you should get the idea): // step 1, modify X prevX = x; x += ...


1

I found this tutorial on the OpenGL wiki a month ago. It explains the basics of skeletal animations; but I hope it is good enough for what you are trying to do, if not, you can also search skeletal animation opengl on google, because there is much more on the opengl wiki about this topic.


3

Your struct is likely being padded by the compiler. The only guarantee offered by a struct is that its members will be sequential in the order they are declared. Compilers are free to add as much or as little padding as they like. C and C++ contain a handy macro for determining offsets within structs. I'd recommend using it rather than manually working out ...


0

The main purpose of the ECS pattern is to be programmer friendly, not speed. So this is essentially an architecture problem, although I will also address your cache-friendliness concerns. It seems like you're setting your components up like data records, whereas they should contain all the relevant behavior for their subject. Think PhysicsComponent ...


1

You can basically start leaning to program by making games. To learn game-specific programming knowledge you must make games. There is no grand preparation ceremony you must complete before you can make games. Like any other skill, it's all just practice and repetition. Make games. Make lots of little games. Don't start with a big project or grand idea. ...


0

SDL doesn't provide typical App GUI affordances. (It does have SDL_ShowSimpleMessageBox() and SDL_ShowMessageBox() which are probably only useful for reporting a startup error or a crash, or system advisories.) You could either mix-in some platform-specific bits as @wondra suggests (quick and done!), or use an abstraction layer which caters more ...


2

If you don't use OpenGl library that does not implement open/save file dialog, you can avoid a lot of work(rendering text, folder browsing etc.) by using platform-specific code as your editor will likely run on single system anyway. Just ask you OS do it - quick, "cheap" and easy. Similar question was answered here for linux.


-1

I fixed it with: glOrtho(0, width, height, 0, 0, 1);


3

Use several constant buffers and group variables together based on how often they change. If your variables are fairly static ( or just huge ) you may be better off converting values into a texture and extracting them in the shader.


0

StretchRect function does not execute the pixel shader. Instead: Set up your render target and draw a polygon to cover the entire screen. This is the common way to perform a "full screen shader" pass. Anecdotally, My personal recommendation is to investigate the Compute Shader.


2

The other answers already mention that you're getting a dangling pointer and should return the strings. But reading shaders from a file, really comes down to putting the whole file into a string. Here's one way to do it: // Read shader file into one string std::string shaderSource; if ( !readFileIntoString( shaderFileName, shaderSource ) ) { return ...


1

You could re-order your std::vector<Object> by creating a function that sort it by Y position of your objects void SortObjects() { std::sort(Object.begin(), Object.end(), CompareYAxis); } bool CompareYAxis(const Object first, const Object second) { //Do the comparison here } I think this would work.


1

const char* vertex_shader = load_shader("test.vert").c_str(); const char* fragment_shader = load_shader("test.frag").c_str(); will result in dangling pointers (with undefined behavior if you dereference it), after you assign the char* to the variable the temp std::string (and backing array you just got a pointer to) gets deleted. const std::string ...


6

You are using pointers to data inside a temporary object: const char* vertex_shader = load_shader("test.vert").c_str(); const char* fragment_shader = load_shader("test.frag").c_str(); Which means both vertex_shader and fragment_shader are pointing to invalid memory, since the strings returned by load_shader get destroyed at the end of each statement. ...


3

I can give one small piece of advice. Don't do this in your render loop: viewMat = getUniformLocation(sp, "viewMat"); modelMat = getUniformLocation(sp, "modelMat"); projMat = getUniformLocation(sp, "projMat"); maxIterLoc = getUniformLocation(sp, "maxIterations"); centerLoc = getUniformLocation(sp, "center"); scaleLoc = getUniformLocation(sp, "scale"); ...


7

Out of curiosity (and peace of the mind...) I wondered how DirectX decides which attribute from a struct corresponds to the right variable inside an HLSL cbuffer-register(x) (apart from the order/type they are declared with). Purely through memory layout. You give D3D a pointer to a chunk of memory which you claim to be organized in a certain ...


1

My assumption based on my experiences with shader reflection in DX11 is that it's mapped by name. If you check out the DX11 shader reflection API you'll see that there is a D3D11_SHADER_VARIABLE_DESC struct that you can rip from the shader. Notice the LPCSTR for the name of the variable. OpenGL also handles variable mapping by name. Of course the best way ...


2

There's nothing particularly inelegant or "unclean" about what you're doing already (toggling every frame), especially if you're also using a fixed framerate. If you're not using a fixed framerate, you may want to consider a slight change to toggle the sprite visibility based on elapsed real-time instead, as this will ensure a more consistent flicker rate ...


0

You are correct that you cannot take the same window with the same GL context and change between fullscreen and windowed. What I have done is set up my rendering system (and input, etc...) to generically set itself up, and extended that slightly to allow it to re-set itself up without leaking memory. So when the application first launches, everything is ...


2

For those unfamiliar with the concept, the proper term is sprite flickering. Old consoles like the NES could only display a certain number of sprites simultaneously, so to work around this limit and show more sprites, games would show them on alternating frames. Your solution can get quite complex if you want to properly emulate the effect, that is, ensure ...


0

Basically its what @DanielHolst said, you can use negative coords and expand in all directions. As for storing your loaded chunks for fast access and checking you could use std::unordered_map, Just #include <unordered_map>, then your code looks something like this: std::unordered_map< std::pair< int, int >, Chunk* > ChunkMap; // For ...


0

To expand @Alexandre Vaillancourt answer, I would even consider using a collection that keeps your data sorted, instead of re-sorting it every frame. struct Drawable_compare { bool operator() (const IDrawable& d1, const IDrawable& d2) const{ return d1.y < d2.y; } }; class Renderer { private: std::multiset<IDrawable*, ...


1

I would forget right away the option to create the sprites in order based on their y coordinate as it will create a hell for you because it's not a flexible design. You look like you need a common way to handle the drawing process. You can achieve this using polymorphism. I would probably create a IDrawable interface, which requires children to have ...


1

A straightforward approach could be to produce a folder which contains always the same executable, copied, and different files next to it. The executable would look for data files relative to itself. .../MyNewThing/ MyNewThing.exe <-- renamed but identical resources/ <-- files with known names or name-patterns MyNewThing.data <-- ...


2

There are additional alignment and layout rules for constant buffers. The float3 probably needs padding on the CPU side to get the right stride. Roughly paraphrased, things need to be on 16-byte boundaries.


1

I had the reciprocal of what I should have been using. The math.h class's sin and cos function want the arguments in radians and m_ShipAngle is in Degrees. I was doing movementX = m_ShipVel * (cos(m_ShipAngle * 180 / PI)); movementY = m_ShipVel * (sin(m_ShipAngle * 180 / PI)); When I should have been doing: movementX = m_ShipVel * ...


1

Well, If you did a basic google search, you would find lots of answers to your question. Here is a good website to answer your question, straight from SFML itself: SFML and Code::Blocks This is based off of windows, but I'm sure it will work for all platforms. Hope this helps.


1

How about this algorithm? It also provide a smooth movement. First declare the animaton speed and the previous position of the sprite (where it should go after the mouse release): float Speed = 0.1f; //animation speed, adjust as you like Vector2 TargetPos; //The previous position of the sprite or just the position where the sprite should move after mouse ...


1

If you have to handle a large set of keys have a look at: SDL_GetKeyState which gives you a snapshot of the state of the whole keyboard.


2

Here is a list of all known SFML bindings. I work now for a few years with SFML but I've never heard about something like a web binding for browsers. If you are new to SFML and c++ you can probably look a bit arround and search for the best language/graphic libary which fit perfectly in your needs.


0

How about using Set Theory to model your data as relations (this is easy with any relational database, or any language/library support for sets and tuples): Imagine a relation killed_by(a, b) where a and b are both members of the set of all living things. character_x_is_dead when there exists any solution to killed_by(?, b). You could store this on disk or ...


0

tl;dr You have rooms, you need "keep an eye on them" by saving them and their contents (NPCs / items) to your sqlite. Each room has entities that can be in different states, you need possibly a simple Enum to save those states, the one row per entity can "remember" that entities state for you. Elaborate answer: You are mixing two things together. One is ...


1

You have two initial options: to hard-code the conditions or to use scripts. Hard-coding is quick and great for prototypes, but it allows 0 flexibility. I expect your game to out-grow this very quickly. Using a script takes more time to get started because you need a script file parser first. Apart from proven scripting languages like LUA, you can devise ...


1

I would express the direction of the ball in an angle. The curve would increase that angle each timestep until a wall or a racket is hit. A quick pseudo-code to give you an idea of what I mean: Update(float deltatime) { direction+=curveangle*deltatime; position.x += cos(direction)*velocity*deltatime; position.y += ...


-1

I'd say give up Unity (as I did) and learn modern OpenGL (3.0-4.0) which is hard to learn but C++ friendly, and it gives you an extremely valuable experience with 3D graphics. Unity might seem powerful for the easy graphics/cross-platform, but developing on it is like trying to run with knives in both your feet, especially when it comes to coding the game. ...


0

You can use Visual Studio 2013 with Unity, you just have to download the tools package from Microsoft. Not sure if this would help with using C++ but I know that C++ works in VS and may or may not work in the VS/Unity environment. I'd recommend using VS with Unity regardless, it's much better all around. If you attach VS to Unity just make sure you ...


0

After a lot of research, I finally found the reason for this. Apparently, Fermi-based GPUs do not support DirectX12 yet. "[They] will gain support for DirectX 12 ... later this year". Hopefully, this won't take too long.


1

This is a quite known issue in box2d, the problem is that you are rendering a rectangle per Tile and in the joint of those there is a ghost vertex, you can read extensive explanation here: http://www.iforce2d.net/b2dtut/ghost-vertices As for a solution to that i solved it by creating an object layer in my tiled map and created a Polyline object that defines ...


1

It looks like Optimus is up to no good again. As long as you render to the screen connected to Intel HD, it simply would not go away, despite any changes made in control panel or device manager, or bios. Optimus tech is designed in a way that screen connected to Intel HD is always linked to the framebuffer of Intel HD card. 'Real' NVidia GPU is only ...



Top 50 recent answers are included