OpenGL - Camera config/picking

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

OpenGL - Camera config/picking

tiboz
Hy,

Does anyone know where I can find the parameters of the camera (OpenGL package)? I would like to know
-cameraLookAt :the 3D point where the camera looks at (glLookat in c or python)
-cameraPosition :the current position of the camera in world space
-cameraUp is the up vector of the camera.

In fact I'm trying to do ray picking with opengl. I need cameraLookAt and cameraPosition to compute the direction of the ray :) Camera positioning is basic in OpenGl, it certainly possible to acces it. the problem is how ?

I welcome all ideas or help.
Thank you
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL - Camera config/picking

Michael Lucas-Smith-2
Hi tiboz,

Cameras aren’t actually part of 3D rendering, per-se. Instead, you have the basic transform of a vertex with:
positionInScene := projectionMatrix * viewMatrix * modelMatrix * vertex.

You might consider the projectionMatrix the camera, or perhaps the viewMatrix, or perhaps a combination of the two. But ultimately, it’s just mathematics multiplying vectors and matrices together. This is typically done either in the fixed graphics pipeline or in a custom shader program.

If you want to know more about this, I recommend you read the OpenGL specification, as it describes how rendering takes place and how all the pieces fit together. It’s quite a big complicated mishmash of technologies in there with all the different shader stages and specific hardware accelerated functions.

If it’s a question of what these values should be, then that comes down to how you describe your units and position your models. Say you have a 1x1x1 cube at 0,0,0 so that its sides are from -0.5 to 0.5. If you wanted to ‘look’ at that cube, you’d have to choose a position for the camera and a direction for the camera to look. Let’s say we place the camera at 2,0,0 and look at 0,0,0. Now we’d need to choose an ‘up’ direction for the camera, which let’s say it is the Y-axis, or 0,1,0. This is a fairly simple configuration. Our projection matrix is important here, because it describes how we handle the frustum and depth. Perhaps its orthogonal or its perspective or it’s a frustum, that’s for you to decide.. the typical matrices for achieving these are on the class side of Matrix4.

So putting this together, perhaps you’re looking for the glu (OpenGL Utility, deprecated) function lookAt, which takes these three parameters and gives you back a matrix for it. This would be the ‘view’ matrix in the above transform. The lookAt matrix is descirbed as:

gluLookAt(eye, center, up):

F = center - eye
f = F / ||F||   (normalised)
UP’’ = UP / ||UP|| (normalised)
s = f x UP’'
u = (s / ||s||) x f
M = s.x s.y s.z
u.x u.y u.z
-f.x -f.y -f.z

lookAtMatrix = M . -(eye)

Here’s a graphic showing how the lookAt matrix is constructed if the above is a bit too heady:

Good luck with your OpenGL explorations and ray picking.

Cheers,
Michael




On 4 Feb 2014, at 7:56 pm, tiboz <[hidden email]> wrote:

Hy,

Does anyone know where I can find the parameters of the camera (OpenGL
package)? I would like to know
-cameraLookAt :the 3D point where the camera looks at (glLookat in c or
python)
-cameraPosition :the current position of the camera in world space
-cameraUp is the up vector of the camera.

In fact I'm trying to do ray picking with opengl. I need cameraLookAt and
cameraPosition to compute the direction of the ray :) Camera positioning is
basic in OpenGl, it certainly possible to acces it. the problem is how ?

I welcome all ideas or help.
Thank you



--
View this message in context: http://forum.world.st/OpenGL-Camera-config-picking-tp4741358.html
Sent from the VisualWorks mailing list archive at Nabble.com.
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL - Camera config/picking

tiboz
Hi thank for these explanations (your links are good ).

