710 likes | 867 Views
Chapter 4 – Object Manipulation in VRML. Understanding Coordinate System. VRML defines the unit of measure of the world coordinate system to be metres All other coordinate systems are built from transformations based from the world coordinate system
E N D
Understanding Coordinate System • VRML defines the unit of measure of the world coordinate system to be metres • All other coordinate systems are built from transformations based from the world coordinate system • The VRML convention that one unit equals one meter • In VRML, we can create any number of coordinate systems
Understanding Coordinate System • Each new coordinate system is positioned or translated relative to the origin of another coordinate system • When a new coordinate system is relative to another, we say that the new coordinate system is a child coordinate system that is nested within the within the parent coordinate system • The entire family tree of coordinate systems including any shape we build within those coordinate system is called the scene graph
Understanding Coordinate System • Try to visualize the coordinate system as indicated in the diagram below
Understanding Coordinate System • The ability to create coordinate systems is a very powerful feature of VRML • Consider the steps in placing the lamp on the table while the table is inside a room • We need to perform the following steps: • Create a lamp, building each of its components relative to a lamp coordinate system • Create a table, building each of its components relative to a table coordinate system
Understanding Coordinate System • Place the lamp on the table by positioning the lamp coordinate system relative to the table coordinate system • Now the lamp coordinate system is a child of the table coordinate system • Create a room, building each of its components relative to a room coordinate system • Place the table (and its lamp) by positioning the table coordinate system relative to the room coordinate system
Translating and Grouping Coordinate Systems • We need to use a Transform node to create a new coordinate system and specify the position or translation relative to a parent coordinate system • The Transform node is similar to the Group node in that it contains a list of child nodes • These child nodes could be Shape node, Group node or Transform nodes • All of the child nodes are built at the origin within the Transform node’s coordinate system
Translating and Grouping Coordinate Systems • All of the child nodes are built at the origin within the Transform node’s coordinate system • If the position of that node changes, all its child nodes will change accordingly with the changed coordinate system • Like Shape and Group nodes, the Transform node may be the child of a parent Group or Transform node
Translating and Grouping Coordinate Systems • The coordinate system of the parent node is the parent coordinate system of the Transform node coordinate system • If the root node is a Transform node, then the parent coordinate system is the world coordinate system of the VRML file
The Transform Node • The Transform node creates a new coordinate system relative to its parent node coordinate system Transform { children [ ] # exposedField MFNode translation 0.0 0.0 0.0 # exposedField SFVec3f rotation 0.0 0.0 1.0 0.0 # exposedField SFRotation scale 1.0 1.0 1.0 # exposedField SFVec3f scaleOrientation 0.0 0.0 1.0 0.0 # exposedField SFRotation bboxCenter 0.0 0.0 0.0 # field SFVec3f bboxSize -1.0 -1.0 -1.0 # field SFVec3f center 0.0 0.0 0.0 # exposedField SFVec3f addChildren # eventIn MFNode removeChildren # eventOut MFNode }
The Transform Node • The value of the children exposed field specifies a list of child nodes to be included in the group • Typical values in the children are the Shape nodes, Group nodes and Transform nodes • The value of the translation exposed field specify the distances in X, Y, Z directions • The value of the translation exposed field can be changed by routing an event to the exposed field’s implied set_translation eventIn. • When the event is received, the translation field is set and the new translation is sent using the exposed field’s implied translation_changed eventOut.
Translating 2.0 units along x-axis and building Cylinder #VRML V2.0 utf8 Transform { translation 2.0 0.0 0.0 children [ Shape { appearance Appearance { material Material { } } geometry Cylinder { } } ] }
Translating -2.0 units along x-axis and building Cylinder #VRML V2.0 utf8 Transform { translation -2.0 0.0 0.0 children [ Shape { appearance Appearance { material Material { } } geometry Cylinder { } } ] }
Translating 2.0 units along y-axis and building Cylinder #VRML V2.0 utf8 Transform { translation 0.0 2.0 0.0 children [ Shape { appearance Appearance { material Material { } } geometry Cylinder { } } ] }
Translating 2.0 units along z-axis and building Cylinder #VRML V2.0 utf8 Transform { translation 0.0 0.0 2.0 children [ Shape { appearance Appearance { material Material { } } geometry Cylinder { } } ] }
Translating along x-, y-, z-axis and building Cylinder #VRML V2.0 utf8 Transform { translation 2.0 1.0 -2.0 children [ Shape { appearance Appearance { material Material { } } geometry Cylinder { } } ] }
Building Shapes in Multiple Coordinate Systems #VRML V2.0 utf8 Group { children [ # Draw the hut walls Shape { appearance DEF White Appearance { material Material { } } geometry Cylinder { height 2.0 radius 2.0 } },
Building Shapes in Multiple Coordinate Systems # Draw the hut roof Transform { translation 0.0 2.0 0.0 children [ Shape { appearance USE White geometry Cone { height 2.0 bottomRadius 2.5 } } ] } ] }
Constructing Multiple Coordinate Systems #VRML V2.0 utf8 Group { children [ # Ground Shape { appearance DEF White Appearance { material Material { } } geometry Box { size 25.0 0.1 25.0 } },
Constructing Multiple Coordinate Systems # Left Column Transform { translation -2.0 3.0 0.0 children Shape { appearance USE White geometry Cylinder { radius 0.3 height 6.0 } } },
Constructing Multiple Coordinate Systems # Right Column Transform { translation 2.0 3.0 0.0 children Shape { appearance USE White geometry Cylinder { radius 0.3 height 6.0 } } },
Constructing Multiple Coordinate Systems # Archway span Transform { translation 0.0 6.05 0.0 children Shape { appearance USE White geometry Box { size 4.6 0.4 0.6 } } } ] }
Nesting Coordinate Systems #VRML V2.0 utf8 Group { children [ # Ground Shape { appearance DEF White Appearance { material Material { } } geometry Box { size 25.0 0.1 25.0 } },
Nesting Coordinate Systems # First archway # Left Column DEF LeftColumn Transform { translation -2.0 3.0 0.0 children DEF Column Shape { appearance USE White geometry Cylinder { radius 0.3 height 6.0 } } },
Nesting Coordinate Systems # Right Column DEF RightColumn Transform { translation 2.0 3.0 0.0 children USE Column }, # Archway span DEF ArchwaySpan Transform { translation 0.0 6.05 0.0 children Shape { appearance USE White geometry Box { size 4.6 0.4 0.6 } } },
Nesting Coordinate Systems # Second archway Transform { translation 0.0 0.0 -2.0 children [ USE LeftColumn, USE RightColumn, USE ArchwaySpan ] } ] }
Rotating Shapes • In order to make the object more realistic, we must also control the orientation or rotation using the rotation field of the Transform node • A rotation axis is an imaginary line about which a coordinate system in rotated • A rotation axis can point to any direction in space • In order to specify a direction for a rotation axis, one could imagine drawing a line between two coordinates in space
Rotating Shapes • Usually, one coordinate corresponds to the origin. Therefore in specifying a rotation axis, (0, 1.0, 0) and (0, 2.0, 0) are all equivalent as they all point upwards • In addition to specifying a rotation axis, we must also indicate how much we want the new coordinate system to rotate about that axis and this value is measured in radian • By default, the centre of rotation is the origin of that coordinate system
Rotating Shapes • Using the Transform node, we could specify the 3D coordinates for rotation centre within a new coordinate system Transform { children [ ] # exposedField MFNode translation 0.0 0.0 0.0 # exposedField SFVec3f rotation 0.0 0.0 1.0 0.0 # exposedField SFRotation scale 1.0 1.0 1.0 # exposedField SFVec3f scaleOrientation 0.0 0.0 1.0 0.0 # exposedField SFRotation bboxCenter 0.0 0.0 0.0 # field SFVec3f bboxSize -1.0 -1.0 -1.0 # field SFVec3f center 0.0 0.0 0.0 # exposedField SFVec3f addChildren # eventIn MFNode removeChildren # eventOut MFNode }
Rotating Shapes • The values of the rotation exposed field specify a rotation axis about which the new coordinate system and a rotation angle, measured in radian • The rotation exposed field value can be changed by routing an event to the exposed field’s implied set_rotation eventIn. • When the event is received, the rotation field is set and the new rotation is sent using the exposed field’s implied rotation_changed eventOut
Rotating in Different Direction #VRML V2.0 utf8 Transform { rotation 1.0 0.0 0.0 0.785 children [ Shape { appearance Appearance { material Material { } } geometry Box { } } ] }
Rotating in Different Direction #VRML V2.0 utf8 Transform { rotation 1.0 0.0 0.0 - 0.785 children [ Shape { appearance Appearance { material Material { } } geometry Box { } } ] }
Rotating in Different Direction #VRML V2.0 utf8 Transform { rotation 0.0 1.0 0.0 0.785 children [ Shape { appearance Appearance { material Material { } } geometry Box { } } ] }
Rotating in Different Direction #VRML V2.0 utf8 Transform { rotation 0.0 0.0 1.0 -0.785 children [ Shape { appearance Appearance { material Material { } } geometry Box { } } ] }
Constructing Multiple Rotated Coordinate Systems #VRML V2.0 utf8 Group { children [ # Arm 1 DEF Arm1 Shape { appearance Appearance { material Material { } } geometry Cylinder { height 1.0 radius 0.1 } },
Constructing Multiple Rotated Coordinate Systems # Arm 2 Transform { rotation 1.0 0.0 0.0 1.047 children USE Arm1 }, # Arm 3 Transform { rotation 1.0 0.0 0.0 2.094 children USE Arm1 } ] }
Nesting Rotated Coordinate Systems #VRML V2.0 utf8 Group { children [ # Arm 1 DEF Arm1 Shape { appearance Appearance { material Material { } } geometry Cylinder { height 1.0 radius 0.1 } },
Nesting Rotated Coordinate Systems # Arm 2 DEF Arm2 Transform { rotation 1.0 0.0 0.0 1.047 children USE Arm1 }, # Arm 3 DEF Arm3 Transform { rotation 1.0 0.0 0.0 2.094 children USE Arm1 },
Nesting Rotated Coordinate Systems # Arms 4 and 5 Transform { rotation 0.0 1.0 0.0 1.785 children [ USE Arm2, USE Arm3 ] } ] }
Translating and Rotating Coordinate Systems #VRML V2.0 utf8 Group { children [ # Ground Shape { appearance DEF White Appearance { material Material { } } geometry Box { size 25.0 0.1 25.0 } },
Translating and Rotating Coordinate Systems # First archway # Left Column DEF LeftColumn Transform { translation -2.0 3.0 0.0 children DEF Column Shape { appearance USE White geometry Cylinder { radius 0.3 height 6.0 } } },
Translating and Rotating Coordinate Systems # Right Column DEF RightColumn Transform { translation 2.0 3.0 0.0 children USE Column }, # Archway span DEF ArchwaySpan Transform { translation 0.0 6.05 0.0 children Shape { appearance USE White geometry Box{ size 4.6 0.4 0.6 } } },
Translating and Rotating Coordinate Systems # Left Roof DEF LeftRoof Transform { translation -1.15 7.12 0.0 rotation 0.0 0.0 1.0 0.524 children DEF Roof Shape { appearance USE White geometry Box { size 2.86 0.4 0.6 } } },
Translating and Rotating Coordinate Systems # Right Roof DEF LeftRoof Transform { translation 1.15 7.12 0.0 rotation 0.0 0.0 1.0 -0.524 children USE Roof } ] }
Rotating about a Center Point #VRML V2.0 utf8 Group{ children [ # Lamp base Shape { appearance DEF White Appearance { material Material { } } geometry Cylinder { radius 0.1 height 0.01 } },
Rotating about a Center Point # Base joint Transform { translation 0.0 0.15 0.0 rotation 1.0 0.0 0.0 -0.7 center 0.0 -0.15 0.0 children [ # Lower arm Shape { appearance USE White geometry Cylinder { radius 0.01 height 0.3 } } ] } ] }
Scaling Shapes • VRML also enables us to scale a coordinate system, increasing or decreasing the size relative to a parent coordinate system • Shapes created within the scaled coordinate system are built at the new scale of the coordinate system • By scaling coordinate systems, we can enlarge or shrink shapes or groups of shapes • A scale factor is used in scaling and this scale factor is a multiplication factor. • If the value of this scale factor is 0.5, then the original object will shrink in size by half
Scaling Shapes • The Transform node’s scale field uses three scale factors, one along the x-axis, one along the y-axis and one along the z-axis • By default, the centre of scaling is the original of that coordinate system • Now we could make use of the combination of translation, rotation and scaling within the same Transform node to achieve the effect that we want • The value of the scale exposed field specify the scale factors in the X, Y and Z directions for the new coordinate system
Scaling Shapes • All the scale factors have to be a positive value • Values between 0.0 and 1.0 would imply reduction and values above 1.0 would imply expansion • The value of the scaleOrientation field specify a rotation axis and angle which to rotate the new coordinate system prior to scaling, and then unrotate if after scaling • Like the rotation field, the first values specify the X, Y and Z components of a 3D coordinate in the new, translated coordinate system and last value specifies the rotation angle measured in radian
Scaling in Different Direction #VRML V2.0 utf8 Transform { scale 2.0 1.0 1.0 children [ Shape { appearance Appearance { material Material { } } geometry Sphere { } } ] }