Screen Position Calculations - Help Needed

Hello guys,

I’ve got three values (angles) - x and y that camera is facing (yaw and pitch, and z if needed), these are:

x - heading from true north in OGL coordinates
y - pitch from flat in OGL coordinates

I am wondering if it is possible by using these values to get Screen Position as a vector of xy?

Also, if we have a pitch value from flat Surface, would it be possible to recalculate pitch if camera moves up? If yes, how?

Sorry for asking for help but I am new to OpenGL and desperatly in need of advice.

Best Regards,

so everyone just left this guy for 12 days, I should start a school.
I’m going to teach you everything in one minute !!!

if you dont want everything, then dont get my example files and dont learn everything,
-== WORLD-3dpnt to SCREEN ==-

void w2s(int xy[2],int fol,double v[3],int x,int y) {
xy[0] = (int)((fol/v[2])*v[0]+x);
xy[1] = (int)((fol/v[2])*v[1]+y);

orbital(cameye,3); // .pos has no obliquity. remember
NORMALIZE(cameye); /// required for dotproduct ANGLE(v,v2)
/// crossproduct tho, is always a right angle vector,
/// normal input not needed, normalize crossproduct result.
set16mat(cmatrix,cameye); /// normal input not required
INITVECTOR(camup,cmatrix[4],cmatrix[5],cmatrix[6]);///a normal in the matrix
/// ////////////////// LookAt transform
/// now begin loop on every point
if Z is positive infront of camera, draw it, clip out xy limits
draw at w2s(f,v) <x y

one of these days I might change fol from int to double for more precise adjustments
now needed in OGL @ 200 fps, awesome !!!

first examples in main, is the trig - focal length to field of view.

know the trig laws and right-angle rules

3D 101, heh

and here’s the working prototype almost as described -

without more testing, I just figure its reversed for leaving ortho2D with 0 at bottom

uses inverted gluLookAt, and gluPerspective with input of fov/2

Update, after sizing the window I realize, ooops


I knew 2 was only close but what? it was aspect

ok then - beginners will likely begin wrong if they dont have this…

BG stars lights camera scene text = the math that IS the Camera!

Worth taking an hour to Google and make high def tga textures and running as eyeCandy.
Improvements very welcome, appreciated and worthwhile - chk it out -


how much does anti Aliasing COST? lol

Latest Features:
Gravity Simulation: c
Focal len and user defined star size: S,s
Random StarGate. Warps to the stars: 5
StarGate: 6
this code answers many questions - got know at least this much about the matrix.
not exactly a newbie - misnomer, hah

took a while, but finally got around to matching perspective screen xy !!
… simple, use the same perspective matrix you gave to the projection matrix.
found the deprecated glulookAt and gluPerspective code, especially lookat was ugly - rewritten.

working example **********************************
('cause no one else knew how, someone had to do it.)
functions not included, are in the file.

#define NORMALIZE4(V) {  \
  V[0]/=V[3];  \
  V[1]/=V[3];   \
  V[2]/=V[3];   \

#define popmatrix4( U, M, V ) { \
U[0] = V[0]*M[0]+V[1]*M[4]+V[2]*M[8]+V[3]*M[12]; \
U[1] = V[0]*M[1]+V[1]*M[5]+V[2]*M[9]+V[3]*M[13];  \
U[2] = V[0]*M[2]+V[1]*M[6]+V[2]*M[10]+V[3]*M[14];  \
U[3] = V[0]*M[3]+V[1]*M[7]+V[2]*M[11]+V[3]*M[15];  \
if (U[3]) NORMALIZE4(U); \
} /// != 0.0)&& (U[3] != 1) 1 changes nothing, NOT 0

double pmat[16] = { 0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0 } ;

void setpmat() {
  double fl; // = tan(dtor(90-fovx/aspect/2)); /// UNIT focal len
  fl = 1/tan(dtor(fov/Aspect/2)); ///  same number  /// fl * cx = actual focal length
  pmat[0]  = fl/Aspect;
  pmat[5]  = fl;
  pmat[10] = (farclip + nearclip) / (nearclip - farclip);
  pmat[14] = 2*farclip*nearclip / (nearclip - farclip);

void fovmat(double v[],double p[]) {
    int cx = (int)(_Width/2),cy = (int)(_Height/2);
    double pnt2[4], pnt[4] = { 0,0,0,1 } ;
    COPYVECTOR(pnt,p);NORMALIZE(pnt); /// matrix in unit form, normalize
    v[0] *= -cx; v[1] *= -cy;
    v[0] += cx; v[1] += cy;

In the gl scheme,

  glMultMatrixd(pmat); //perspective
  Camera(); // invertmatrix()

And for 2D - a 3D radius to 2D screen points.
first invert cam matrix to world wmatrix -
apply perspective to points in front.

    if (VLEN(v) < farclip) {
    if (v2[2] < 0.0) { /// reversed
    fovmat(v,v2); // FIN

// label down one radius
    sub = 10 + (int)VLEN2(v2);
// not some 3d point bouncing around dependent on z roll
// sticks like glue at any fov angle.

//or return a perspective size for an image -- fsize(1,12);
double fsize(double x, double z) { // Z focal len
  double v[3], p[3] = { x,0,z } ;
  return v[0] - _Width / 2;