Tag Info

New answers tagged

0

I am not sure I'm getting the question, but to me it breaks down like this; You have some grid-based map You have a path traversing the map from one point to another Given the path in 2, you want to fill all grid cells above with color A, and all below with color B. I would do that by traversing the path and for each node/grid-cell along the path ...


0

Looks to me its some kind of timer function that returns the time elapsed since the start of program. As for how to shoot missiles at set intervals, you do this: give your object a cooldown property; On update step: cooldown -= dt; if (cooldown <= 0) { shootMissile(); cooldown = missileCooldown; }


1

The problem was inside present parameters - i forgot to set backbuffer's width and height. dx_PresParams.Windowed = TRUE; dx_PresParams.SwapEffect = D3DSWAPEFFECT_DISCARD; dx_PresParams.BackBufferFormat = D3DFMT_UNKNOWN; dx_PresParams.BackBufferWidth = 1024;//Width dx_PresParams.BackBufferHeight = 1024;//Height dx_PresParams.EnableAutoDepthStencil = TRUE; ...


1

You need to put your thinking level one step backward, and try to imagine that there is a different way than the quadratic solve. You can use iterative solving. This will not give you a perfect solution in all cases, but when many entities moves relative to each other with 2 or 3 contact points in average, this is the fastest and gives very good results. All ...


0

I think what is happening is this: +---+ | A | +---+ | B |P (player) +---+ (A, B are wall "blocks") When the player is attempting to walk to the top-left, and run the collision resolution with blocks A then B, this is what happens: +\--+ | A | ----- "A: You're hitting me from below! Go left!" +--\+ \P \ \ +--\+ | B \P ----- "B: You're hitting me ...


1

You need to store some c (c++) properties for the enemy to support this. You have to ask yourself: Do you want each enemy to shoot in sync? Or off sync? Do you want shooting to be at a set interval or the timing to be somewhat random? Do you want each enemy to have shooting triggered by some other event so that shooting can be turned on or ...


2

Another (albeit a little more complicated) thing you could do is have your components register for specific event types: class EventHandler { public: using EventCallback = std::function<void(SDL_Event const&)>; void register(SDL_EventType type, EventCallback callback) { _registeredCallbacks[type].push_back(callback); } void ...


3

When you run your while loop in each of your HandleInput functions, you're burning through the entire event queue up to that moment in time. So yes, whichever event handler you call first will eat all of the events. There are a few ways to handle this problem, but obviously, paramount to every possible solution, is the removal of your destructive ...


1

You are polling all the events the first time you handle them and not using all cases at that time. That will leave some untouched. Instead of having multiple event polls, have it all processed in one function. (Preferably in your main class or somewhere able to access all things needed to be updated by events)


2

SFML 2.0+ makes it even easier to load a texture; sf::Texture texLid; std::string image2="images/top.jpg"; if (!texLid.loadFromFile(image2)) { std::cout << "Could not load" << image2; char c; std::cin>>c; return false; } glEnable(GL_TEXTURE_2D);//tell OpenGL to use textures when drawing ...


1

You can use instancing and a texture atlas to combine all the draw calls into a single one. You only have a single 4 vertex VBO with the 4 corners 0,0 0,1 1,1 1,0 and an index buffer to draw them using GL_TRIANGLES. Then in a separate VBO you have the position and size of the quad (in a single vec4) and the position and size of the texture to use in the ...


3

1) Do I have to create array for each component? Yes, but a vector would be more convenient, and equally performant. 2) How can I get components using entity id if I do this? You should store the Entity ID on the components themselves. Keep your vector sorted by that ID, and then use vector::lower_bound to retrieve the components. In my own ...


7

Not really. Use vertex buffer objects. There can be perfectly efficient for large numbers of small triangles. The thing is that you don't want to make one VBO per quad, but rather few VBOs into which you stuff multiple quads.


6

This seems great, considering fast access for a component using entity id and more importantly, fast iteration over elements of array (because systems do this all the time) and fewer cache misses than if I store components in Entity or use: Have you actually measured cache misses? Are they in any way being a problem for you? Would eliminating them for ...


5

I heard that dynamic_cast is not really elegant and that is also slow. "Elegant" is the most worthless word in a programmer's vocabulary. Strike it from your lexicon. Every programmer has an utterly different idea of what "elegant" means. If you like the code and it works, why worry about if some armchair engineer on the Internet thinks it's "elegant" ...


2

It depends how often you call this function. If you call it only at start of a game and save pointers you shouldn't care about dynamic_cast. If you call this function in game loop (why?) better avoid it. But if your game is small I think `dynamic_casts' will not decrease performance significantly even if it will be called in game loop few times per frame. ...


0

