# OpenGL Math Behind the Perspective View and ModelView

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

## Recommended Posts

Hello everyone, I'm trying to practice the math behind the matrix magic behind opengl. I want to draw a cube by using the matrix multiplication instead of glFrustum and glrotation.

Here's what the code look like when drawing the right side of the cube.

Please assume we can only draw a line in 2D.

http://snipt.net/stevenie/opengl?key=6785e6b975db5d7cf223101ef1bc2f6f

However the right face doesn't look perspective at all. I can only see one straight line.

Thanks!

Steven

##### Share on other sites
You forgot the perspective division. And for that matter, what's going on with the W values of your vertices?

##### Share on other sites
Quote:
 Original post by SneftelYou forgot the perspective division. And for that matter, what's going on with the W values of your vertices?

Thanks for your reply. Now i can see the 3D effect if i divided x and y by z. However, they are inverted. Do you need to divided them by -z? Thanks!

Steven

##### Share on other sites
Quote:
 Original post by stevenieThanks for your reply. Now i can see the 3D effect if i divided x and y by z. However, they are inverted. Do you need to divided them by -z? Thanks!

That's not how the perspective division works. What are you using as a reference for this?

1. 1
Rutin
25
2. 2
JoeJ
20
3. 3
4. 4
5. 5

• 9
• 9
• 46
• 41
• 23
• ### Forum Statistics

• Total Topics
631749
• Total Posts
3002051
×