I know that we have to place the camera (I've already done some small OpenGL projects in python) but as you can notice I'm little bit lost in smalltalk. I can't find functions to place the camera. I suppose it's pre-configurated somewere in OpenGL package. I would like to access it and be able to place the camera where I want.

I didn't that Glu existed in smalltalk too ? It would be pleasant!
I can't find OpenGL Utility, you mentioned, is it a package ?

Cheers,
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL - Camera config/picking

abergel
In reply to this post by Michael Lucas-Smith-2
Hi!

Just to let you know, we have worked hard on Roassal3d on Pharo.
http://objectprofile.com/#/pages/products/roassal3d/overview.html

We are wondering whether the VW community would be interested in having Roassal 3d...

Alexandre


On Feb 4, 2014, at 6:47 AM, Michael Lucas-Smith <[hidden email]> wrote:

> Hi tiboz,
>
> Cameras aren’t actually part of 3D rendering, per-se. Instead, you have the basic transform of a vertex with:
> positionInScene := projectionMatrix * viewMatrix * modelMatrix * vertex.
>
> You might consider the projectionMatrix the camera, or perhaps the viewMatrix, or perhaps a combination of the two. But ultimately, it’s just mathematics multiplying vectors and matrices together. This is typically done either in the fixed graphics pipeline or in a custom shader program.
>
> If you want to know more about this, I recommend you read the OpenGL specification, as it describes how rendering takes place and how all the pieces fit together. It’s quite a big complicated mishmash of technologies in there with all the different shader stages and specific hardware accelerated functions.
>
> If it’s a question of what these values should be, then that comes down to how you describe your units and position your models. Say you have a 1x1x1 cube at 0,0,0 so that its sides are from -0.5 to 0.5. If you wanted to ‘look’ at that cube, you’d have to choose a position for the camera and a direction for the camera to look. Let’s say we place the camera at 2,0,0 and look at 0,0,0. Now we’d need to choose an ‘up’ direction for the camera, which let’s say it is the Y-axis, or 0,1,0. This is a fairly simple configuration. Our projection matrix is important here, because it describes how we handle the frustum and depth. Perhaps its orthogonal or its perspective or it’s a frustum, that’s for you to decide.. the typical matrices for achieving these are on the class side of Matrix4.
>
> So putting this together, perhaps you’re looking for the glu (OpenGL Utility, deprecated) function lookAt, which takes these three parameters and gives you back a matrix for it. This would be the ‘view’ matrix in the above transform. The lookAt matrix is descirbed as:
> http://www.opengl.org/sdk/docs/man2/xhtml/gluLookAt.xml
>
> gluLookAt(eye, center, up):
>
> F = center - eye
> f = F / ||F||   (normalised)
> UP’’ = UP / ||UP|| (normalised)
> s = f x UP’'
> u = (s / ||s||) x f
> M = s.x s.y s.z
> u.x u.y u.z
> -f.x -f.y -f.z
>
> lookAtMatrix = M . -(eye)
>
> Here’s a graphic showing how the lookAt matrix is constructed if the above is a bit too heady:
> http://img.docstoccdn.com/thumb/orig/85433663.png
>
> Good luck with your OpenGL explorations and ray picking.
>
> Cheers,
> Michael
>
>
>
>
>
> On 4 Feb 2014, at 7:56 pm, tiboz <[hidden email]> wrote:
>
>> Hy,
>>
>> Does anyone know where I can find the parameters of the camera (OpenGL
>> package)? I would like to know
>> -cameraLookAt :the 3D point where the camera looks at (glLookat in c or
>> python)
>> -cameraPosition :the current position of the camera in world space
>> -cameraUp is the up vector of the camera.
>>
>> In fact I'm trying to do ray picking with opengl. I need cameraLookAt and
>> cameraPosition to compute the direction of the ray :) Camera positioning is
>> basic in OpenGl, it certainly possible to acces it. the problem is how ?
>>
>> I welcome all ideas or help.
>> Thank you
>>
>>
>>
>> --
>> View this message in context: http://forum.world.st/OpenGL-Camera-config-picking-tp4741358.html
>> Sent from the VisualWorks mailing list archive at Nabble.com.
>> _______________________________________________
>> vwnc mailing list
>> [hidden email]
>> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.




_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc