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

tommyline at ...2340... tommyline at ...2340...
Fri May 25 16:58:43 CEST 2012


Hi Kevin, 

I attach simple project that uses glu.lookat and rotates around a point on the floor. Try it and tell if it's what you're looking for.

Tomek

----- Original Message -----
From: "Kevin Fishburne" <kevinfishburne at ...1887...>
To: gambas-user at lists.sourceforge.net
Sent: Friday, 25 May, 2012 6:53:58 AM
Subject: Re: [Gambas-user] gb3: OpenGL Rotate and Translate logic

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


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Gambas-user mailing list
Gambas-user at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kevin-0.0.1.tar.gz
Type: application/x-compressed-tar
Size: 116752 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20120525/1a382b22/attachment.bin>


More information about the User mailing list