[Gambas-user] gb3: OpenGL Rotate and Translate logic

Kevin Fishburne kevinfishburne at ...1887...
Fri May 25 07:53:58 CEST 2012


On 05/24/2012 05:00 AM, tommyline at ...2340... wrote:
>
> Hi Kevin.
> I think you should concider using Glu.LookAt function, which should solve all your problems.
>
> I used it in collision project (attached) to follow the ball.
> You just set the camera with few parameters, and that's it! Please check the command help in Gambas.
> Simply speaking, you define eye point's (x,y,z position - no need for scale or translate), point you look at and point where the top of camera is (by changing it, you rotate the world in front of you), so I think that would solve it. See the attached example to see how I did it. Press F3 to see how it works.
>
> > From glu man pages:
>
> NAME
> 	  gluLookAt - define a viewing transformation
>
>
>       C SPECIFICATION
> 	  void gluLookAt( GLdouble eyeX,
> 			  GLdouble eyeY,
> 			  GLdouble eyeZ,
> 			  GLdouble centerX,
> 			  GLdouble centerY,
> 			  GLdouble centerZ,
> 			  GLdouble upX,
> 			  GLdouble upY,
> 			  GLdouble upZ )
>
>
>       PARAMETERS
> 	  eyeX,	eyeY, eyeZ
> 			  Specifies the	position of the	eye point.
>
> 	  centerX, centerY, centerZ
> 			  Specifies the	position of the	reference
> 			  point.
>
> 	  upX, upY, upZ	  Specifies the	direction of the up vector.
>
>       DESCRIPTION
> 	  gluLookAt creates a viewing matrix derived from an eye
> 	  point, a reference point indicating the center of the	scene,
> 	  and an UP vector.
>
> 	  The matrix maps the reference	point to the negative z	axis
> 	  and the eye point to the origin.  When a typical projection
> 	  matrix is used, the center of	the scene therefore maps to
> 	  the center of	the viewport.  Similarly, the direction
> 	  described by the UP vector projected onto the	viewing	plane
> 	  is mapped to the positive y axis so that it points upward in
> 	  the viewport.	 The UP	vector must not	be parallel to the
> 	  line of sight	from the eye point to the reference point.
>
> 	  Let
>
> 	      (	centerX	  -   eyeX  )
> 	  F = |			    |
> 	      |	centerY	  -   eyeY  |
> 	      (	centerZ	  -   eyeZ  )
>
> 	  Let UP be the	vector (upX,upY,upZ).
>
> 	  Then normalize as follows: f = _____
> 					 ||F||
>
> 	  UP' =	______
> 		||UP||
>
> 	  Finally, let s = f x UP', and	u = s x	f.
>
> 	  M is then constructed	as follows:
> 	      (	s[0]   s[1]   s[2]  0  )
> 	      |	u[0]   u[1]   u[2]  0  |
> 	  M = |			       |
> 	      |-f[0]  -f[1]  -f[2]  0  |
> 	      |	 0	0      0    1  |
> 	      (			       )
> 	  and gluLookAt	is equivalent to glMultMatrixf(M);
> 	  glTranslated (-eyex, -eyey, -eyez);
>
> I hope I did help.
>
> Tomek.
>

Cool little program. I posted here as well about the issue:

http://www.opengl.org/discussion_boards/showthread.php/177719-Matrix-scale-rotation-and-translation-with-repsect-to-2D-camera

and someone had the same idea about using GluLookAt(). I'm still stuck 
on the camera rotation though. I need it to spin perpendicular to the 
direction it's pointing, like tilting your head to the side but 360 
degrees. I think I understand that I need to apply the camera's 
orientation to the "up vector", but don't really know how to go about 
it. I don't think it's a matter of just plugging the orientation into 
one of the three vector values. Any insight into how exactly the up 
vector works in this regard?

-- 
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: sales at ...1887...
phone: (770) 853-6271





More information about the User mailing list