Hello,
I recently posted this over in the DirectX part of the forum but figured this would be a better place for this question. I am currently working on trying to visualize a raycast and am trying to draw an arrow to signify the direction they ray is facing. I have it working for when the ray is pointing in a specific direction however, when I have the ray pointing in a different everything blows up. This is how I find the various points to render the raycast.
float fStartX = 0.0f;
float fStartY = 0.0f;
float fStartZ = 0.0f;
float fEndX = fStartX + (v3Dir.X * m_fLength);
float fEndY = fStartY + (v3Dir.Y * m_fLength);
float fEndZ = fStartZ + (v3Dir.Z * m_fLength);
float fCos = cosf(ToRadians(45.0f));
float fSin = sinf(ToRadians(45.0f));
fAngle1X = fEndX + fCos;
fAngle1Y = fEndY + fSin;
fAngle1Z = fEndZ / 2.0f;
fAngle2X = fEndX - fCos;
fAngle2Y = fEndY + fSin;
fAngle2Z = fEndZ / 2.0f;
fAngle3X = fEndX - fCos;
fAngle3Y = fEndY - fSin;
fAngle3Z = fEndZ / 2.0f;
fAngle4X = fEndX + fCos;
fAngle4Y = fEndY - fSin;
fAngle4Z = fEndZ / 2.0f;
I have a feeling that my issue is that I am not taking into account the ray direction. Which is throwing off the position of my angles. My question is what would be the best way to find the correct positions of the arrow based on direction. The only thing that I can think of is throwing in a couple of if statements to figure it out but that seems like a bad idea. I know it can be done with math. I am just not sure what the steps are to find it.
Thank you,
Chaz H.