Cameras and Light Chapter 4, The Inventor Mentor

Preview:

Citation preview

Cameras and Light

Chapter 4, The Inventor Mentor

Camera structure

Image plane

Focal length

Camera nodes

• Camera node should be near the top left

• Camera node generates a picture after it

• A scene should contain only one camera

• The camera position is set by current trans.

• Viewport – rectangular rendered area

How can we use more than one camera?

Built-in viewer• Using viewer (predefined camera)

– SoWinExaminerViewer * viewer = new SoWinExaminerViewer(window);

– viewer->setSceneGraph(root);– viewer->show();

• Using your own window– SoWinRenderArea *myRenderArea = new

SoWinRenderArea(window);– root -> addChild(myCamera)– myCamera->viewAll(root, myRenderArea-

>getViewportRegion());– myRenderArea->setSceneGraph(root);– myRenderArea->show();

Perspective camera

widthAngle = heightAngle*aspectRatio

Orthographic camera

width = height*aspectRatio

Orthographic – Perspective

SoCamera

• viewportMapping (SoSFEnum)– How to map camera to the viewport– Adjust the viewport (dead space remains)

• CROP_VIEWPORT_FILL_FRAME• CROP_VIEWPORT_LINE_FRAME• CROP_VIEWPORT_NO_FRAME

– Adjust the camera to fit the viewport (default)• ADJUST_CAMERA• Temporarily override aspectRatio

– Adjust the image (distortion)• LEAVE_ALONE

SoCamera• position (SoSFVec3f)

– Location of the camera viewpoint (origin).– Modified by the current transformation.

• orientation (SoSFRotation)– Orientation of camera’s viewing direction (V).– Camera rotation with respect to the default.

The default position and orientation of a camera is at (0,0,1)

looking along the negative z-axis. The up direction is (0, 1 ,0).

SoCamera• aspectRatio (SoSFFloat)

– Ratio of the camera viewing width to height.– Must be greater than 0– SO_ASPECT_SQUARE = 1/1– SO_ASPECT_VIDEO = 4/3– SO_ASPECT_HDTV = 16/9

• nearDistance (SoSFFloat)– Camera viewpoint to the near clipping plane.

SoCamera• farDistance (SoSFFloat)

– Camera viewpoint to the far clipping plane.

• focalDistance (SoSFFloat)• height / heightAngle (SoSFFloat)

SoCamera functions• void pointAt(SbVec3f &target)

– Sets the orientation towards specific target

• void viewAll(SoNode *root, SbViewportRegion &vpRegion, float slack = 1.0)– View the entire scene– Orientation does not change– Position, near distance and far distance change– SbViewportRegion vpRegion(myRenderArea->getSize());

Example

Lights in Inventor

• Light node in Inventor determines– What the light illuminates (following nodes)– Where it is located (affected by current

transformation)

• Light sources are cumulative

• SoTransformSeparator– Light should not be under standard separator– You can separate only light transformation– Only the light position can be changed

Light Nodes

• SoLight fields– On (SoSFBool)

• If the source is turned on / off

– Intensity (SOSFFloat)• 0 – minimum• 1 – maximum

– color (SOSFColor)• Color of the light

Light Nodes

• SoPointLight (Point Source)– location (SoSFVec3f)

• 3D location of a point light source • affected by current geometric transformation

Light Nodes

• SoDirectionalLight (Parallel source)– direction (SOSFVec3f)

• Direction of rays• Affected by current transformation

Light Nodes• SoSpotLight

– A point light restricted to a cone– location (SoSFVec3f)

• 3D location of a point light source • affected by current geometric transformation

– direction (SoSFVec3f)• primary direction of illumination

– dropOffRate (SoSFFloat)• rate at which the light intensity drops off from the primary

direction.• 0.0 = constant intensity• 1.0 = sharpest drop-off

Light Nodes• cutOffAngle (SoSFFloat)

– angle, in radians, where the intensity is 0.0– measured from one cone edge to the other

Light Nodes

• Directional lights are the fastest

• Spotlights are the slowest

• To increase speed use fewer lights

Multiple Lights Example

• The example contains:– A red stationary directional light– A green light moved back and forth by SoShuttle

Recommended