HUD coords

Started by
1 comment, last by haphazardlynamed 18 years, 3 months ago
Hello, I'm ready to start implementing my HeadsUpDisplay in my game. Say for instance, I wanted to print the name of the selected object above its mesh. I have done the raytracing, and know which object is selected. I knwo its going to involve a similar process, maybe in reverse. I need to translate the vector position into screen coord ( also I suppose, it would be worth checking if its visible before doing too much! ). So how would I go about that? Thanks Simon
Advertisement
Depending on how you're doing your picking, it may be more or less the reverse, as you suggest. OpenGL has gluProject(), and I believe DirectX has something similar - perhaps you could use one of these functions to get the screen coordinates corresponding with the model.
Have some psuedo code:

viewspaceposition=VecSub(object.position,cam.position)
screendist=VecDot(viewspaceposition,cam.viewmatrix.z)
screenspaceposition=VecMultiply(viewspaceposition,1.0/screendist)
screenX=VecDot(screenspaceposition,cam.viewmatrix.x)
screenY=VecDot(screenspaceposition,cam.viewmatrix.y)


It is assumed that you have already written equivalent Vector functions.
also assumes that the camera viewmatrix x,y, and z axis are normalized


That *should* work, unless I have forgotten to compensate for some kind of screen aspect ratio stuff, but thats just divisions at most, so if there's an issue you can figure it out...

[Edited by - haphazardlynamed on January 11, 2006 3:52:20 PM]

This topic is closed to new replies.

Advertisement