View Full Version : projection onto hemisphere

08-07-2002, 05:16 PM
maybe this question doesn't belong in this forum but I was trying to do this in opengl for a trackball so...

I was wondering if someone could explain this code I found for projecting 2D points onto a hemisphere...especially the (*) parts

Vec3f v;
float d;
(*) v.x = (2.0*point.x - windowSize.x) / windowSize.x;
(*) v.y = (windowSize.y - 2.0*point.y) / windowSize.y;
v.z = 0.0;
d = v.Length();
d = (d<1.0) ? d : 1.0;
(*) v.z = sqrtf(1.001 - d*d);
v.Normalize(); // Still need to normalize, since we only capped d, not v.
return v;


08-08-2002, 03:30 AM
it appears that Vec3f is a structure/class with 3 pointers to floats, i.e.:

typedef struct
float *x;
float *y;
float *z;

the (*) before each value is dereferncing the pointer in order to assign a value to it. although, the line v.z = 0.0; seems to debunk my theory, that might not cause a compiler error.


08-08-2002, 03:36 AM
I don't think the (*)'s belong to the code, they can be more like notes that refer to comments on the code.