oCOSMO 3D User manual

Category
Software manuals
Type
User manual
Cosmo 3D
â„¢
Programmer’s Guide
Document Number 007-3445-002
Cosmo 3D
â„¢
Programmer’s Guide
Document Number 007-3445-002
CONTRIBUTORS
Written by George Eckel
Illustrated by Dany Galgani and Martha Levine
Production by Carlos Miqueo
Engineering contributions by Brian Cabral, John Rohlf, Brad Grantham, Chris
Tanner, Rich Silba, Tonia Spyridi, Michael Jones, Trina Roy, Chris Walker
St. Peter’s Basilica image courtesy of ENEL SpA and InfoByte SpA. Disk Thrower
image courtesy of Xavier Berenguer, Animatica.
© 1998, Silicon Graphics, Inc.— All Rights Reserved
The contents of this document may not be copied or duplicated in any form, in whole
or in part, without the prior written permission of Silicon Graphics, Inc.
RESTRICTED RIGHTS LEGEND
Use, duplication, or disclosure of the technical data contained in this document by
the Government is subject to restrictions as set forth in subdivision (c) (1) (ii) of the
Rights in Technical Data and Computer Software clause at DFARS 52.227-7013
and/or in similar or successor clauses in the FAR, or in the DOD or NASA FAR
Supplement. Unpublished rights reserved under the Copyright Laws of the United
States. Contractor/manufacturer is Silicon Graphics, Inc., 2011 N. Shoreline Blvd.,
Mountain View, CA 94043-1389.
Silicon Graphics, the Silicon Graphics logo and OpenGL are registered trademarks,
and Cosmo 3D, ImageVision, Inspector, OpenGL Optimizer, Open Inventor, and
Performer are trademarks, of Silicon Graphics, Inc. Java is a registered trademark of
Sun Microsystems, Inc.
iii
Contents at a Glance
List of Figures xxi
List of Tables xxiii
About This Guide xxv
What This Guide Contains xxv
Related Reading xxvii
Who Should Read This Guide xxvii
What You Should Know Before Reading This Guide xxvii
Suggestions for Further Reading xxvii
Style Conventions xxviii
1. Getting Started with Cosmo 3D 1
Understanding a Cosmo 3D Scene Graph 2
Scene Graph Base Classes 2
Scene Graph Construction Classes 7
Classes That Determine How Things Are Drawn 12
Classes defining Geometric Objects 13
Steps for Creating and Displaying a Simple Scene Graph 13
2. Creating Geometries 15
Geometry Terminology 16
Using Large Geometries 16
Creating csGeoSet Objects 17
csGeoSet Attributes 20
Setting Attributes 22
Cosmo 3D-Derived csGeoSet Objects 30
iv
Contents at a Glance
3. Specifying the Appearance of Geometries 35
csContext Overview 35
Changing the Context 39
Using csAppearance 40
Applying Textures to Geometries 42
Material Settings 51
Shade Model Settings 53
Transparency Settings 53
4. Scene Graph Nodes 55
What Is a Node 56
Leaf Nodes 57
Group Nodes 58
Setting the Values in Scene Graph Nodes 61
5. Building a Scene Graph 65
Creating Scene Graphs 66
Diagramming Scene Graphs 69
Altering Scene Graphs 73
Loading a VRML Scene Graph 74
Saving Scene Graphs 75
Troubleshooting Scene Graph Construction 75
6. Placing Shapes in a Scene 77
Creating a Sense of Depth 77
Transforming Shapes to New Locations, Sizes, and Orientations 79
7. Traversing the Scene Graph 83
Scene Graph Actions 83
The Order In Which Actions Are Passed Between Nodes 86
8. Lighting and Fog 89
Using Lights in Scenes 89
Limiting the Scope of Lights 92
Using Fog in Scenes 93
Contents at a Glance
v
9. Viewing the Scene 97
Setting the Screen Display of the Scene 97
csCamera 99
csOrthoCamera 101
csPerspCamera 101
csFrustumCamera 105
10. Scene Graph Engines 107
Engines 107
Engines that Interpolate Values 110
Engines That Change Shapes 117
11. Sensors 121
csTimeSensor 122
csSphereSensor 126
csPlaneSensor 130
csTouchSensor 134
12. User Interface Mechanisms 137
Creating a csWindow 137
Handling User Input 139
Selecting Screen Objects 140
Creating Your Own Window 143
13. Multiprocessing 145
Implementing Multiprocessing 146
Thread Blocking 148
Multithreaded Example 150
14. Optimizing Rendering 151
Face Culling 152
Back Patch Culling 152
Culling the View Frustum 160
Level of Detail Reduced for Performance 160
Performance Programming Techniques 163
vi
Contents at a Glance
15. Adding Sounds To Virtual Worlds 167
Overview 168
How to Play a Sound File 173
Specifying Audio Files 174
Playing Sound in Immediate Mode 177
A. Cosmo Basic Types 179
Array Storage Class Types 180
Vector Classes 183
Bounding Volumes 187
Field Classes 188
Other Math Classes 191
B. Cosmo 3D Sample Application 193
Cube.cxx Explained 195
Scene Graph for Cube.cxx 203
C. Cosmo 3D Class Hierarchy 209
Index 215
vii
Contents
List of Figures xix
List of Tables xxi
About This Guide xxiii
What This Guide Contains xxiii
Related Reading xxv
Who Should Read This Guide xxv
What You Should Know Before Reading This Guide xxv
Suggestions for Further Reading xxv
Style Conventions xxvi
1. Getting Started with Cosmo 3D 1
Understanding a Cosmo 3D Scene Graph 2
Scene Graph Base Classes 2
The csObject Class 3
Reference Counting 3
Runtime Typing 4
The csContainer Class 5
The csField Class 5
Field Access 5
Single-Item and Multi-Item Fields 6
The csNode Class 6
Scene Graph Construction Classes 7
The csGroup Class 8
The csTransform Class 9
The csShape Class 11
The csAppearance Class 11
The csGeometry Class 11
viii
Contents
Classes That Determine How Things Are Drawn 12
csContext 12
The csEnvironment Classes 12
Classes defining Geometric Objects 13
Steps for Creating and Displaying a Simple Scene Graph 13
2. Creating Geometries 15
Geometry Terminology 16
Using Large Geometries 16
Creating csGeoSet Objects 17
csGeoSet Fields 19
Setting the Number of Primitives 19
csGeoSet Attributes 20
Attribute Bindings 20
Setting Attribute Bindings 21
Setting Attributes 22
Indexing Attributes 23
When to Index Attributes 24
Specifying Attributes 26
Using More Specific Attribute Arrays 26
Indexing Attributes 28
Setting Attributes Example 28
Editing Attribute Arrays 29
Cosmo 3D-Derived csGeoSet Objects 30
Using csPointSet 30
Using csLineSet 31
Using csIndexedLineSet 31
Using csLineStripSet 31
Using csTriSet 31
Using csTriFanSet 32
Using csTriStripSet 32
Using csPolySet 33
Using csQuadSet 33
Using csIndexedFaceSet 33
Contents
ix
3. Specifying the Appearance of Geometries 35
csContext Overview 35
State Machine 36
Inheritance Mask 36
Accessing States 37
What Modifies the Graphics State? 38
Traversal Order 38
csContext in Multi-threaded Programs 38
Overriding Appearances and Geometry Properties with csContext 39
Making the Screen One Color 39
Changing the Context 39
Using csAppearance 40
Inheriting Appearance Values 40
Setting Appearance Fields Locally 40
Lazy Updating of Appearance Values 41
Applying Textures to Geometries 42
Texture Map Coordinates 42
Applying a Texture 43
Specifying a Texture Image 44
Texture Mode Settings 44
Texture Environment Settings 46
Color Components 47
Specifying Texture Coordinates 48
Using the Default 48
Using the Texture Coordinate Function 48
Setting the csTexGen Mode 50
Enabling Texture Generation 50
Material Settings 51
Material Example 52
Filling Geometries 52
Shade Model Settings 53
Transparency Settings 53
Producing Transparency Without Blending 53
x
Contents
4. Scene Graph Nodes 55
What Is a Node 56
Node Types 56
Leaf Nodes 57
csShape 57
Group Nodes 58
Group Node Types 58
Using csSwitch to Switch Between Nodes 59
Using csBillboard 60
Setting the Values in Scene Graph Nodes 61
Using set() and get() Methods to Set and Get Single-Value Fields 61
Using Tokens to Set and Get Single-Value Fields 62
Using set() and get() Methods to Set and Get Multiple-Value Fields 62
Using Tokens to Set and Get Multiple-Value Fields 63
5. Building a Scene Graph 65
Creating Scene Graphs 66
Root Node 66
Applying Actions to Multiple Root Nodes 67
Creating A Sample Scene Graph 68
Diagramming Scene Graphs 69
Scene Graph Diagrams At A Glance 69
Altering Scene Graphs 73
Loading a VRML Scene Graph 74
Saving Scene Graphs 75
Troubleshooting Scene Graph Construction 75
6. Placing Shapes in a Scene 77
Creating a Sense of Depth 77
Overriding the Default Order of Layering Shapes 78
Contents
xi
Transforming Shapes to New Locations, Sizes, and Orientations 79
Placing Transform Nodes 79
Setting the Transformation 80
Ordering Transformations 81
Placing Geometries in World Space 82
Cosmo 3D Matrices 82
7. Traversing the Scene Graph 83
Scene Graph Actions 83
Action Types 84
csAction 84
Rendering the Scene 85
Playing Sound Files 86
The Order In Which Actions Are Passed Between Nodes 86
Top-Down Traversals 86
8. Lighting and Fog 89
Using Lights in Scenes 89
csLight 90
csDirectionalLight 90
csSpotLight 91
csPointLight 91
Limiting the Scope of Lights 92
The Scope of the Light Array 92
csEnvironment Methods 92
Using Fog in Scenes 93
Uses of Fog in Cosmo 3D Applications 93
How to Use Fog in Cosmo 3D Applications 94
Enabling Fog 94
How to Use Fog 95
9. Viewing the Scene 97
Setting the Screen Display of the Scene 97
Using a Camera to View a Scene 98
csCamera 99
xii
Contents
csOrthoCamera 101
csPerspCamera 101
Setting the Frustum 102
Setting the Clip Planes 103
Setting the Fields of View 103
Offsetting the Fields of View 103
csFrustumCamera 105
10. Scene Graph Engines 107
Engines 107
Input and Output Fields 108
Connecting Engines to Other Nodes 108
Connecting Engines to Other Engines 108
Engine Types 109
Engines that Interpolate Values 110
Interpolator Engine Terminology 111
csSpline 112
Keys and Key Values 113
csSpline Fields 113
csColorInterpolator 114
csCoordinateInterpolator 114
csNormalInterpolator 114
csOrientationInterpolator 115
csPositionInterpolator 116
csScalarInterpolator 116
csSelectorEng3F and csSelectorEng4F 117
Engines That Change Shapes 117
csMorphEng 117
csMorphEng Fields 118
csMorphEng3f and csMorphEng4f 118
csTransformEng 119
Contents
xiii
11. Sensors 121
csTimeSensor 122
Enabling csTimeSensor 122
Updating csTimeSensor 123
Updating with csWindow 123
Setting the Start and Stop Times 123
isActive 124
Setting Cycle Duration 124
Continuing Timer Events 125
Cycle Time Event 125
Fraction Changed Event 125
csSphereSensor 126
Virtual Sphere 126
Offsetting the Rotation 126
csSphereSensor Events 127
Updating csSphereSensor 128
Setting Up csSphereSensor 128
Scope of csSphereSensor 128
Rotating Geometry Using csSphereSensor 129
csPlaneSensor 130
Setting Up csPlaneSensor 130
Scope of csPlaneSensor 131
csPlaneSensor Events 131
Updating csPlaneSensor 132
Limiting Translations 132
Unclamped Translations 132
Local or World Translations 133
csPlaneSensor Offsets 133
xiv
Contents
csTouchSensor 134
Associating csTouchSensor and Geometry 134
Scope of csTouchSensor 135
csTouchSensor Output 135
isOver Event 135
Hit Events 136
touchTime Events 136
12. User Interface Mechanisms 137
Creating a csWindow 137
Manipulating the Window Stack 138
Handling User Input 139
Using Callback Functions 139
Querying Devices 140
Selecting Screen Objects 140
Using csIsectAction 140
Using Pick() 141
Storing Selected Screen Objects 142
Creating Your Own Window 143
Sample Window Code 143
13. Multiprocessing 145
Implementing Multiprocessing 146
Creating Threads 146
Starting Threads 147
Thread Parameters 148
Thread Blocking 148
Cleaning the csContext Fields 150
Multithreaded Example 150
14. Optimizing Rendering 151
Face Culling 152
Contents
xv
Back Patch Culling 152
Back Patch Culling Advantage 153
When to Use Back Patch Culling 154
Method of Calculation 154
Updating the View Vector 155
Normals 155
Choosing the Type of Normal 156
Using Back Patch Culling 157
Enabling Back Patch Culling 157
Building Back Patch Culling Data for a csGeoSet 158
Updating Back Patch Culling Data 158
Back Patch Culling Code 159
Culling the View Frustum 160
Level of Detail Reduced for Performance 160
Choosing a Child Node Based on Range 161
Transitioning Between Levels of Detail 162
Performance Programming Techniques 163
Minimize Use of csAppearance Fields 163
Minimize Use of csAppearance Modes 163
Indexing csGeoSet Attributes 164
Setting the Transformation Matrix Directly 164
Compiling Part of a Scene Graph 164
15. Adding Sounds To Virtual Worlds 167
Overview 168
csSound Fields 169
Choosing Sound Samples to Play 169
Sound Priority 170
Playing the Sound File 170
Locating and Directing the Sound 170
Reverse Direction Sound 172
How to Play a Sound File 173
xvi
Contents
Specifying Audio Files 174
Manipulating the Audio Samples Directly 176
Example Setting a csAudioSamples Node 176
Playing Sound in Immediate Mode 177
csSoundPlayer Methods 177
A. Cosmo Basic Types 179
Array Storage Class Types 180
Data Class 180
Array Classes 181
Array Methods 181
Returning Array Data 183
Vector Classes 183
Vector Math 184
Vector Methods 184
csVec3s 186
csVec4ub Methods 186
Transforming csVec3f Vectors 186
Bounding Volumes 187
Field Classes 188
csField 189
csFieldInfo 189
csMField 189
csAtomField 190
csArrayField 190
Other Math Classes 191
csSeg 191
csPlane 192
csFrustum 192
Contents
xvii
B. Cosmo 3D Sample Application 193
Cube.cxx Explained 195
Understanding the Different Parts of Cube.cxx 202
Scene Graph for Cube.cxx 203
Relating Local Space to World Space 204
Creating the User Interface 206
Rendering World Space 206
Summary 207
C. Cosmo 3D Class Hierarchy 209
Index 215
xix
List of Figures
Figure 1-1 Cube Scene Graph 8
Figure 1-2 Two Transformations into World Space 10
Figure 2-1 Primitives in a csGeoSet 18
Figure 2-2 Sequential Specification of Attributes Per Primitive 23
Figure 2-3 Indexed Attributes 24
Figure 2-4 Deciding Whether to Index Attributes 25
Figure 2-5 Stride and Offset Values 27
Figure 2-6 TriFanSet 32
Figure 2-7 Triangle Strip 32
Figure 3-1 Inheritance Mask 37
Figure 3-2 Applying a Texture to a Geometry 42
Figure 3-3 Texture Coordinates 43
Figure 3-4 Non-Perspective and Perspective Modes 45
Figure 3-5 Texture Coordinate Function 48
Figure 3-6 Repeated Texture on a Geometry 49
Figure 4-1 A Simple Grouping 58
Figure 4-2 Setting Single and Multiple-Value Variables 61
Figure 5-1 Scene Graph 65
Figure 5-2 Multiple Root Nodes 67
Figure 5-3 Simple Scene Graph 69
Figure 5-4 Two Sets of Data Rendered Differently 70
Figure 5-5 Torso Subgraph 71
Figure 5-6 Showing the Same Geometry in Two Locations 72
Figure 6-1 Placement of csTransform Nodes 79
Figure 6-2 Scaling in Different Orientations 81
Figure 6-3 Order of Transformations 81
Figure 7-1 The Flow of an Action Through A Scene Graph 87
xx
List of Figures
Figure 9-1 Viewport 98
Figure 9-2 Aspect Ratio 99
Figure 9-3 Changing the Window Without Changing the Image’s Aspect 100
Figure 9-4 Perspective Explained 102
Figure 9-5 Horizontal and Vertical Fields of View Offsets 104
Figure 10-1 Keys and Key Values 110
Figure 10-2 Engine Terminology 111
Figure 10-3 Spline 112
Figure 11-1 Rotation and trackPoint Representations 127
Figure 11-2 Placing csSphereSensor in a Scene Graph 129
Figure 11-3 Placing csPlaneSensor in a Scene Graph 131
Figure 11-4 Placing csTouchSensor in a Scene Graph 134
Figure 12-1 Ray Pick Action 141
Figure 12-2 Creating Your Own Window 143
Figure 13-1 Multiprocessing 145
Figure 13-2 Blocking Action of Multiple Threads 149
Figure 14-1 Before and After Back Patch Culling 153
Figure 14-2 Viewing Angle 154
Figure 14-3 Face and Primitive Normals 155
Figure 14-4 Direction of Normals 156
Figure 14-5 csLOD Ranges 162
Figure 14-6 Arranging Scene Graph Nodes 165
Figure 15-1 Sound Classes 168
Figure 15-2 Sound Direction 171
Figure 15-3 Forward and Reverse Sound Propagation 172
Figure A-1 Bounding Sphere 187
Figure B-1 Cube Application 194
Figure B-2 Cube Scene Graph 203
Figure B-3 Two Transformations Into World Space 205
  • Page 1 1
  • Page 2 2
  • Page 3 3
  • Page 4 4
  • Page 5 5
  • Page 6 6
  • Page 7 7
  • Page 8 8
  • Page 9 9
  • Page 10 10
  • Page 11 11
  • Page 12 12
  • Page 13 13
  • Page 14 14
  • Page 15 15
  • Page 16 16
  • Page 17 17
  • Page 18 18
  • Page 19 19
  • Page 20 20
  • Page 21 21
  • Page 22 22
  • Page 23 23
  • Page 24 24
  • Page 25 25
  • Page 26 26
  • Page 27 27
  • Page 28 28
  • Page 29 29
  • Page 30 30
  • Page 31 31
  • Page 32 32
  • Page 33 33
  • Page 34 34
  • Page 35 35
  • Page 36 36
  • Page 37 37
  • Page 38 38
  • Page 39 39
  • Page 40 40
  • Page 41 41
  • Page 42 42
  • Page 43 43
  • Page 44 44
  • Page 45 45
  • Page 46 46
  • Page 47 47
  • Page 48 48
  • Page 49 49
  • Page 50 50
  • Page 51 51
  • Page 52 52
  • Page 53 53
  • Page 54 54
  • Page 55 55
  • Page 56 56
  • Page 57 57
  • Page 58 58
  • Page 59 59
  • Page 60 60
  • Page 61 61
  • Page 62 62
  • Page 63 63
  • Page 64 64
  • Page 65 65
  • Page 66 66
  • Page 67 67
  • Page 68 68
  • Page 69 69
  • Page 70 70
  • Page 71 71
  • Page 72 72
  • Page 73 73
  • Page 74 74
  • Page 75 75
  • Page 76 76
  • Page 77 77
  • Page 78 78
  • Page 79 79
  • Page 80 80
  • Page 81 81
  • Page 82 82
  • Page 83 83
  • Page 84 84
  • Page 85 85
  • Page 86 86
  • Page 87 87
  • Page 88 88
  • Page 89 89
  • Page 90 90
  • Page 91 91
  • Page 92 92
  • Page 93 93
  • Page 94 94
  • Page 95 95
  • Page 96 96
  • Page 97 97
  • Page 98 98
  • Page 99 99
  • Page 100 100
  • Page 101 101
  • Page 102 102
  • Page 103 103
  • Page 104 104
  • Page 105 105
  • Page 106 106
  • Page 107 107
  • Page 108 108
  • Page 109 109
  • Page 110 110
  • Page 111 111
  • Page 112 112
  • Page 113 113
  • Page 114 114
  • Page 115 115
  • Page 116 116
  • Page 117 117
  • Page 118 118
  • Page 119 119
  • Page 120 120
  • Page 121 121
  • Page 122 122
  • Page 123 123
  • Page 124 124
  • Page 125 125
  • Page 126 126
  • Page 127 127
  • Page 128 128
  • Page 129 129
  • Page 130 130
  • Page 131 131
  • Page 132 132
  • Page 133 133
  • Page 134 134
  • Page 135 135
  • Page 136 136
  • Page 137 137
  • Page 138 138
  • Page 139 139
  • Page 140 140
  • Page 141 141
  • Page 142 142
  • Page 143 143
  • Page 144 144
  • Page 145 145
  • Page 146 146
  • Page 147 147
  • Page 148 148
  • Page 149 149
  • Page 150 150
  • Page 151 151
  • Page 152 152
  • Page 153 153
  • Page 154 154
  • Page 155 155
  • Page 156 156
  • Page 157 157
  • Page 158 158
  • Page 159 159
  • Page 160 160
  • Page 161 161
  • Page 162 162
  • Page 163 163
  • Page 164 164
  • Page 165 165
  • Page 166 166
  • Page 167 167
  • Page 168 168
  • Page 169 169
  • Page 170 170
  • Page 171 171
  • Page 172 172
  • Page 173 173
  • Page 174 174
  • Page 175 175
  • Page 176 176
  • Page 177 177
  • Page 178 178
  • Page 179 179
  • Page 180 180
  • Page 181 181
  • Page 182 182
  • Page 183 183
  • Page 184 184
  • Page 185 185
  • Page 186 186
  • Page 187 187
  • Page 188 188
  • Page 189 189
  • Page 190 190
  • Page 191 191
  • Page 192 192
  • Page 193 193
  • Page 194 194
  • Page 195 195
  • Page 196 196
  • Page 197 197
  • Page 198 198
  • Page 199 199
  • Page 200 200
  • Page 201 201
  • Page 202 202
  • Page 203 203
  • Page 204 204
  • Page 205 205
  • Page 206 206
  • Page 207 207
  • Page 208 208
  • Page 209 209
  • Page 210 210
  • Page 211 211
  • Page 212 212
  • Page 213 213
  • Page 214 214
  • Page 215 215
  • Page 216 216
  • Page 217 217
  • Page 218 218
  • Page 219 219
  • Page 220 220
  • Page 221 221
  • Page 222 222
  • Page 223 223
  • Page 224 224
  • Page 225 225
  • Page 226 226
  • Page 227 227
  • Page 228 228
  • Page 229 229
  • Page 230 230
  • Page 231 231
  • Page 232 232
  • Page 233 233
  • Page 234 234
  • Page 235 235
  • Page 236 236
  • Page 237 237
  • Page 238 238
  • Page 239 239
  • Page 240 240
  • Page 241 241
  • Page 242 242
  • Page 243 243
  • Page 244 244
  • Page 245 245
  • Page 246 246
  • Page 247 247
  • Page 248 248
  • Page 249 249
  • Page 250 250
  • Page 251 251
  • Page 252 252
  • Page 253 253
  • Page 254 254
  • Page 255 255
  • Page 256 256
  • Page 257 257
  • Page 258 258
  • Page 259 259
  • Page 260 260
  • Page 261 261

oCOSMO 3D User manual

Category
Software manuals
Type
User manual

Ask a question and I''ll find the answer in the document

Finding information in a document is now easier with AI