Jump to content
  • Advertisement
perkalkyl

DX11 How do I draw a line from model origin to specific position in WordlView

Recommended Posts

Hi!

Pretty new to 3D programming, using SharpDX wrapper to build a 3D world (for testing and learning).

I am adding several visible camera objects (very rudimentary models) in order to visualize different views.  

 

Let's say I have a "world" floor grid covering vectors {0,0,0 - 1,1,0}

I add a pretend camera "CAM2" object at {0.5, 1.5, -1.0}

I am looking at this world by setting the parameters for "CAM1" a worldView projection position at pos: {0.0, 1.5, 1.5} lookat: {0.5, 0.0, 0.5}  (looking down from upper left towards the center of the floor).

I would like to draw a line from the pretend camera "CAM2" model origin, to the center of the floor as it is projected through "CAM1" view.

Obviously a line from "CAM1" to the Lookat point would be invisible. But I can't for my life figure out how to apply the correct conversions to the vector end point for "CAM2".

As can be seen in the snashot, the line (green) from "CAM2" points to.... well.. Russia?? :-D

Can anyone help?

 

BR
Per

 

model.png

Share this post


Link to post
Share on other sites
Advertisement

should be as simple as transforming that local point to the models world space:

p1 = localPoint * modelWorldMat;

p2 = worldPoint;

draw([p1, p2]);

in the vertex shader, you'll have to then multiply the points by the cam1 view mat and the projection mat

outPos = p * viewMat * projectionMat;

where viewMat is CAM1's view matrix, and p is p1 or p2

EDIT:

so your CAM2 position is the world point, and the "local" point is the direction CAM2 is facing? normally camera's are specified in world coordinates, so the direction should already be in world space

p1 = CAM2.position + CAM2.direction * lineLength;

P2 = CAM2.position;

the direction a camera is facing is usually a unit vector, so if you want a longer line you'll have to multiply that vector by a scalar, like 10 if you wanted the line to be 10 units long

Share this post


Link to post
Share on other sites

Wow! It turned out to be too simple for me to even try!

Just subtract the "Camera" position from its "lookat" point, and it works as expected!

 Vertices.AddRange(new[]{
 new Vector4(0, 0, 0, 1), Color.V4,
 new Vector4(CameraLookAt.X - Position.X, CameraLookAt.Y - Position.Y, CameraLookAt.Z - Position.Z, 1), Color.V4,
});

But thanx for putting in the effort!

 

Cheers!

Edited by perkalkyl

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!