CSE 40166 / 60166 - Computer Graphics

|    Home  |   Syllabus  |   Assignments  |   Schedule  |   Resources   |

CSE40166 Library API v1.5

Download the latest version of the code here.
Revision History
Download Past Versions

CSE40166.h

Simply add an additional header to your code:

#include <CSE40166/CSE40166.h>
using namespace CSE40166;

Each class is defined within the CSE40166 namespace so you may wish to state which namespace to use (though you can access each class CSE40166::Camera for example). After calling glutCreateWindow(), call

CSE40166Init( bool usingOpenGL, bool usingOpenAL );

to set up the necessary headers and file information. It will print some debug information to the terminal telling which version of OpenGL and OpenAL you are using (if applicable).

[top]

Camera

  • Camera( CameraType cType )
    Camera constructor, specify camera type to use. Available types are: ARCBALLCAM, FREECAM, OTHER
  • void computeArcballPosition()
    Compute the X,Y,Z eye position of the camera based off of its current radius, theta, and phi settings
  • void computeFreecamOrientation()
    Compute the X,Y,Z lookAt position of the camera based off of its current position, theta, and phi settings
  • void look()
    Call gluLookAt() with the current eye point, lookAt point, and up vector
  • void moveForward()
    Move free cam one step forward along its current heading
  • void moveBackward()
    Move free cam one step backward along its current heading
  • Point* getEye()
  • void setEye( Point eye )
  • void setEye( Point *eye )
  • Point* getLookAt()
  • void setLookAt( Point lookAt )
  • void setLookAt( Point *lookAt )
  • Vector* getUp()
  • void setUp( Vector up )
  • void setUp( Vector *up )
  • Vector* getView()
    Returns a pointer to a Vector containing the view vector for the current camera.
  • float getTheta()
  • void setTheta( float theta )
  • float getPhi()
  • void setPhi( float phi )
  • float getRadius()
  • void setRadius( float radius )
[top]

Light

