viewing vs modeling transforms

viewing vs modeling transforms

Post by ndln » Mon, 30 Jun 2003 13:11:03



<Newbie alert>

I am reading the redbook and have some confusion regarding the viewing and
modeling transformation.

Same commands can be used for both.
I should code viewing transforms before modeling ones.

How do I specify that a particular command(s) is for a viewing transform and
another one for a modeling transform. I guess if I am to achieve the same
say translation effect my viewing and modeling transforms are different. If
I have to use only viewing Vs only modeling transform how do I go about it?

Let me know if I am not clear. I am pretty confused regarding this.

--
Afternoon, n.:
        That part of the day we spend worrying about how we wasted the morning.

 
 
 

viewing vs modeling transforms

Post by fungu » Mon, 30 Jun 2003 13:34:52



> <Newbie alert>

> I am reading the redbook and have some confusion regarding the viewing and
> modeling transformation.

> Same commands can be used for both.

All commands can be used for both, but it's not a good idea.

Quote:> I should code viewing transforms before modeling ones.

Doesn't matter. Just put everything in the right place.

Quote:> How do I specify that a particular command(s) is for a viewing transform and
> another one for a modeling transform.

glMatrixMode()

Quote:> I guess if I am to achieve the same
> say translation effect my viewing and modeling transforms are different. If
> I have to use only viewing Vs only modeling transform how do I go about it?

The projection matrix should contain the view projection,
created by glFrustum(), glOrtho(), gluPerspective(),
etc.

The modelview matrix should have everything else.

--
<\___/>          For email, remove my socks.
/ O O \
\_____/  FTB.    Why isn't there mouse-flavored cat food?

 
 
 

viewing vs modeling transforms

Post by DM » Mon, 30 Jun 2003 22:19:49



Quote:> <Newbie alert>

> I am reading the redbook and have some confusion regarding the viewing and
> modeling transformation.

<snip>

There is a "duality" between modeling and viewing transformations. Suppose
you want to draw a ball. Translating the "camera" -10 units in Z before you
draw the ball has the same effect as translating the ball 10 units in Z and
leaving the camera alone. They both occur on the modelview matrix. Whether
the camera or ball moves is all in how you think about it.

If you want to think in terms of moving the "camera" or "view", those
transformations come first.  Then you move, rotate, scale, the objects in
your model or scene.   All of those transformations are performed relative
to where you placed the "camera" or "view".

Read chapter 3 of the Red Book until it sinks in. It takes a while when
you're a beginner. ;-) Also, read up on the gluLookAt() function. It's the
closest thing in OpenGL to a true "camera". It should be covered in chapter
3 as well.

 
 
 

viewing vs modeling transforms

Post by marc » Mon, 30 Jun 2003 21:43:16



> <Newbie alert>

> I am reading the redbook and have some confusion regarding the viewing and
> modeling transformation.

> Same commands can be used for both.
> I should code viewing transforms before modeling ones.

In my engine I have separated the viewing and the modeling like this:
I have one matrix that holds the camera values. In addition, every
object have a matrix that holds the transformations
(translations/rotations) that the object has done.

In my drawing method I then do a glLoadMatrixf(view) followed by a
glMultMatrixf (model). Theese 2 matrices makes up my modelview matrix
and after theese 2 invokations I just start doing my glVertex stuff.

Quote:> How do I specify that a particular command(s) is for a viewing transform and
> another one for a modeling transform. I guess if I am to achieve the same
> say translation effect my viewing and modeling transforms are different. If
> I have to use only viewing Vs only modeling transform how do I go about it?

In the object transform methods I affect the objects model matrix. In
the camera control methods I affect the view matrix.

Quote:> Let me know if I am not clear. I am pretty confused regarding this.

I don't know for sure if this was what you were looking for (I may
have gotten your question wrong). But since I did this separation I
find it a lot easier to keep track on what I'm doing, and to what I'm
doing it.
 
 
 

viewing vs modeling transforms

Post by ndln » Mon, 30 Jun 2003 23:45:40





>> <Newbie alert>

>> I am reading the redbook and have some confusion regarding the viewing
>> and modeling transformation.

> <snip>

> There is a "duality" between modeling and viewing transformations. Suppose
> you want to draw a ball. Translating the "camera" -10 units in Z before
> you draw the ball has the same effect as translating the ball 10 units in
> Z and leaving the camera alone. They both occur on the modelview matrix.
> Whether the camera or ball moves is all in how you think about it.

> If you want to think in terms of moving the "camera" or "view", those
> transformations come first.

First of all thanks to all who replied (Fungus, Marcus and DM)

Yes DM, it is just 'beginning' to sink in now.
You mentioned here that 'moving the camera transformations come first' and I
get that part. This means moving the objects transformation come next.
Suppose I have a series of transformations and I am *not* using gluLookAt()
function.
say

translate(z, -10);
translate(z, -5);
drawObject();

