New answers tagged

0

Find all triangles that intersect with the plane, split them into two polygons and triangulate the polygons. If you want a cap, enumerate all vertices generated from the slice and create a cap to fill the possibly concave planar hole. The devil is in the edge cases where you go exactly through vertices and edges, so make sure to robustly handle those.


0

The way I would do it is detect the mousex and mousey position when it is clicked and then use something like the following: if (xmouse > something AND xmouse < something_else) AND (ymouse > whatever AND ymouse < whatever_else) THEN pic_clicked = True something, something_else, whatever and whatever_else would be the x and y top, ...


1

First, this line: float dotProduct = (_one->velocity().x() * collisionNormal.y() + _one->velocity().y() * collisionNormal.x()) * remainingTime; is calculating the wrong quantity (it should be x * x + y * y). Second, if you want to slide, you simply need to set the component of the velocity parallel to the normal of the collision surface to 0, and ...


-1

Try using glCullFace( GL_BACK );


-4

#include < iostream> #include < fstream> // use to input / output files #include < stdlib.h> using namespace std ; int apple ; int input ; int main () { main: cout << "What do you want to do ! \n" ; cout << "1) add some apple \n" ; cout << "2) check the stock \n" ; cout << "3) quit ...


0

In your code you seem to assume each face consists of 3 vertices aka. triangles which doesn't have to be the case. Blender tend to prefer exporting OBJ models using quads instead. The easiest way to fix this is to tell blender to convert all quads to triangles before exporting. Just tick off "Triangulate Faces" when you export. Though you do seem to also ...


0

I am no game designer or have any qualification but I have an idea for a realistic tactical semi turn based ship to ship combat system. Ideally it would be full 3d movement but it is likely easier to explain in 2d. So you would have the area of space between the 2 ships. This is measured in light seconds. Therefore at the start lets say there is a 120 ...


2

I know it's stupid to answer my own question but... With very, very big thanks to @Ben I fixed this problem by creating SDL_Surface and load image to it once for each TextureAsset and store it inside TextureAsset instead of creating new SDL_Surface for same texture and free it each draw call.


3

