-
February 18th, 2000, 03:22 PM
#1
OpenGL Pan & Rotate Help
I am trying to write a viewing application that simply draws some graphics and allows the user to Rotate, Pan, and Zoom the view. I can do each of these separately but whenever I rotate the view my panning algorithm does not seem to work right. Does anyone have any code examples that show how to do this correctly?
Thanks,
-
February 18th, 2000, 05:57 PM
#2
Re: OpenGL Pan & Rotate Help
Howdy!
Hope this helps. I wrote a map-viewer that uses glu perspective. So, I only need to modify camera spot point, viewpoint and upvector.
Variables you need to know:
Zoom.Cursor[2], screen cursor coords
Zoom.Dcursor[2], delta screen coords
Zoom.HCursor[2], screen cursor coords extended to 3D cursor line, that penetrates z=0 layer at HCursor[2] real world coords.
Zoom.DHcursor[2], delta
Zoom.Spot_Eye[4], is polar vector from camera spot point to viewpoint (Phi, Theta, R, Phi+PI)
Zoom.Eye[3], cartesian coords of viewpoint
Zoom.Spot[3], cartesian coords of camera spot point
Zoom.ChgVP is a boolean, that describes drastic altitude shifts of viewpoint, which requre recalibration of clipping planes.
Shell.Width=Shell.W_Size[0], Shell.Height=Shell.W_Size[1], screen metrics
So, sometimes I alter cartesian coords, sometimes polar coords that describe viewpoint and spot point. Depending on this I must call another function to keep those variables mutually compatibile.
Those two functions are:
EyeV_2_EyeP (); (polar vector -> cartesian point) and
EyeP_2_EyeV (); (vice cersa)
Check_Ground (); prevents viewpoint from colliding with map surface
Check_Bound (); prevents viewpoint from departing far outside of map area
Generalize_Eye (); keeps all angular coords within range [0..2PI], updates screen normal and upvector.
Check_Spot (); keeps the camera spot point on actual map surface and not on z=0 layer.
Cursor_2_Hcursor (); takes screen cursor coords, transforms them to real world polar vector, and seeks for penetration point with layer z=0 (if exists). That is Zoom.HCursor[2].
Code successfully runs within elevation angle 15° to 75°. What happenes at 90°, I cannot tell.
Happy coding!
========================
void
Rotate_View_Up (void)
{
if(Zoom.Cursor[1] >= (Shell.Height - 10)){
Zoom.ChgVP=1;
if(Zoom.Spot_Eye[1] < topagl) Zoom.Spot_Eye[1] += agl;
if(Zoom.Spot_Eye[1] < minagl) Zoom.Spot_Eye[1]=minagl;
EyeV_2_EyeP ();
Check_Ground ();
Check_Bound ();
Generalize_Eye ();
}
}
void
Rotate_View_Dn (void)
{
if(Zoom.Cursor[1] <= 10){
if(Zoom.Spot_Eye[1] >= bottomagl){
Zoom.ChgVP=1;
Zoom.Spot_Eye[1] -= agl;
}
if(Zoom.Spot_Eye[1] < minagl) Zoom.Spot_Eye[1]=minagl;
EyeV_2_EyeP ();
Check_Ground ();
Check_Bound ();
Generalize_Eye ();
}
}
void
Rotate_View_CW (void)
{
if(Zoom.Cursor[0] <= 10){
Zoom.Spot_Eye[0] -= agl;
/*
if(Zoom.Spot_Eye[0] < 0) Zoom.Spot_Eye[0] += 2*PI;
Zoom.Spot_Eye[3]=(Zoom.Spot_Eye[0]-PI);
if(Zoom.Spot_Eye[3] < 0) Zoom.Spot_Eye[3] += 2*PI;
*/
EyeV_2_EyeP ();
Check_Ground ();
Check_Bound ();
Generalize_Eye ();
}
}
void
Rotate_View_CCW (void)
{
if(Zoom.Cursor[0] >= (Shell.Width - 10)){
Zoom.Spot_Eye[0] += agl;
/*
if(Zoom.Spot_Eye[0] > 2*PI) Zoom.Spot_Eye[0] -= 2*PI;
Zoom.Spot_Eye[3]=(Zoom.Spot_Eye[0]-PI);
if(Zoom.Spot_Eye[3] < 0) Zoom.Spot_Eye[3] += 2*PI;
*/
EyeV_2_EyeP ();
Check_Ground ();
Check_Bound ();
Generalize_Eye ();
}
}
void
Zoom_In (void)
{
float dzoom, dy=0.03;
if((Zoom.Button[B_M]==HOLD) && (Zoom.Dcursor[1] < 0)){
Zoom.ChgVP=1;
dzoom = (Zoom.Dcursor[1] * dy * ceil(Zoom.Eye[2]/10));
if(Zoom.Spot_Eye[2] > 1.0) Zoom.Spot_Eye[2] += dzoom;
EyeV_2_EyeP ();
Check_Ground ();
Check_Bound ();
Generalize_Eye ();
}
}
void
Zoom_Out (void)
{
float dzoom, dy=0.03;
if((Zoom.Button[B_M]==HOLD) && (Zoom.Dcursor[1] > 0)){
Zoom.ChgVP=1;
dzoom = (Zoom.Dcursor[1] * dy * ceil(Zoom.Eye[2]/10));
Zoom.Spot_Eye[2] += dzoom;
EyeV_2_EyeP ();
Check_Ground ();
Check_Bound ();
Generalize_Eye ();
}
}
void
Pan_MAP (void)
{
if(Zoom.Button[B_R]==HOLD){
Zoom.Eye[0] -= Zoom.DHcursor[0];
Zoom.Eye[1] -= Zoom.DHcursor[1];
Zoom.Spot[0] -= Zoom.DHcursor[0];
Zoom.Spot[1] -= Zoom.DHcursor[1];
Check_Spot ();
Check_Ground ();
Check_Bound ();
Generalize_Eye ();
Cursor_2_Hcursor ();
}
}
void
Pan_Camera (void)
{
float dp, dphi;
if((Zoom.Button[B_M]==HOLD) && (Zoom.Dcursor[0] != 0)){
dp = 2*Zoom.HFoV/Shell.W_Size[0];
dphi = Zoom.Dcursor[0]*dp;
Zoom.Spot_Eye[0] += dphi;
/*
if(Zoom.Spot_Eye[0] > 2*PI) Zoom.Spot_Eye[0] -= 2*PI;
Zoom.Spot_Eye[3]=(Zoom.Spot_Eye[0]-PI);
if(Zoom.Spot_Eye[3] < 0) Zoom.Spot_Eye[3] += 2*PI;
*/
Zoom.Spot[0] = (Zoom.Eye[0] - cos(Zoom.Spot_Eye[0])*cos(Zoom.Spot_Eye[1])*Zoom.Spot_Eye[2]);
Zoom.Spot[1] = (Zoom.Eye[1] - sin(Zoom.Spot_Eye[0])*cos(Zoom.Spot_Eye[1])*Zoom.Spot_Eye[2]);
Check_Spot ();
EyeP_2_EyeV ();
Generalize_Eye ();
}
}
Miran
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|