No matter how I structure the code I can't figure out a logic path that doesn't involve > creating global variables in my project so the Lua helper functions can access the core > of my engine. That's basically inevitable, given the required signature of functions registered to the Lua API. Data can only get in to the scope of a free function body via ...


2

This is not exactly an answer - rather a suggestion. A lot of game developers are shifting from LUA (it is slow and it forces you to push data back and forth). For example Star Citizen is using Runtime compiled C++ (actually they use Kythera which runs RCC++). RCC++ lets you script in C++ and reload your modified code on the fly, which - I guess - would ...


1

Your template definition needs to be in the header file. More specifically: template<typename ComponentType> ComponentType* Entity::GetComponent() { for(unsigned int i = 0; i < m_components.size(); i++) { if(ComponentType* cmp = dynamic_cast<ComponentType*>(m_components[i])) { return cmp; } } return ...


1

Move the definition of Entity::GetComponent to the header, Entity.h. In general, template definitions must be put into header files. See this related question: http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file


1

Assuming the rope has no weight, this problem is about finding the lowest point of an ellipse (http://en.wikipedia.org/wiki/Ellipse ) where (PF1+PF2 == rope length) This image show how the ellipse is rotated. From there you can figure out the lowest point by tracing the ellipse with a binary search to find the lowest point. That's where the weight should ...


2

Add a BulletCheck[BulletNo] == true condition. if ((BulletX[BulletNo] >= 103 && BulletX[BulletNo] <= 103.09) && (BulletY[BulletNo] <= -38 && BulletY[BulletNo] >= -45 && BulletActive[BulletNo]) == true) { BulletActive[BulletNo] = false; TurretTrial = TurretTrial - 5.0; if (TurretTrial ...


1

This is a problem that has several solutions and optimizations to it, especially in 3d. 2d, there are fewer but still more than one "right answers". If you understand the first answer, but not this one, it has a good chance of being "Fast enough" on modern hardware there won't be a problem. Another solution is Quadtrees: ...


3

try using a multiplicative "bias" instead of additive: shadowCoordinate.z *= 0.98; If you're doing the sampling yourself rather than using the shadow comparator interpolating the shadow map helps reduce acne a lot. There shouldn't be any shadow visible behind the object as the light should not affect it with the light being completely occluded by the ...


1

Computing an exact convex decomposition of a surface S is an NP-hard problem and usually produces a high number of clusters. To overcome these limitations, the exact convexity constraint may be relaxed and an approximate convex decomposition of S is instead computed. Here, the goal is to determine a partition of the mesh triangles with a minimal number of ...


1

Why make it any harder then it needs to be? Just add a boolean to the entity state right next to the 2D position. Then during rendering you will need to offset when try depending on the tile, some logic will also depend on the true false value like line of sight calculation. But you can mostly short circuit that if you assume the amount of object like that ...


1

In my online-game that I'm tinkering on as a hobby, I plan to split the map up into tiles that have only a 2D coordinate inside each tile. The vertical coordinate for a player or NPC inside its particular tile-cube will then simply be decided by the ground level underneath it. Since each tile has arbitrary connections to other tiles in 4 directions, stairs ...


1

I'm struggling to understand what you're asking, but I'll take a shot at it. I'm assuming what you're talking about is an "area graph" or "zone graph", a concept for AI. In an area graph, parts of the map are linked logically in a sparse graph to make it easier for AI to understand what's going on. If that's the case, why not just add a 3rd coordinate to ...


1

TL;DR: process collisions Manhattan-distance style http://en.wiktionary.org/wiki/Manhattan_distance, each axis independently one-by-one (move in X, then move in Y, then in Z, rince and repeat) properly rounding each axis before processing the next. AABB / Voxel collision systems work the same way old tile-based 2D games did, you add a 3rd dimension but ...


0

What you need to do to implement sliding: 1) find the exact location of collision 2) find the normal of the collision 3) move the object to the location of collision 4) set the velocity of object opposite of the collision normal to 0; (or you need projection if you are working with non axis aligned stuff) 5) move the object again using the new adjusted ...


1

If you only have a single SDL_Renderer, it should be managed outside of the ECS code and just passed to the rendering system when you call it to render the visual data for each entity. In this way it's like you are associating your single SDL_Renderer with all renderable entities. If for some reason you had multiple, differently configured SDL_Renderer ...


0

One of the programmers on my team figured out something which is good enough for our purposes. It is not exactly the same as the output of whatever X-Com is using. We take the whole tiles given to us by the Dijkstra pathfinding algorithm on the set of tiles and start at one which we can guarantee is an edge. We define a forward direction and a perpendicular ...


0

As described here, the texture wasn't bound to the Vertex shader. Without this (@Mooseboys) The texture data was not presented to the Vertex Shader, causing NULL or zero values. Binding the texture resolved the problem.