Light is an abstract class and should not be instantiated. Instead instatiate DirectionalLight, PointLight, SpotLight depending on the type of light you need.
  • GLfloat* getAmbient()
  • void setAmbient( GLfloat amb[4] )
  • GLfloat* getDiffuse()
  • void setDiffuse( GLfloat diff[4] )
  • GLfloat* getSpecular()
  • void setSpecular( GLfloat spec[4] )
  • GLfloat* getEmissive()
  • LightType getLightType()
    Return the type of light being used. Values are: POINT, DIRECTIONAL, SPOT
  • GLint getLightNumber()
  • void setLightNumber( GLint lNum )
    Acceptable values are between 0 and 8
  • GLfloat getConstantAttenuation()
  • void setConstantAttenuation( GLfloat cA )
  • GLfloat getLinearAttenuation()
  • void setLinearAttenuation( GLfloat lA )
  • GLfloat getQuadraticAttenuation()
  • void setQuadraticAttenuation( GLfloat qA )
  • void turnLightOff()
    Calls glDisable( GL_LIGHT# ) and sets the flag to false
  • void turnLightOn()
    Calls glEnable( GL_LIGHT# ) and sets the flag to true
  • bool isLightOn()
    Returns if the light is on or off
  • void shine()
    Call all the necessary glLightf() parameters

[top]

DirectionalLight

DirectionalLight is a subclass of the abstract class Light.
  • DirectionalLight( GLint lightNum )
    Create a DirectionalLight with light number equal to lightNum. lightNum must be between 0 and 8 to be valid
  • Vector* getDirection()
  • void setDirection( Vector dir )
  • void setDirection( Vector* dir )

[top]

PointLight

PointLight is a subclass of the abstract class Light.
  • PointLight( GLint lightNum )
    Create a PointLight with light number equal to lightNum. lightNum must be between 0 and 8 to be valid
  • Point* getPosition()
  • void setPosition( Point pos )
  • void setPosition( Point* pos )

[top]

SpotLight

SpotLight is a subclass of the abstract class Light.
  • SpotLight( GLint lightNum )
    Create a SpotLight with light number equal to lightNum. lightNum must be between 0 and 8 to be valid
  • Point* getPosition()
  • void setPosition( Point pos )
  • void setPosition( Point* pos )
  • Vector* getDirection()
  • void setDirection( Vector dir )
  • void setDirection( Vector* dir )
  • GLfloat getCutoff()
  • void setCutoff( GLfloat cutoff )
    Set the cutoff angle for the cone. Acceptable values are between 0 and 90, or the special value of 180
  • GLfloat getExponent()
  • void setExponent( GLfloat exp )

[top]

Material

  • Material()
    Create a material that has all components set to (0,0,0,1) by default
  • Material( CSE40166_MaterialColor preDefinedColor )
    Create a material from a predefined color. Available values are: CSE40166_MATERIAL_WHITE, CSE40166_MATERIAL_BLACK, CSE40166_MATERIAL_BRASS, CSE40166_MATERIAL_REDPLASTIC, CSE40166_MATERIAL_GREENPLASTIC, CSE40166_MATERIAL_CYANRUBBER.
  • GLfloat* getAmbient()
  • void setAmbient( GLfloat amb[4] )
  • GLfloat* getDiffuse()
  • void setDiffuse( GLfloat diff[4] )
  • GLfloat* getSpecular()
  • void setSpecular( GLfloat spec[4] )
  • GLfloat* getEmissive()
  • void setEmissive( GLfloat emis[4] )
  • GLfloat getShininess()
  • void setShininess( GLfloat shin )
setCurrentMaterial( Material *mtl )
Set mtl to be the active material properties

[top]

PointBase

  • double getX()
  • void setX( double x )
  • double getY()
  • void setY( double y )
  • double getZ()
  • void setZ( double z )
  • double getW()
  • double* asArray()
    Return an array of doubles corresponding to the X,Y,Z,W values
  • double* asArray4D()
    Return an array of doubles corresponding to the X,Y,Z,W values
  • double* asArray3D()
    Return an array of doubles corresponding to the X,Y,Z values
  • double* asArray2D()
    Return an array of doubles corresponding to the X,Y values
  • double* asArray1D()
    Return an array of doubles corresponding to the X value
  • char* toString()
    Return the variables in a string with the format "(x, y, z, w)".

[top]

Point

Point is a subclass of PointBase.
  • Point()
    Create a point set to (0,0,0) by default
  • Point( int a, int b, int c )
    Create a point set to (a, b, c)
  • Point( double a, double b, double c)
    Create a point set to (a, b, c)
  • double at( int i )
    Return coordinate at index i. Acceptable values of i = [0,2]. i=0, a. i=1, b. i=2, c.
  • void glVertex()
    Call glVertex3f(a, b, c)
  • void glTexCoord()
    Call glTexCoord2f(a, b)
The +=, -=, *=, /=, *, /, *, -, + operators are all defined for a Point class. Notes: You may add/subtract/multiply/divide a Point and a scalar which returns a Point. You may subtract a Point from a Point, which return a Vector. You may also add two Points together (to ease Point averaging). Also, the == and != operators are defined for two Points.


[top]

Vector

Vector is a subclass of PointBase.
  • Vector()
    Create a vector set to (0,0,0) by default
  • Vector( int a, int b, int c )
    Create a vector set to (a,b,c)
  • Vector( double a, double b, double c )
    Create a vector set to (a,b,c)
  • double magSq()
    Return the magnitude squared of the vector
  • double mag()
    Return the magnitude of the vector
  • void normalize()
    Normalize the vector
  • double at( int i )
    Return coordinate at index i. Acceptable values of i = [0,2]. i=0, a. i=1, b. i=2, c.
  • void glNormal()
    Call glNormal3f(a, b, c)
Vector cross( Vector a, Vector b )
Return the result of the cross product of a cross b

double dot( Vector a, Vector b )
Return the result of the dot product of a dot b

The +=, -=, *=, /=, *, /, +, - operators are all defined for a Vector and a scalar. The == and != operators are defined for two Vectors.


[top]

Object

Class used for reading in *.obj files
  • Object()
    Object constructor. Must call loadObjectFile( string filename ) after initialization.
  • Object( string filename )
    Object constructor and load filename object file
  • ~Object()
    Object destructor
  • bool loadObjectFile( string filename )
    Returns result of loadObjectFile( filename, TRUE, TRUE )
  • bool loadObjectFile( string filename, bool INFO )
    Returns result of loadObjectFile( filename, INFO, TRUE )
  • bool loadObjectFile( string filename, bool INFO, bool ERRORS )
    Loads object file from filename. If INFO is true, displays informative debug information to terminal. If ERRORS is true, displays error debug information to terminal. Returns success or failure.
  • bool draw()
    loadObjectFile( ... ) compiles a display list of object information. draw() executes the display list
  • Point* getLocation()
    Returns a pointer to the point the object is located at
  • vector< Face* >* getFaces()
    Return a vector of Faces for each polygon face in the object. NOTE: This function will reparse the *.obj file provided to the object. It should only be called once within the code as after the object is read the faces will never change.

[top]

Face

  • Material* getMaterial()
  • void setMaeterial( Material* mtl )
  • GLuint getTextureHandle()
  • void setTextureHandle( GLuint texHandle )
  • bool getSmooth()
    Return if smooth shading is used for this face or not
  • void setSmooth( bool s )
  • Point getP()
  • void setP( Point p )
  • Point getPTexCoord()
  • void setPTexCoord( Point pTex )
  • Point getPNormal()
  • void setPNormal( Point pNorm )
  • Point getQ()
  • void setQ( Point q )
  • Point getQTexCoord()
  • void setQTexCoord( Point qTex )
  • Point getQNormal()
  • void setQNormal( Point qNorm )
  • Point getR()
  • void setR( Point r )
  • Point getRTexCoord()
  • void setRTexCoord( Point rTex )
  • Point getRNormal()
  • void setRNormal( Point rNorm )
  • void draw( bool front = true )
    Draw the face, draws the front face by default
  • void drawFrontFace()
    Draws the front face
  • void drawBackFace()
    Draws the back face and reverses vertex normals
  • Point CenterOfMass()
    Compute the center of mass of the face

[top]

Listener

  • Listener()
    Create a Listener positioned at (0,0,0) facing (0,0,-1) with upVector (0,1,0) and velocity (0,0,0)
  • Point getPosition()
  • void setPosition( Point pos )
  • Vector getVelocity()
  • void setVelocity( Vector vel )
  • Vector getLookAt()
  • void setLookAt( Vector la )
  • Vector getUpVector()
  • void setUpVector( Vector up )
  • float getTheta()
  • void setTheta( float theta )
    Sets the listener's theta value and recomputes the listener's lookAt vector
  • float getPhi()
  • void setPhi( float phi )
    Sets the listener's phi value and recomputes the listener's lookAt vector
  • void listen()
    Call the necessary alListener() parameters with the current position, velocity, and orientation
  • void moveForward()
    Move the listener's position one step forward along the lookAt vector
  • void moveBackward()
    Move the listener's position one step backward along the lookAt vector
  • void turnLeft()
    Rotate the listener's theta value to the left
  • void turnRight()
    Rotate the listener's theta value to the right
  • void lookUp()
    Rotate the listener's phi value upwards
  • void lookDown()
    Rotate the listener's phi value downwards

[top]

Buffer

  • Buffer()
    Constructor method. Generates buffer handle
  • Buffer( char* filename )
    Constructor method. Generates buffer handle and loads in WAV file of given filename
  • void loadWAVFile( char* filename )
    Loads in a WAV file of given filename
  • ALuint getBufferHandle()
    Returns handle to buffer

[top]

Source

  • Source()
    Constructor method. Generates source handle and position source at (0,0,0) with velocity (0,0,0)
  • Source( Buffer buf )
    Constructor method. Generates source handle and position source at (0,0,0) with velocity (0,0,0) and sets the source's buffer to buf
  • ALfloat getPitch()
  • void setPitch( ALfloat pitch )
  • ALfloat getGain()
  • void setGain( ALfloat gain )
  • Point getPosition()
  • void setPosition( Point pos )
  • Vector getVelocity()
  • void setVelocity( Vector vel )
  • Buffer getBuffer()
  • void setBuffer( Buffer buf )
  • ALboolean getLoop()
  • void setLoop( ALboolean loop )
  • ALuint getSourceHandle()
    Returns handle to source
  • void start()
    Start playing the source's buffer at given location with set parameters
  • void play()
    Start playing the source's buffer at given location with set parameters
  • void stop()
    Stop playing the source's buffer
  • void pause()
    Pause the source's buffer

[top]

Revision History

  • v1.5 - 12/06/2012
    • Added asArray4D(), asArray3D(), asArray2D(), asArray1D() to PointBase class
    • Added Listener class for use with OpenAL
    • Added Buffer class for use with OpenAL
    • Added Source class for use with OpenAL
  • v1.4 - 11/12/2012
    • Per request, added toString() to PointBase class.
    • Per request, added == and != operators to Point and Vector classes.
  • v1.3 - 11/09/2012
    • Corrected bug when SOIL reads an object with a texture consisting of 4 color channels. Now properly reads in RGBA when registering texture.
  • v1.2 - 10/31/2012
    • Corrected bug when linking against multiple class and object files. No longer gives multi-declaration error.
    • Added Camera::getView() per request which returns the view vector for the camera.
  • v1.1 - 10/22/2012
  • v1.0 - 10/17/2012
    • Initial Release

[top]

Download Past Versions


[top]