#### Archived

This topic is now archived and is closed to further replies.

# Can some one post a example of GluLookAt

This topic is 2762 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i don''t think i''m using GluLookAt right. can some one post a example of this.

##### Share on other sites
Bob is hanging upside down from a branch, looking at Alice, lying on the grass with a book.
gluLookAt( Bob_x, Bob_y, Bob_z,           Alice_x, Alice_y, Alice_z,           UpsideDown_x, UpsideDown_y, UpsideDown_z );

Bob''s branch is at 20,80,15 (it''s a tall tree)
Alice is at 15,0,12 (near the foot of the tree)
Upside-down mean your ''up'' vector is 0,-1,0

gluLookAt( 20, 80, 15,           15,  0, 12,            0, -1,  0 );

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)

##### Share on other sites
oh, ok thanks, i was thinking alice was a direction, but it''s actuly a point your looking at. :D

##### Share on other sites
but what if alice is not a point but an object like finite size(not a zero size point)

##### Share on other sites
[quote name='Kamal Reddy' timestamp='1300974440' post='4789937']
but what if alice is not a point but an object like finite size(not a zero size point)
[/quote]

Are you saying Alice needs to lose weight? Alice may be of 'finite size' (she says it's glandular), but gluLookAt still needs a precise direction in which to look. OpenGL doesn't support [i]sorta that way[/i] vectors.

If her position (ie: the translation part of her transform matrix) isn't reliable because she's deforming (that's glandular too), you can calculate an appropriate target vector by taking the centre of her bounding box, or the average of all her vertices, her centre of mass, centre of volume and so on.

That wouldn't have to be done precisely on every frame, though. You can get some nice camera movement with gluLookAt by treating the eye position, centre and up-vector as heavily damped particles (with position and velocity), [i]attracting[/i] the centre to target locations with damped springs, and repelling the camera itself from walls with a soft collision sphere or capsule. That way you don't have to be too fussy about calculating appropriate eye/centre/up-vectors all the time - the camera will still move smoothly on every frame even if you only [i]occasionally[/i] make careful decisions about where it's going.

1. 1
Rutin
45
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632998
• Total Posts
3009811
• ### Who's Online (See full list)

There are no registered users currently online

×