Jump to content
  • Advertisement
Sign in to follow this  
spiffycrony

Drawing a line in 3d

This topic is 4199 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to draw a line using 3d coordinates in directx8 and vb. I want to draw the line when two mouse clicks(start pt is first clicked point and end point is second clicked point) are made on the screen. I know there is a far & near plane because of which we get two sets of 3d coordinates(x1,y1,z1 for near plane & x2, y2, z2 for far plane). I assume this way i cannot get the exact 3d point corresponding to a clicked mouse pt. Now is there any other way for me to draw the line using 3d coordinate values? Any other alternative? PS: I want to draw the line in 3d because when i keep rotating the model i want the transformations to get applied for this line as well. I have tried D3DXVec3Unproject for getting the 3d point.

Share this post


Link to post
Share on other sites
Advertisement
someone correct me if i am wrong but when you unproject a vector you are calculating its position on screen not the other way round as i think you believe it is. that being said to draw the line where you want you could use the scroll wheel normally set to mouse.z to set the Z value of the position vector you want to set and then the usual mouse x and mouse y values to get your x and y values. finally render the line using a linestrip primitive so this way you shouldn't have to unproject anything at all :) hopefully that will help, good luck.

Share this post


Link to post
Share on other sites
Hey fanaticlatic, guess you got it wrong. I am pasting the info from directx sdk doc below

"
D3DXVec3Unproject
Projects a vector from screen space into object space.

D3DXVec3Unproject( _
VOut As D3DVECTOR, _
V As D3DVECTOR, _
Viewport As D3DVIEWPORT8, _
Projection As D3DMATRIX, _
View As D3DMATRIX, _
World As D3DMATRIX)

Parameters
VOut
D3DVECTOR type that is the result of the operation, the vector projected from screen space to object space.
V
The source D3DVECTOR type.
Viewport
D3DVIEWPORT8 type, representing the viewport.
Projection
D3DMATRIX type, representing the projection matrix.
View
D3DMATRIX type, representing the view matrix.
World
D3DMATRIX type, representing the world matrix.
"

Share this post


Link to post
Share on other sites
Quote:
Original post by fanaticlatic
someone correct me if i am wrong but when you unproject a vector you are calculating its position on screen not the other way round...

It's the other way around [wink]. In computer graphics, projection takes a 3D point to 2D (informally speaking) and unprojection is the (partial) inverse.

Spiffycrony, your design leaves a few questions unanswered. As you indicated, vector unprojection is not well-defined. In particular, a point in screen space unprojects to a ray in world-space. For this reason, the vertex coordinates of your line-list are ambiguous: you have a degree of freedom to fix before a deterministic algorithm may exist.

You will need a good constraint on where the points may be. For example, if you'd like the lines' endpoints to lie a fixed distance from the viewer, then you can determine the points by extrapolating the vector away from the camera by this fixed distance. Alternatively, if these lines are being drawn onto some existing mesh, then you can perform a line-mesh intersection to the same effect.

Perhaps you could give us a little more detail on the subject matter, so we can suggest how to proceed.

Admiral

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!