I am pretty sure the first translation will move the "camera". What will the
second one do? Will it push the camera further or will it get the object
nearer to the camera? Do I need to specify the matrixmode(modelview) in
between these two to specify that the second translation should affect the
object? Reading chapter 3 made me believe that modelview is used for both
camera and object. So I am getting confused how should i explicitely say
'hey, this command is to move the camera'  'this command is to move the
object.'

Quote:> Then you move, rotate, scale, the objects in
> your model or scene.   All of those transformations are performed relative
> to where you placed the "camera" or "view".

got that. but how is openGL to know that I done moving/rotating my camera
and now further commands will affect the position and orientation of the
object when all I have is one object. what will be the psudocode for

//orient camera
//orient object 1
//draw object 1
//orient object 2
//draw object 2
//move camera to look at these two from some other place
//orient object 3
//draw object 3

Thanks a lot for your time people. Really appreciate it.

Quote:> Read chapter 3 of the Red Book until it sinks in. It takes a while when
> you're a beginner. ;-) Also, read up on the gluLookAt() function. It's the
> closest thing in OpenGL to a true "camera". It should be covered in
> chapter 3 as well.

am in the second pass. :)
 
 
 

viewing vs modeling transforms

Post by ndln » Mon, 30 Jun 2003 23:53:20





>> <Newbie alert>

> In my engine I have separated the viewing and the modeling like this:
> I have one matrix that holds the camera values. In addition, every
> object have a matrix that holds the transformations
> (translations/rotations) that the object has done.

> In my drawing method I then do a glLoadMatrixf(view) followed by a
> glMultMatrixf (model). Theese 2 matrices makes up my modelview matrix
> and after theese 2 invokations I just start doing my glVertex stuff.

>> How do I specify that a particular command(s) is for a viewing transform
>> and another one for a modeling transform. I guess if I am to achieve the
>> same say translation effect my viewing and modeling transforms are
>> different. If I have to use only viewing Vs only modeling transform how
>> do I go about it?

> In the object transform methods I affect the objects model matrix. In
> the camera control methods I affect the view matrix.

I think yes, this definitely clarifies things for me as you are treating
them as two separate matrices. Perhaps I will use this strategy once I am
comfortable as it seems to reduce a lot of confusion in a bigger code.

What I am interested in is finding out how you got the 'view' and 'model'
matrices separately. My basic confusion is the inability to find them. I
seem to have only the modelview matrix when i set the mode to modelview.
how do I 'save' these two separately?

Thanks for your time!

--
You know you've been spending too much time on the computer when your
friend misdates a check, and you suggest adding a "++" to fix it.

 
 
 

viewing vs modeling transforms

Post by DM » Tue, 01 Jul 2003 01:09:55






> >> <Newbie alert>

> > In my engine I have separated the viewing and the modeling like this:
> > I have one matrix that holds the camera values. In addition, every
> > object have a matrix that holds the transformations
> > (translations/rotations) that the object has done.

> > In my drawing method I then do a glLoadMatrixf(view) followed by a
> > glMultMatrixf (model). Theese 2 matrices makes up my modelview matrix
> > and after theese 2 invokations I just start doing my glVertex stuff.

> >> How do I specify that a particular command(s) is for a viewing
transform
> >> and another one for a modeling transform. I guess if I am to achieve
the
> >> same say translation effect my viewing and modeling transforms are
> >> different. If I have to use only viewing Vs only modeling transform how
> >> do I go about it?

> > In the object transform methods I affect the objects model matrix. In
> > the camera control methods I affect the view matrix.

> I think yes, this definitely clarifies things for me as you are treating
> them as two separate matrices. Perhaps I will use this strategy once I am
> comfortable as it seems to reduce a lot of confusion in a bigger code.

> What I am interested in is finding out how you got the 'view' and 'model'
> matrices separately. My basic confusion is the inability to find them. I
> seem to have only the modelview matrix when i set the mode to modelview.
> how do I 'save' these two separately?

Keeping them separate is up to you.  OpenGL processes all model and view
transformations on the modelview matrix.  What you probably want to do to
keep them separate is to create a camera object and an object for the things
in your model.  Then have each object either keep track of their own matrix,
or simply have each one issue its own OpenGL commands to translate, rotate,
etc.  Just make sure you have your camera issue its commands first:

glMatrixMode(GL_MODELVIEW_MATRIX);
glLoadIdentity();
MyCameraObject.draw();
MyTreeObject.draw();
MyHouseObject.draw();
...

 
 
 

viewing vs modeling transforms

Post by marc » Tue, 01 Jul 2003 15:13:17



> Keeping them separate is up to you.  OpenGL processes all model and view
> transformations on the modelview matrix.  What you probably want to do to
> keep them separate is to create a camera object and an object for the things
> in your model.  Then have each object either keep track of their own matrix,
> or simply have each one issue its own OpenGL commands to translate, rotate,
> etc.  Just make sure you have your camera issue its commands first:

