Convert coordinate to zero Z ( 2D )

Recommended Posts

Hi, i have this method for example firing bullets from some position then set the Z axis to 0.0f so all bullets will be at Z 0.0f;

It involves 4 divides, so i like to know how you would solve this without 4 divisions per coordinate.

There is something like convert 3D position to 2D screen position, then i need to convert that back from 2D screen position to 3D position at Z 0.0f;

Would that be faster, or how would you solve this problem ?

The camera in my engine is always located at position x = 0.0f;  y = 0.0f;  z = -1000.0f;

The game always located at Z position 0.0f;

By the way : do my meshes would have to big coordinates with such a big camera Z position ?

thanks

Share on other sites

The general solution for this is Vector3D * Vector3D.

So  (10, 22, 8) * (1,1,0) = (10, 22, 0).

Because a value multiplied by 1 remains the same. A value multiplied by 0 becomes 0.

Just keep a (1,1,0) to use for this.

You can also just multiply the Z with 0.

Edited by Scouting Ninja

Share on other sites

Hi, does the optical illusion also works then ?, no.

The way i have it the new X and Y position will be calculated, so it looks like exact the same spot.

Look this movie at 12:10 then u see what i mean, the bullets are all 2D while the mesh shooting is 3D

Share on other sites
On 6/13/2018 at 2:50 PM, the incredible smoker said:

The way i have it the new X and Y position will be calculated, so it looks like exact the same spot.

Yes it would work, no reason it won't. I forgot to mention above that you can also set Z to 0. For example: Vector3.z = 0;

Looking in the game above in the video, it could be top down. In that case it could be Y that should be 0; what ever your "depth" axis is.

Share on other sites

If you convert a vector from  (10, 22, 8 ) to (10, 22, 0). then you only change the Z value,

it will only look the same in exact the center of the screen.

Changing value (0,0,8) to (0,0,0) would work.

Edited by the incredible smoker

Share on other sites
5 hours ago, the incredible smoker said:

it will only look the same in exact the center of the screen.

This is because of your camera, not the position of the object.

You want a Orthographic camera.

Share on other sites

I am assuming you are using a perspective projection or other projection that is not orthographic.

If that is the case, and what you want is the screen X,Y coordinates of the projected point to be unchanged when you transform them so that Z=0, then the easiest thing is to project the points and set Z=0 directly.

This is what previous answers are assuming you mean, because the other option is...unusual. The other option is that you want to find out where the points are going to be after they are projected, then altering their position so that when they are projected they end up with the same X,Y coordinates but with Z=0. This would be a waste of computation, and against the general approach of separating logical coordinates from graphical coordinates.

I'm not an expert game designer, just a regular programmer, but I'm betting that if your game logic depends on the screen space coordinates of an asset, and that logic is not related directly to user interaction, then it is likely your design is off. If perspective distortion is an aesthetic requirement, then the game logic shouldn't care or even know about it*.

Given that your camera is up at Z=-1000 and you want your objects to be down at Z=0, I bet that if you just use an orthographic camera like Scouting Ninja said it would all be much easier.

Share on other sites

What is a ortographic camera ?

Share on other sites
2 minutes ago, the incredible smoker said:

What is a ortographic camera ?

"Orthographic" comes from the Greek for "proper drawing" (kinda). Think "faithful reproduction" or "scale drawing"; it works like a blueprint or schematic. An orthographic projection won't change the shape of objects; it might scale them, it might translate them, but it does not distort them. Squares will still be squares, circles will be still be circles, straight lines are still straight and parallel lines do not intersect at infinity.*

A camera using an orthographic projection has no perspective; objects closer to the camera will not appear larger than those farther away. Basically, you scale everything such that the image you get is undistorted. In your case, a practical example would be something like:

[ 1/10 0         0 0 ]
[ 0    1/10      0 0 ]
[ 0    0    1/1000 0 ]
[ 0    0         0 1 ]


which would map the box with corners at (-10,-10, -1000), (10,10,1000) to the cube with corners at (-1,-1,-1), (1,1,1). Graphics (usually) requires depth information to be saved, so here the Z axis is not zeroed out and instead crushes a lot more Z into the final volume than it does X and Y.

You still need to deal with your world, object, and camera matrices though. Note that this is an example based on a number of assumptions, like the handedness of your coordinates, the aspect ratio of the screen, or the bounds of the canonical volume. I've chosen a simple transform to make it clear what we are talking about, otherwise it'd be weird fractions. Also, I haven't implemented this in quite a while.

Share on other sites

Ok thanks, how would i do that in DirectX9 ?

I still have all meshes in 3D, then the bullets are spawned,

then the bullets should hit the players hitbox.

Create an account

Register a new account

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 46
• 22
• 27
• Forum Statistics

• Total Topics
634051
• Total Posts
3015254
×