Download as pdf or txt
Download as pdf or txt
You are on page 1of 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