Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.



This topic is 5501 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 think you understand the general idea. I think that maybe just a couple of steps are off.

When you transform your ray origin and direction by the inverse of the object's world matrix, I think you may be using the wrong function for the ray direction. You use D3DXVec3TransformCoord for both the origin and the ray direction. Eventhough both are stored as D3DXVECTOR3's, they each represent different things. Try using D3DXVec3TransformNormal to transform your rays direction instead. I know that the ray direciton is not a normal but you should use this function because it assumes that the "w" component of the input vector is 0, whereas D3DXVec3TransformCoord assumes that the "w" component is 1.

I'm not sure if it will make a difference, but you can try it and see: make sure that the ray direction is normalized.

Another thing is that I'm not sure why you have the following code. I guess you know your particular app better than anyone but this doesn't make much sense to me.

// Add the host entity's position to the ray direction to keep it moving as the entity moves.
m_vRayDirection.x += m_vPosition.x;
m_vRayDirection.y += m_vPosition.y;
m_vRayDirection.z += m_vPosition.z;

Maybe I'm missing something but I don't see why you're overwriting the ray origin and direction with a set value.

// Set the y point of both rays so it is in the middle of the target entity
m_vRayDirection.y = m_vRayOrigin.y = 10;

See if normalizing the ray direction and using D3DXVec3TransformNormal for the ray direction helps you out.


[edited by - neneboricua19 on October 24, 2003 10:47:35 PM]

Share this post

Link to post
Share on other sites
I think you need to take out these lines:

m_vRayDirection.x += m_vRayOrigin.x;
m_vRayDirection.y += m_vRayOrigin.y;
m_vRayDirection.z += m_vRayOrigin.z;

A direction has no position value. The direction value of any object does NOT depend on that object''s position. You do not have to "move" a direction vector anywhere. I saw that you went ahead and normalized your direction vector, but then you went and added your origin to it. So now your ray direction is not of unit length anymore.

Also, try to take out this line:

m_vRayDirection.y = m_vRayOrigin.y = 10;

This feels like a RNH (Really Nasty Hack) to me. If you feel like you must have something like that in there, do it AFTER you call D3DXIntersect. Since you said that you''re only doing this so that you can see your ray on the screen, then it would make sense to have it come after your intersection test because it should really have no bearing on the intersection intself.

Hope this helps,

Share this post

Link to post
Share on other sites

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