Archived

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

Directions

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

Recommended Posts

I have 2 questions, both relating to my attempt to make a compass-style HUD element. 1 - is there a way to see what direction the player is looking? I see a direction element on the camera structure. Is a similar element present on the player structure as well? I haven''t run across it yet if it''s there. 2 - in the camera direction element, the values for x range from 1 to -1 with -1 being looking straight forward to 1 looking straight backward. The value for z ranges from 1 (straight right) to -1 (straight left). Does anyone have a quick algorithm for computing the direction the camera is facing from those values? I can do it with a series of if statements, but that seems clumsy. What I''m looking for is a way to translate the (x,z) values to compass directions. For example, (-1, 0) = N, (-.5, -.5) = NW, (0,-1) = W, etc. Thanks for any assistance

Share on other sites
This may or may not help, but here's how I drew a compass needle in Crystal Space:

// calculate and draw the compass needle
camPoint = Sys->view->GetCamera()->Camera2WorldRelative(csVector3(0, 0, -1));
camPoint.y = 0;
camPoint = camPoint.Unit();
G2D->DrawLine(582, h3d - height + 49, 582 - (camPoint.x * 30), h3d - height + 49 + (camPoint.z * 30), red);

(prototype for DrawLine: DrawLine(x1, y1, x2, y2, color))

What you'll probably want to do is rotate a unit vector through the character's rotation matrix:

// tvector = unit vector pointing in our character's direction
PR_Globals.tvector[0] = 0;
PR_Globals.tvector[1] = 0;
PR_Globals.tvector[2] = 1;
// rotate tvector through our character's rotation matrix
PR_Transform(entityNodePtr->Info.Character->LayerEntities[0]->orientation.rot_mat);

You may need to then clear out any Y component and re-normalize.
Then draw the line as above using PR commands.

Then again, if this is an FPS, instead of rotating tvector through an entity's rotation matrix, rotate it through the camera's rotation matrix.

Does that help, or do you still need the ordinals (N,W,E,S)?

Edited by - Dr Pain on October 23, 2001 9:38:36 AM

Share on other sites
Here's how I'm doing it now:

  if (PR_Globals.PR_CurrentCamera->direction.x > .25 && PR_Globals.PR_CurrentCamera->direction.x < .75 && PR_Globals.PR_CurrentCamera->direction.z < 0) sprintf(dirbuf, "SW");

I clear dirbuf before I start, then I have a similar line for each of the 8 cardinal directions. Then at the end, I print dirbuf to a spot on the screen. This works, but it's not very elegant and I was looking for a more efficent way.

Plus, this method is tied to the camera, and not the player. I need it to be the direction the player is facing and not necessarily the camera (in case a 3rd person camera was used at a different angle).

Edited by - OldRod on October 23, 2001 1:30:09 PM

Share on other sites
If it''s a third-person, then rotate the unit vector through that entity''s rotation matrix as I showed above.

Then, off the top of my head, you could do this:

dirbuff[1] = 0;
if (PR_Globals.tvector[0] < 0.25)
dirbuff[0] = "S";
else if (PR_Globals.tvector[0] > 0.75)
dirbuff[0] = "N";
else
dirbuff[0] = 0;

if (PR_Globals.tvector[2] < 0.25)
strcat(dirbuff, "E");
else if (PR_Globals.tvector[2] > 0.75)
strcat(dirbuff, "W");

That''s all written without testing, so the N/S and E/W are probably reversed, as is the choice of tvector[0] and [2]. And you''ll probably want to tweak the values 0.25 and 0.75 to get "NE" and others.

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
19
5. 5

• 14
• 26
• 11
• 11
• 9
• Forum Statistics

• Total Topics
631771
• Total Posts
3002253
×