Jump to content


i want to draw the ray D3DXIntersect creates ..


5 replies to this topic

#1 Anddos

    Valued Member

  • Members
  • PipPipPip
  • 161 posts

Posted 03 February 2008 - 02:08 AM

is it possible to draw the ray D3DXIntersect creates? , DrawLine only draws x , y cordinates and not z ,

#2 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 04 February 2008 - 07:10 AM

I'm certain it's possible to do that, in fact...

You feed the function a 3 vector direction right? Well this is really just a coordinate that it would point to assuming it's coordinates were at 0,0,0. It's really no different that the LookAt part of the camera matrix.

So basicly what you do is get a plain old line drawing function (or use a skinny quad, or string of dots). Make the position of the first drawing point your ray position (obviously). For the second point where you want the line to end up, you simply say (in psuedo code):

DestPoint.xyz = sourcePoint.xyz + (direction.xyz * desiredLength)

The "desired length" can be whatever you want seeing as how a ray never ends, just don't make it negative :P .

As for only drawing X and Y, I guess I'm not sure what you mean... since everything ends up on a flat screen anyway. If you are trying to get the line to not be effected by the Z buffer (aka blocked by other objects) this is an easy fix as well.

-Render everything in your scene as normal
-turn the Z buffer off using SetRenderState(D3DRS_ZENABLE, false)
-then render all your lines just like if they were in 3D

good luck with whatever your doing

EDIT: oops, I misread your post a bit for the second part, oh well, still useful info. As far as drawing the line in 3D, I guess I'm not sure. I personally use a line of small dots. It's not good for preformance, but it gives the feedback I need. One thing that may work though is if you transformed the two points (source and destination) into clip (projection) space and used the 2D screen coordinates to draw the line with an ordinary function.

Other than that the only thing I can suggest is just a long, thing polygon. But I'm not %100 sure on how to get the destination point for that.

#3 Goz

    Senior Member

  • Members
  • PipPipPipPip
  • 574 posts

Posted 04 February 2008 - 09:30 AM

Erm ... drawing a 3D line in D3D is dead easy. DrawPrimitiveUP with D3DPT_LINELIST is your friend ...

#4 Anddos

    Valued Member

  • Members
  • PipPipPip
  • 161 posts

Posted 04 February 2008 - 05:32 PM

alright thanks guys , i was thinking the DrawPrimitive can only do x and y screen cordinates because the ray needs z as the last parameter

#5 Anddos

    Valued Member

  • Members
  • PipPipPip
  • 161 posts

Posted 04 February 2008 - 07:25 PM

i cant seem to make the line transformed so if the ray moves , so does the line to show where the ray is , it seems like the line is just stuck on front of the screen with no z direction etc...here is a screen shot

http://img86.imagesh...=d3dlinest6.jpg

#6 Goz

    Senior Member

  • Members
  • PipPipPipPip
  • 574 posts

Posted 05 February 2008 - 04:28 PM

Not sure what you mean? If you mean change the ray then you need to change the vertices past into DP. If you mean why does it not move with the camera .. try applying the view and projection matrices and specifying the ray in world coordinates ...





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users