Archived

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

designlord

#rror

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.
quote:

// 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.
quote:

// 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.

neneboricua

[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,
neneboricua

Share this post


Link to post
Share on other sites