Tag Info

Hot answers tagged

7

You'll want to use 3D picking. Here's some code I use in my game. First I cast a ray from my camera. I'm using the mouse, but if you're just using where the user is looking, you can just use the center of the window. This is that code from my camera class: public Ray GetPickRay() { int mouseX = Mouse.getX(); int mouseY = ...


6

Instead of D3DXVec3Unproject() use XMVector3Unproject(). It accpet float parameters for viewport: XMVECTOR XMVector3Unproject( [in] XMVECTOR V, [in] float ViewportX, [in] float ViewportY, [in] float ViewportWidth, [in] float ViewportHeight, [in] float ViewportMinZ, [in] float ViewportMaxZ, [in] XMMATRIX Projection, [in] XMMATRIX ...


5

The view matrix transforms from world space to view space. Your mouse is in view space and you want to transform it into world space. That's the opposite of what the view matrix does. But the solution is simple - just multiply by the inverse view matrix instead. Matrix inverseViewMatrix = Matrix.Invert(camera.ViewMatrix); Vector2 worldMousePosition = ...


4

This is known as 3D picking, and usually involves some kind of raycast from a point in screen space (the cursor position) in the camera's forward vector direction. For some Ogre tutorials, check those links: http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Intermediate+Tutorial+3 http://www.ogre3d.org/tikiwiki/ThreeDeeObjectPicking ...


4

How do you want this to behave? There are different ways to do this. A simple option is to just move the object by some fixed number of world space units for each screen space unit (pixel, say) that the mouse moves. Another option is to take the vector of mouse movement and project it onto the axis of movement through the normal projection/camera ...


3

It depends on how you implement picking. It may not matter how you draw it, because you won't be detecting a face that's been drawn already. Since it's already been sent to the graphics card, it's usually more work to get information back from the drawn image than just checking your objects directly. If you implement picking in the way I've described here, ...


3

If you want do it this way (render colors for color picking and use texture for texturing in one rendering), I think you have to use frame buffer objects or / and shaders. You can use only frame buffers but you have to render your scene twice - first use only colors and store output image (render) to frame buffer, then draw scene normally (with textures) ...


3

The technique you're looking for is called "picking" or "3D picking." There are several ways to do it; one of the more common ones is to transform a 2D point on the screen into eye space by using the inverse of the projection transformation. This will allow you to generate a ray in view space, which you can use to test for collision with the physical ...


3

When I was debugging mouse picking in my game, I had it set up to draw a line from my camera to where ever the picking function ended. It lets you know if the ray is going the right direction, and if the ray is ending too soon, or too late. In your case, I'd have it draw a line between nearPoint and farPoint. Make sure those are the rays you want. I ...


3

You can treat this as a conversion from spherical coordinates to Cartesian coordinates. Assuming the ray should have some length r, your x, y, and z components can be calculated like this: x = r * sin(mPitch) * cos(mYaw) y = r * sin(mPitch) * sin(mYaw) z = r * cos(mPitch)


3

If your hit test is really that simple, then instead of doing more complicated triangle intersection as Byte56 suggests you could do simple AABB-ray intersection test. The intersection test will tell you the point that was hit. This point in model space will lie on one of the faces (so one of X, Y, or Z will be +/-h, where h is the half-width of your ...


3

First of all, you need to attach a collider to your terrain in order to get hits from raycasts. If you're using a Terrain, it should already have a Terrain Collider attached to it. In your script you can then do something like this: // create a ray from your mouse-position Ray r = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; ...


3

I think you may be confusing some terms. Theme Hospital is diamond shaped from what I can tell. That's the shape of the tiles, not the entire world. You can shape the entire would however you like. The shape of the world would be the same as the shape of the tiles if the world was square (meaning equal width and height), but you don't need to make it that ...


2

Pardon the brevity as I'm posting from my phone. Unproject to get your ray. Transform the ray by the transpose of your view matrix to get its position in world space. Now, either: A. For each model, transform the world ray by the transpose of the model's world matrix and test the meshes for intersections, or B. Test the ray against the transformed ...


2

I recently attempted to implement picking, and this thread was invaluable in getting things to work. One problem that I ran into though is that I don't think that the accepted answer generates the right view matrix in all cases. Let me suggest an alternative for obtaining it, which is much simpler and more likely to be right - it just pulls the matrix ...


2

If you are rendering with one different single color for each pickable item, then just compare the color under the mouse against the background color.


2

This isn't a complete answer in itself, but this wouldn't fit into the comments below your question. If believe this part of the Intersects function is what should be disallowing reverse facing triangles to be given as a result: float triangleU; Vector3.Dot(ref distanceVector, ref directionCrossEdge2, out triangleU); triangleU *= inverseDeterminant; if ...


2

I ended up changing the reticle to be rendered by the game instead of the GUI. All is well now and glad my math was solid from the beginning.


2

As Steven Stadnicki suggested in his comment, and what is also suggested in a related question over at stackoverflow, just do a linear search without any hierarchy.


2

OK, so I found your problem. I don't, however, know why it's the problem. I plugged your code into mine, everything was the same except the matrices. The matrices retrieved from OpenGL did not match the ones I was generating. So, if you would, try upgrading your camera class to generate those matrices for you. There's a few functions you'll need: Matrix4f ...


2

Range picking is basically a set of intersection tests between objects and camera frustum (6 planes that together define a convex volume). If you have some frustum culling code, you can just fix it up to make it work. The easiest way is to generate point data from camera matrix (view*projection), adjust the point data by means of coordinate transforms and ...


2

It is hard to say exactly what is broken, but I can make a few suggestions. Generally, the front buffer is what is currently shown, and drawing calls that are being processed are drawn to the back buffer. Once the entire scene is rendered, the back buffer is copied to the front buffer. Therefore I think that you should read from the back buffer, because ...


2

The structures are passive data, the only difference is that the D3D11 flavor deals with floats instead of integers for most of the fields. If your quantities are integral, simply construct a corresponding D3D10_VIEWPORT and call the function.


2

Since you're using Ogre then you should probably read those ogre3d.org links, but if you want to know the math behind the intersect algorithm, here it is: http://softsurfer.com/Archive/algorithm_0104/algorithm_0104B.htm#Line-Plane%20Intersection When I do that I also use a bit from http://softsurfer.com/Archive/algorithm_0104/algorithm_0104.htm


2

Use a plane or three planes to check collision against them. If the world is empty you need to collide with something... one easy solution is setting a reference plane... usually the ground... and check ray collision against the plane to get coordinates in world space... when you work with objects in an editor, the easier is working in world ...


2

The values you'd get from glGet with GL_VIEWPORT (that you were previously passing to glUnProject) are the same values you have previously used to define the OpenGL viewport size using glViewport. If, as noted in the referenced documentation, you've never called glViewport yourself, the width and height of the viewport are the dimensions of the (client ...


2

Instead of using a collider for your terrain, you can also use a plane to perform a raycast. For example, if your grid is situated on the XZ plane, you can do something like this: static Plane XZPlane = new Plane(Vector3.up, Vector3.zero); public static Vector3 GetMousePositionOnXZPlane() { float distance; Ray ray = ...


1

How can I calculate intersection with my scene geometries? it varies depending on your performance needs and scene size, there are different approaches the easiest one is checking ray intersection with all bounding volumes containing geometry in the scene, however this may not be good enough if your scene is huge, or you have limited computational ...


1

Triangle picking aside, generally you can only have 1 texture per draw call. (Technically, I think it's effectively one shader effect per vertex buffer. If multi-texturing occurs here then it would be done by having multiple texture samplers in the shader, or by using a texture atlas) What this means is you need to split models up into parts when you want ...


1

You might want to try rendering both the snapped to grid and unsnapped positions to help you see where it's going wrong. You should also check that the near and far plane values that you're using aren't too far apart. Most notably the bigger far/near ratio is the less accuracy you'll get both for rendering and for the calculations. Having said that the ...



Only top voted, non community-wiki answers of a minimum length are eligible