0

Hmm... like the other answerers, I'm going to make some guesses about unclear information in the question. My assumptions: Your map is essentially 2d, and projected downward onto the walkable surface Your map is represented as a set of polygonal areas Adjacent areas share 2 (or more) vertices If that's true, one approach is to: Collect the edges of ...


1

First of all, I think the grid is pseudo-3d: 2D movement area, but create vertical lines when the height changes. Given that, check this answer, as the same principle applies.


1

Create your points so they form a solid line on a 2D plane. Walk the line starting with a point that's on ground level, for each point: If the ground is above or below the current position, add a new point, and shift the existing point and all remaining points up or down to meet the height of the ground. -Continue until all points have been touched. You ...


1

"Which of these options is better from a practical point of view?" I'll interpret the word "practical" here to be distinct from "theoretically highest performance on a computer"... At two triangles per sprite, recomputing all the vertices on the host CPU will be not that expensive, & easy to think about. Or, since all the geometries are the same (two ...


1

You aren't limited to having only one MVP per VBO. So you would not in fact need to update the VBO every frame just because you stuff all of your sprites into a single VBO. What I do is store an instance ID with each vertex, which changes only on a per-model basis, and use those instance ID's to index into a uniform array of mat4's, one for each "instance."


1

First thing you should do to save some time is eliminate the ones that can not match. To do this, calculate the smallest rect that contains the circle. Intersect that with whatever rect you think might intersect with it (loop over all of them, most likely). Two rectangles intersect if they overlap both horizontally or vertically. There are three ways an ...


0

From what I understand, you should be able to integrate the stream of haptic information from the CHAI3d or H3dApi frameworks with a DSP framework like http://aquila-dsp.org/. The 3D haptics frameworks should provide the collision detection required, without adding the complexity of another physics layer. This will generate a force effect that can drive ...


0

I took a look at a number of implementations that are all based off of this paper: http://home.arcor.de/philippe.guigue/triangle_triangle_intersection.htm Here is one that I extracted and ran with your numbers - it returns no collision. You can look at main() to see the invocation with your test numbers. I have not done any more analysis than that. Good ...


2

When drawing 2D over 3D you don't need to apply view matrix. You only need to apply the orthographic projection. Applying the view matrix dones't work because it changes the position and rotation of the objects relative to the camera you don't want that.


1

Is this actually a problem? How much overhead would you incur by allowing the same check to happen twice in these cases? It is quite possible that the check would cause a bigger overhead than it saves. If you need to eliminate double results from the final set of collisions, I suggest that you do so after you have found them. The set of actual collisions ...


5

When you say 'synthesis' do you mean pure analog/additive/FM synthesis from scratch, or would a sample-based approach be acceptable? If you can't use combinations of real-world audio samples then this is more complicated process. Trying to generate truly realistic sounds through synthesis isn't the standard way that most game/virtual instruments/sound ...


3

First, your concerns are definitely valid and this is not "premature optimization." The problem is, std::deque::insert invalidates all iterators and references, so deque is not actually useful for this. What I did to solve this problem is create a wrapper data structure around std::vector (I called it a perma_vector) that stores a vector of ...


0

You should: bind the shader with the modelview matrix for transforming the first object bind the buffer with the vertex data for the first object draw bind the shader with the modelview matrix for transforming the second object (or use the same shader and change only matrix through uniform) bind buffer with the vertex data for the second object draw ...


1

Are you always doing triangle v triangle, or could it be triangle v sphere? Regardless, I think I would break it down into two problems: collecting candidate triangles for collision detection, and the detection itself. As you point out, when you hash into multiple buckets you need to identify and reject duplicates. I have two solutions, both of which I have ...


0

I want to draw lines with user's finger touch. Following the screenshot of a CCScene I had a same project in cocos2dx. for drawing something like this you can use CCRenderTexture. RenderTexture work like a paiting canvas. you put a sprite ( imagine it as a painting brush) on somewhere on RenderTexture and call sprite->visit(). If you this visit() ...


2

The quaternion you find using your method is indeed correct. However, it’s also pretty unlikely that DirectX::XMQuaternionSlerp would behave incorrectly with such trivial input. Thus, I suspect that the thing you are doing wrong is: trusting what you see in the debugger while running potentially optimised code assuming the layout of a __mm128 would be ...


2

By design, DirectXMath returns for XMQuaternionSlerp the same result as you'd get from the following (inefficient used only for testing) scalar code: XMVECTOR ScalarQuatSlerp(XMVECTOR q1, XMVECTOR q2, float t) { // Extract the components float q1x = XMVectorGetX(q1); float q1y = XMVectorGetY(q1); float q1z = XMVectorGetZ(q1); float q1w = ...



Top 50 recent answers are included