R.U.B.E. does this. The feature was included with the addition of samplers since v1.6.0. This tutorial video gives a description of how it can be done. To test, I used Anko's and Xander's images for comparison. First I imported the image of the sword and heart wand into RUBE (I'm on v1.7.0) and created some samplers (shown by dashed outlines) over them. ...


2

No, you don't need to port forward the client. If the server runs on a home computer (behind a NAT) then yes, you need to port-forward the server or check out how udp-hole-punching works but if the server runs on a real server (a server you rent with a public ip-address) then it should work out of the box. Note though, the client, which is probably behind a ...


0

Give each persistent object an unique id value (an unsigned int should suffice unless the number of objects can go into billions). Use that value as the primary key* of your database table. This ensures that the database will never have two entries for the same object. I would recommend you to not use auto increment for the id and instead assign that value ...


9

I tried this. It was hard, but I did it. Left is GIMP, top-right is a Box2D debug renderer, bottom-right is a build shell Code repository for reference The full code is on github here. It's scattered in a whole lot of files, so it's a bit big to put here. See below for an explanation of the technique. How? I used ImageMagick, Potrace, Node.js ...


0

I think you're missing a bind to your index buffer. It's been a while, but I believe binding the VertexArray only affects the vertex data, not the index data. If I remove the glBindBuffer(GL_ELEMEN_ARRAY_BUFFER...) from my code, i get a black screen. glBindVertexArray(VAO); **glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);** glDrawElements(GL_TRIANGLES, 6, ...


2

If you calculate the final result as final.red = bitmap.red + viewport.red and divide by 255, then you are simply averaging them out, without taking alpha into account. The way I learned to calculate transparency is a formula that is also present in the top of the page you linked: res.r = dst.r * (1 - src.a) + src.r * src.a res.g = dst.g * (1 ...


1

One possible solution could be to use weak_ptr. A weak_ptr is like a shared_ptr, except it doesn't keep the object alive. If there are no shared_ptrs pointing to the object, it will be deleted, and then any weak_ptrs will hold NULL. You can use the lock method to get a shared_ptr from a weak_ptr. Example use: shared_ptr<Thingy> s = ...


2

Does every type returned by SDL_RegisterEvents get read as SDL_UserEvent? If so, why even bother registering more than one event when you can use the event.user.code field to differentiate between types? All the event types returned by SDL_RegisterEvents are considered "user events", yes. The code field can be used for whatever you want. Two ...


7

At the moment I'm using std::shared_ptr to support multiple ownership of GameObjects so that they are held by both the scene and any other GameObjects within the game Don't do that. shared_ptr is often the wrong tool for the job, and that certainly applies here. Remember that smart pointers are for managing ownership; shared_ptr is about sharing ...


2

I see a couple of options: Have the Scene refuse to destroy a GameObject if the ref_count of it's shared_ptr is more than 1. This will oblige your users to take a great care of what happens. This might not be very fun or practical, though. In your GameObject architecture, add a listener pattern: when GameObject A links to GameObject B, tell B that A is ...


4

While not necessarily at fault here, GetSpriteByPosition returns a pointer to a temporary returned by getDrawable. You may not return pointers or references to locals or temporaries, as they do not outlast the function they appear in. As for your error, you can divine some information from the faulting address. 0xB4 is almost zero, which usually means that ...


2

The primary thing that stands out is that your loop copy initializes the auto val loop variable with the elements as you iterate. Even though your type is reasonably small, there's a bunch of overhead in doing so and it's likely that you would gain some by going for auto& val. Of secondary concern is that you're using strings for non-textual things. ...


2

If you want to write them to the Lua file--as in the script text file itself--you'll have to do it as you would any other text file. As far as I know, Lua doesn't include any way to do this.


2

If your intention is to modify your Lua State so that your Lua script can access parameters set from C++, you need to actually set those values before calling into Lua (luaL_dofile is a helper for loading a chunk from a file, compiling it if necessary, and immediately executing it). So the following lines should be moved up just after luaL_openlibs. ...


1

SFML has a few good functions that allows you to do what you want a bit simpler window.mapPixelToCoords(sf::Mouse::getPosition(window), viewRect); That line of code will convert the mouse position relative to the window (sf::Vector2i), to a world coordinate (sf::Vector2f). I have the window as an argument there, or else it will get the mousePos relative ...


2

First off, you should really store the tiles in a 2d array. As far as I can tell from documentation, sf::View has a getViewport() method. This method gives the coordinates of the top-left point of your view. Next you will need the coordinate of the mouse, in relation to the top-left of your window. Finally, you add the two coordinates together, and you'll ...


2

Figure out your mouse position in world space and divide by the tile size. Basically keep track of where your upper left corner is in world space, add the mouse position to that (with appropriate scaling etc.) and then divide it by your tilesize.


2

One issue with your implementation is that you only check if det is smaller kEpsilon, but there is no guarantee that det is positive. You want to check if(det<kEpsilon && det>-kEpsilon) So that might explain the false positives. The way this algorithm works is by basically figuring out "when" the ray will hit the triangles plane and then ...


0

The issue turned out to be a problem with the way Wayland works. My install of Gnome was defaulting to Wayland, instead of x, and Wayland doesn't do a good job of capturing the cursor within a window.


1

A standard parametric ray equation is r(t) = p + td. The origin point is p and d is the ray direction. So, that algorithm gives you t and you know p and d already. Therefore you can compute ray (or vector) r(t), and then take its magnitude |r(t)| to obtain the distance to triangle (intersection). PS. You may need to normalize your direction vector d first. ...


0

If your biggest problem is with the Systems, switch from hand-written nodes to tuples. Then you can make some function and class templates to handle most of the work. template <typename ...ComponentTypes> class AbstractSystem { using Node = tuple<weak_ptr<ComponentTypes>...>; /* bunch of template boilerplate */ }; Though I really ...


0

Well, to me the description is a bit vague, but sounds like the main problem is with the entities/components logistics within your systems? If so, then why not just upgrade the way you build your systems? These upgrades could come in flavor of abstraction and encapsulation, where the base system class has a set of abstracted pointer-keepers, which ...


-1

This is a very broad question. I'm assuming you have seen the answer from Kieran Chandler about platform abstraction. You've mentioned the SDL Library that you want to use. I've used it myself for such a OpenGL cross-platform project. The library provides most of the platform abstraction. Use its functions for all input and output, like accessing files, ...


1

It's unclear where your issue lies. To rotate a vector about the origin, you create a rotation matrix, and then you multiply the vertex by the matrix. In order to create the rotation matrix, you need a rotation axis and an angle. With glm, you can do it this way: glm::vec3 v3RotAxis( 0.0f, 0.0f, 1.0f ); // Rotate about z+ float angleRad = ...


2

To be physical, you need to calculate friction based on the magnitude of your velocity. You can simply remove the if checks when calculating friction and store a "friction constant" instead of a "friction force." You are already essentially doing this because m_fFriction is a double and not a vector, you are just thinking about it wrong. The friction ...


0

Found the issue with my program, the algorithm was mostly right, I just had to modify my if statements when taking things on and off the closelist to include the the if statement whether it was smaller than the previous route, since we only want to take things off the close list if a better route has been found. A secondary issue popped up when I realized I ...


-1

It doesn't sound like you are ready to take on a large task like this. You need to learn about the underlying concepts and make some smaller projects before you can really move on to making a cross-platform game. The main point to make about cross-platform games is that you need to have a "Platform Abstraction Layer" which will allow your game to perform ...


3

You get the error because there is no operator*= for vec4 that takes a matrix as a parameter. It then tries to convert the matrix to a float, but just can't. To work around this, you should try to not use the operator*= and write it all in the long form: Off = Off * Util::createTransform(offset); Also, as pointed out in the comments to the OP, what you ...


0

It looks like you're using acceleration in a weird way in your engine, so I can't give you a 100% fool-proof answer you can directly implement into your code, but I can take a shot at it. You'd want to apply your friction to your current speed, not your characters acceleration. Try to change your code to this instead: if( curVel.x > 0.0f ) curVel.x ...


1

I don't want to replicate Steven's answer, but I want to include images. The correct answer is to use OnActorBeginOverlap, as you were marked to. If you are not receiving the correct triggering dispatch, it's almost sure that you don't have the correct layering configuration. You can do that using the Collision subpanel in the Details panel of your object ...


2

Your problem is this line: roomSprites[x]->setPosition(sf::Vector2f(x * 32, y * 32)); What do you think will happen in the second row? x will start at 0 again and you'll set the position of the first 10 sprites. In the third row, x will start at 0 again and you'll set the position of the first 10 sprites. See where this will end? You either have to ...


0

I finally found a solution, on this page: http://gamedevelopment.tutsplus.com/tutorials/how-to-create-a-custom-2d-physics-engine-the-basics-and-impulse-resolution--gamedev-6331 This completely elimenated both the sinking and the jitter.


0

You need to detect when the object has come to "rest" and turn off the physics (gravity included) on it until some force gets applied to it again. You'll have to pick a threshold of "rest" that's larger than most cases of vibration but small enough to let objects bounce a few times and slide a bit. How to do this exactly depends on the physics engine and ...


0

The problem is that in the constructor of your "MyCustomActor" you need to assign a RootComponent that is a SceneComponent. Typically you will see something like a ShapeComponent (SphereComponent, CylinderComponent, etc.). Then in the constructor, once you have a RootComponent defined in the actor, you need to attach the RootComponent to all other ...


2

It is likely that you have corrupted the underlying storage of your map object and the VC++ debug runtime has protection code that tests if the data structure and iterators are in a valid state to avoid more damage. Clobbering memory and other undefined behaviour can result in all sorts of amusing results. When in doubt about the semantics of something, ...



Top 50 recent answers are included