| 101 | |
| 102 | == Coordinate system == |
| 103 | Copy the following code to your level file to make the axis of the coordinate system visible. The x-axis is coloured red, the y-axis green and the z-axis is blue. |
| 104 | {{{ |
| 105 | #!xml |
| 106 | <!-- Large coordinate axis --> |
| 107 | <Model position="0,0,0" mesh="Coordinates.mesh" scale="20"/> |
| 108 | }}} |
| 109 | Start the level and press the F1 button on the keyboard to display the position of the spaceship. Verify that the x component of the position increases if you fly along the x-axis (red). |
| 110 | Let's add a few models to the scene: |
| 111 | {{{ |
| 112 | #!xml |
| 113 | <!-- Large coordinate axis --> |
| 114 | <Model position="0,0,0" mesh="Coordinates.mesh" scale="20"/> |
| 115 | |
| 116 | <!-- Example position and scale --> |
| 117 | <Model position="200,0,0" mesh="cube.mesh" scale="10"/> |
| 118 | <Model position="0,200,0" mesh="sphere.mesh" scale="3"/> |
| 119 | <Model position="0,0,200" mesh="cylinder.mesh" scale3D="3,3,10"/> |
| 120 | <Model position="0,100,100" mesh="rocket.mesh" scale="3"/> |
| 121 | <Model position="100,100,0" mesh="Coordinates.mesh" scale="3"/> |
| 122 | }}} |
| 123 | Fly to the models and verify their position. |
| 124 | Worldentities and therefore models (because the Model class inherits from the WorldEntity class) don't only have a position and a scale attribute. They also have an orientation. The orientation in three dimensional space is described by four numbers: |
| 125 | {{{ |
| 126 | #!xml |
| 127 | <!-- Large coordinate axis --> |
| 128 | <Model position="0,0,0" mesh="Coordinates.mesh" scale="20"/> |
| 129 | |
| 130 | <!-- Example orientation --> |
| 131 | <Model position="100,100,0" orientation="1.0,2.0,3.0,4.0" mesh="Coordinates.mesh" scale="3"/> |
| 132 | }}} |
| 133 | These four numbers are called a "Quaternion". Because it is not obvious how these four numbers affect the orientation of an object we created the "direction" attribute for the WorldEntity class which is much simpler to use in level design. |
| 134 | {{{ |
| 135 | #!xml |
| 136 | <!-- Large coordinate axis --> |
| 137 | <Model position="0,0,0" mesh="Coordinates.mesh" scale="20"/> |
| 138 | |
| 139 | <!-- Example direction --> |
| 140 | <!-- the -z axis of this model points in x-direction --> |
| 141 | <Model position="100,100,0" mesh="Coordinates.mesh" scale="3" direction="1,0,0"/> |
| 142 | <!-- the -z axis of this model points in the direction of the bisecting line of the angle between the x- and y-axis --> |
| 143 | <Model position="100,100,100" mesh="Coordinates.mesh" scale="3" direction="1,1,0"/> |
| 144 | }}} |
| 145 | The direction attribute specifies in what direction the -z axis of the WorldEntity points. The -z axis of the model at position (100,100,0) points in the x-direction which is parallel to the large red axis. |
| 146 | Another way to discribe the orientation of a WorldEntity is the "lookat" attribute: |
| 147 | {{{ |
| 148 | #!xml |
| 149 | <!-- Large coordinate axis --> |
| 150 | <Model position="0,0,0" mesh="Coordinates.mesh" scale="20"/> |
| 151 | |
| 152 | <!-- Example lookat --> |
| 153 | <!-- the -z axis of all theese models point towards the cube --> |
| 154 | <Model position="50,50,50" mesh="cube.mesh" scale="3"/> |
| 155 | <Model position="100,100,0" mesh="Coordinates.mesh" scale="3" lookat="50,50,50"/> |
| 156 | <Model position="100,0,100" mesh="Coordinates.mesh" scale="3" lookat="50,50,50"/> |
| 157 | <Model position="0,100,100" mesh="Coordinates.mesh" scale="3" lookat="50,50,50"/> |
| 158 | <Model position="100,100,100" mesh="Coordinates.mesh" scale="3" lookat="50,50,50"/> |
| 159 | }}} |
| 160 | All four small "Coordinates.mesh" models look with their -z axis to the yellow cube located at (50,50,50). |
| 161 | Because the attributes orientation, direction and lookat all represent the same information always at most one of them should be specified. Don't do this: |
| 162 | {{{ |
| 163 | #!xml |
| 164 | <!-- Too much information --> |
| 165 | <Model position="100,100,0" orientation="1.0,2.0,3.0,4.0" direction="0,100,0" lookat="0,100,100" mesh="Coordinates.mesh" scale="3"/> |
| 166 | }}} |
| 167 | There won't be any error message but the worldentity may not behave as expected. |