0% found this document useful (0 votes)
120 views9 pages

16 - More On 3D Modeling in OpenGL

The document discusses 3D shapes, perspective projection, and coordinate systems in OpenGL. It provides functions for generating common 3D shapes like cubes, spheres, cones, toruses, and teapots. It also covers the glFrustum and gluPerspective functions for perspective projection and notes that they use a left-handed coordinate system, unlike other aspects of OpenGL which are right-handed. Code examples are provided to demonstrate orthographic versus perspective projection.

Uploaded by

src0108
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views9 pages

16 - More On 3D Modeling in OpenGL

The document discusses 3D shapes, perspective projection, and coordinate systems in OpenGL. It provides functions for generating common 3D shapes like cubes, spheres, cones, toruses, and teapots. It also covers the glFrustum and gluPerspective functions for perspective projection and notes that they use a left-handed coordinate system, unlike other aspects of OpenGL which are right-handed. Code examples are provided to demonstrate orthographic versus perspective projection.

Uploaded by

src0108
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Basic 3D Shapes More on perspective projection Left- vs. Right-handed coordinate systems.

Glut has many different preset 3d shapes for use in OpenGL. Both solid and wireframe versions for each shape. For a cube:
glutSolidCube(GLdouble size); glutWireCube(GLdouble size); Render a solid or wireframe cube respectively. The cube is centered at the modeling coordinates origin with sides of length size. Next we will show only the solid version functions, remember wireframe versions are available too.

Sphere:
glutSolidSphere(GLdouble radius, GLint slices, GLint stacks); radius: The radius of the sphere. slices: The number of subdivisions around the Z axis (similar to lines of longitude). stacks: The number of subdivisions along the Z axis (similar to lines of latitude).

Cone:
glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);

Torus (doughnut)
glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint nsides, GLint rings); innerRadius: Inner radius of the torus. outerRadius: Outer radius of the torus. nsides: Number of sides for each radial section. rings Number of radial divisions for the torus.

Teapot
glutSolidTeapot(GLdouble size); size: Relative size of the teapot.

& some other shapes as well

glFrustum( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far );

gluPerspective( GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble far );

gluPerspective() gluPerspective() requires only 4 parameters. Can produce a symmetrical viewing volume only. you have to use glFrustum() glFrustum() directly if you need to create a non-symmetrical viewing volume. if you want to render a wide scene into 2 adjoining screens, you can break down the frustum into 2 asymmetric frustums (left and right). Then, render the scene with each frustum.

It is very important to remember that gluPerspective, gluPerspective, glOrtho and glFrustum are left handed. It is easier if you think of zNear and zFar as distances from view point (point where the camera is placed, using the glulookAt function). Everything else is right handed, including the vertices to be rendered.

Refer to the attached code. Notice the difference between orthographic and perspective projections. Try changing the parameters of the projection functions calls, and the gluLookAt function call. Two OpenGL programs (with their source code) are attached as well, they will help you better understand how to adjust the parameters passed to the projection and transformation functions.

You might also like