Lecture 3

Cameras, lights, properties, transformations

contains notes and images from:

Chapter 4 and 5 of Inventor Mentor


Cameras

#include <Inventor/nodes/SoOrthographicCamera.h>
#include <Inventor/nodes/SoPerspectiveCamera.h>

By default the camera is at 0,0,1 looking along the -Z axis

SoPerspectiveCamera * cam = new SoPerspectiveCamera;
SoOrthographicCamera * cam = new SoOrthographicCamera
cam->position
cam->nearDistance
cam->farDistace
cam->orientation

cam->pointAt
cam->viewAll


Lights

#include <Inventor/nodes/SoDirectionalLight.h>
#include <Inventor/nodes/SoPointLight.h>

SoDirectonalLight * dir = new SoDirectionalLight;
SoPointLight * poi = new SoPointLight;

both->color.setValue(1.0, 1.0, 1.0);
both->intensity.setValue(0.5);
both->on.setValue(FALSE);
poi->location.setValue(1.0, 5.0, -10.5);
dir->direction.setValue(-1.0, 0.0, 4.5);


Properties

#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoShapeHints.h>
#include <Inventor/nodes/SoDrawStyle.h>
#include <Inventor/nodes/SoEnvironment.h>
#include <Inventor/nodes/SoComplexity.h>

SoMaterial * mat = new SoMaterial
mat->ambientColor.setValue(0.2, 0.2, 0.2);
mat->diffuseColor.setValue(0.8, 0.8, 0.8);
mat->specularColor.setValue(0.0, 0.0, 0.0);
mat->emissiveColor.setValue(0.0, 0.0, 0.0);
mat->shininess = 0.2;
mat->transparency = 0.5;

Material {

ambientColor 0.2 0.2 0.2

diffuseColor 0.8 0.8 0.8

specularColor 0 0 0

emissiveColor 0 0 0

shininess 0.2

transparency 0.5

}

SoShapeHints * hints = new SoShapeHints;
hints->shapeType.setValue(SoShapeHints::SOLID);
hints->faceType.setValue(SoShapeHints::CONVEX);
hints->vertexOrdering.setValue(SoShapeHints::CLOCKWISE);
hints->vertexOrdering.setValue(SoShapeHints::COUNTERCLOCKWISE);
root->addChild(hints);

ShapeHints {

vertexOrdering CLOCKWISE

shapeType CONVEX

faceType CONVEX

}

SoEnvironment * env = new SoEnvironment;
env->ambientIntensity.setValue(0.2);
env->ambientColor.setValue(1.0, 1.0, 1.0);
root->addChild(env);

Environment {

ambientIntensity 0.2

ambientColor 1 1 1

}

SoDrawStyle * sty = new SoDrawStyle
sty->style = SoDrawStyle::FILLED
sty->style = SoDrawStyle::LINES
sty->style = SoDrawStyle::POINTS
sty->style = SoDrawStyle::INVISIBLE
sty->lineWidth.setValue(5);
sty->pointSize.setValue(5);
root->addChild(sty);


DrawStyle {

style FILLED

pointSize 5

lineWidth 5

}

SoComplexity * comp = new SoComplexity;
comp->value.setValue(0.25);
comp->textureQuality.setValue(0.5);
root->addChild(comp0);

Complexity {

value 0.25

textureQuality 0.5

}


Transformations

#include <Inventor/nodes/SoRotation.h>
#include <Inventor/nodes/SoRotationXYZ.h>
#include <Inventor/nodes/SoScale.h>
#include <Inventor/nodes/SoTransform.h>
#include <Inventor/nodes/SoTranslation.h>

SoRotation * ro = new soRotation;
ro->rotation.setValue(SbVec3f(0,1,0), angle * PI);

Rotation {

rotation 0 1 0 1.343

}

SoRotationXYZ * rot = new SoRotationXYZ;
rot->angle = 3.14159;
rot->axis = SoRotationXYZ:: Z;


RotationXYZ {

axis Z

angle 3.14159

}

SoScale * sca = new SoScale;
sca->scaleFactor.setValue(0.4, 0.4, 0.6);

Scale {

scaleFactor 0.4 0.4 0.6

}

SoTransform * trans = new SoTransform;
trans->translation.setValue(1.0, 2.5, 3.5);
trans->scaleFactor.setVlaue(2.0, 2.0, 2.0)
trans->rotation.setValue(SbVec3f(0, 1, 0), 1.57);

Transform {

translation 1.0 2.5 3.5

rotation 0 1 0 1.57

scaleFactor 2.0 2.0 2.0
}

SoTranslation * lat = new SoTranslation;
lat->translation.setValue(0.0, 0.6, 1.5);

Translation {

translation 0 0 0

}


Interfacing with GLUT

int globalMouseX, globalMouseY;

void parsekey_special(int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_UP: mySwitch->whichChild = 1;
break;

case GLUT_KEY_DOWN: mySwitch->whichChild = 2;
break;

case GLUT_KEY_LEFT: mySwitch->whichChild = 3;
break;

case GLUT_KEY_RIGHT: mySwitch->whichChild = 4;
break;
}

}

void processKey(unsigned char key, int x, int y)
{
switch(key)
{
case 'A': mySwitch->whichChild = 1;
break;
}
}

void mousemover(int x, int y)
{
globalMouseX = x;
globalMouseY = y;
}

in main:

glutKeyboardFunc(processKey);
glutSpecialFunc(parsekey_special);

glutMotionFunc(NULL); // moving while button is down
glutPassiveMotionFunc(mousemover);



Coming Next Time

Text, Textures, Files, and Engines


last revision 1/14/01