> glMatrixMode(GL_MODELVIEW_MATRIX);
> glLoadIdentity();
> MyCameraObject.draw();
> MyTreeObject.draw();
> MyHouseObject.draw();
> ...

Thats right, and initially you load the viewmatrix with the values of
the GL_MODELVIEW_MATRIX after initiated a gluLookAt or whatever you
choose to use for setting up the view. The modelmatrix will have the
identity matrix (or the identity matrix multiplied with the models
initial position, depends how you want to do it), I just use the
identity matrix. This makes the modelmatrix only consist of the
translations/rotations the model have made after creation.

But like DM says, there is only one modelview matrix, and what is in
it is what matters when you are to draw your models. You just have to
multiply your viewmatrix with the models modelmatrix (and thereby get
the complete modelview matrix) before you issue any drawing commands.

 
 
 

viewing vs modeling transforms

Post by Be » Tue, 01 Jul 2003 22:04:08


Hi,

This confused the hell out of me the first time i saw it as well. I
came from a DirectX background and it took a while to get an
appreciation for how this worked in opengl.

=============================================
In DirectX (Pseudo):
=============================================

SetTransform(VIEW, Camera->Matrix) // Set View matrix here

For each mesh in scene

    SetTransform(WORLD, mesh->Matrix)

    Mesh.Draw

Next

=============================================
In OpenGL (Pseudo):
=============================================

glMatrixMode(GL_MODELVIEW)
glloadMatrixf((float*)Camera->Matrix) // Load view matrix

glPushMatrix()

    glMultMatrix(Mesh->Matrix)
    Mesh->Draw

glPopMatrix()

In opengl there is a matrix stack (a list of matrices).
As you can see the opengl implementation looks funny until you get an
appreciation for how the matrix stack works. First we set the matrix
mode to the confusing MODEL_VIEW, then we load our camera matrix into
the matrix stack. To draw our models we simply call glPushMatrix()
(why? - because we need to preserve a copy of the view matrix - why? -
so we can restore the view matrix after we have rendered the current
mesh) which creates a new copy of the existing matrix on the stack. We
then multiply this matrix (a copy of the view matrix) with our mesh
matrix. Our copy matrix now contains the result of this multiplication
so our co-ordinate axes are such we can now render our mesh. Once
rendered we pop our mesh/view multiplied hybrid matrix off the stack
thus restoring the view matrix underneath and so we continue with the
next mesh...

Confused...you willl beee(in a yoda type voice).

Hope this helps. If not then feel free to mail me at

Ben.


> <Newbie alert>

> I am reading the redbook and have some confusion regarding the viewing and
> modeling transformation.

> Same commands can be used for both.
> I should code viewing transforms before modeling ones.

> How do I specify that a particular command(s) is for a viewing transform and
> another one for a modeling transform. I guess if I am to achieve the same
> say translation effect my viewing and modeling transforms are different. If
> I have to use only viewing Vs only modeling transform how do I go about it?

> Let me know if I am not clear. I am pretty confused regarding this.

 
 
 

1. Question: Adjusting viewing volume based upon model transforms?

Hello all,

It will soon become apparent that I'm not terribly comfortable with how OpenGL handles model
transformations and viewing volumes. :)  It is my fault, not OpenGL's.  That being said, any
pointers would be appreciated.

First, a quick bit about what I'm trying to do.  I have model data being parsed in and stored.
Given this model data, I know the size and coordinates of the minimum bounding box, including
the model centre.  I can display this properly.  Currently, I'm always moving the model so that
it is centred on the origin.  I set up my viewpoint (using gluLookAt) as appropriate, given
that the model is centred at the origin.

The user is allowed to pan/translate, rotate, and zoom/scale the model.  Currently, I'm loading
these into a matrix and then, at the render level, I'm multiplying the modelview matrix by this
'user defined' transformation matrix.

This leads me to the actual problem -- how can I ensure that my viewing volume (as set up by
glOrtho) will prevent any clipping, given that the model can be moved all over the place,
scaled, etc.?  Currently, I'm setting my viewing volume based on the extents of the model.
I've also tried dynamically calculating the viewing volume based upon the model transformation
being performed (e.g. pump the bounding box through the modelview transformation matrix and get
a new bounding box and use that -- however, this counteracts stuff like scaling).

Thanks for any pointers to resource or code.  I'm sure I just need to sit down and work this
out from first principles in the Red Book, so I'll have a crack at that as well.

Take it easy,
Matthew

2. Lighting

3. Transforming multiple 2D-views into one 3D-model

4. Just a reminder... ;-)

5. Viewing Transformation vs. Modeling Transformation

6. .MOV => .AVI or .MPG

7. Model rotation vs View point rotation - Help!

8. Help: Transforming the View Normal

9. view transform

10. Viewing transforms

11. Renderman to OpenGL viewing transform.

12. view transform