opengl - Get normal of a gluDisk? -


i'm writing solar system simulator in opengl. 1 of components in solar system earth's orbit (simple circle around sun, created gludisk function).

i wondering how can retrieve normal vector of disk because need use rotation vector camera (which needs follow earth's spin around sun).

this code (java) creates orbit, works well. using code, how retrieve normal of disk? (as disk contained in plane, defined normal).

    gl.glpushmatrix();      // if tilt 0, align orbit xz plane     gl.glrotated(90d - orbittilt, 1, 0, 0);      gl.gltranslated(0, 0, 0); // orbit around origin     gl.glcolor3d(0.5, 0.5, 0.5); // gray      // draw orbit     glu.gluquadricdrawstyle(quad, glu.glu_silhouette);     glu.gludisk(quad, 0, position.length(), slices, 1);      gl.glpopmatrix(); 

before transformation, disk in xy-plane. means normals point in z-direction, (0, 0, 1). in fact, gludisk() emit these normal during rendering, , transformations specify applied them, rendering don't have anything.

to calculate transformed normal yourself, need apply rotation. translation not used transforming normals.

so need apply rotation of 90 - t around x-axis vector (0, 0, 1). applying corresponding rotation matrix gives:

[ 1     0           0      ]   [ 0 ]   [     0      ] [ 0  cos(90-t)  -sin(90-t) ] * [ 0 ] = [ -sin(90-t) ] [ 0  sin(90-t)   cos(90-t) ]   [ 1 ]   [  cos(90-t) ] 

applying couple of trigonometric identities:

cos(90 - t) = sin(t) sin(90 - t) = cos(t) 

gives:

[     0      ]   [    0    ] [ -sin(90-t) ] = [ -cos(t) ] [  cos(90-t) ]   [  sin(t) ] 

when apply sin() , cos() functions in code, keep in mind angles specified in radians. if orbittilt angle in degrees, normal be:

xnormal = 0.0; ynormal = -cos(orbittilt * (m_pi / 180.0)); znormal = sin(orbittilt * (m_pi / 180.0)); 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -