Changeset 67
- Timestamp:
- 05/24/08 22:19:12 (3 months ago)
- Files:
-
- trunk/bin/yage3d.exe (modified) (previous)
- trunk/src/demo1/gameobj.d (modified) (1 diff)
- trunk/src/demo1/main.d (modified) (5 diffs)
- trunk/src/demo1/ship.d (modified) (3 diffs)
- trunk/src/demo2/main.d (modified) (1 diff)
- trunk/src/yage/core/all.d (modified) (1 diff)
- trunk/src/yage/core/color.d (added)
- trunk/src/yage/core/math.d (modified) (2 diffs)
- trunk/src/yage/core/types.d (modified) (1 diff)
- trunk/src/yage/core/vector.d (modified) (12 diffs)
- trunk/src/yage/gui/style.d (modified) (1 diff)
- trunk/src/yage/node/base.d (modified) (2 diffs)
- trunk/src/yage/node/light.d (modified) (1 diff)
- trunk/src/yage/node/moveable.d (modified) (11 diffs)
- trunk/src/yage/node/node.d (modified) (5 diffs)
- trunk/src/yage/node/scene.d (modified) (3 diffs)
- trunk/src/yage/resource/ms3dloader.d (modified) (2 diffs)
- trunk/src/yage/resource/objloader.d (modified) (1 diff)
- trunk/src/yage/util/flyer.d (modified) (3 diffs)
- trunk/src/yage/util/misc.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/demo1/gameobj.d
r66 r67 12 12 import std.stdio; 13 13 import yage.core.timer; 14 import yage.core. types;14 import yage.core.color; 15 15 import yage.core.vector; 16 16 import yage.resource.resource; trunk/src/demo1/main.d
r65 r67 21 21 // Current program entry point. This may change in the future. 22 22 int main() 23 { 24 23 { 25 24 // Init (resolution, depth, fullscreen, aa-samples) 26 25 Device.init(800, 600, 32, false, 1); … … 53 52 Ship ship = new Ship(scene); 54 53 ship.setPosition(Vec3f(0, 50, -950)); 55 ship.getCameraSpot().setPosition( 0, 1000, 3000);54 ship.getCameraSpot().setPosition(Vec3f(0, 1000, 3000)); 56 55 57 56 // Camera … … 85 84 if (Input.keydown[SDLK_ESCAPE]) 86 85 Device.exit(0); 86 87 if(key == SDLK_c){ 88 std.gc.fullCollect(); 89 writefln("garbage collected"); 90 } 87 91 } 88 92 … … 102 106 l1.setDiffuse(Color(1, .85, .7)); 103 107 l1.setLightRadius(7000); 104 l1.setPosition( 0, 0, -6000);108 l1.setPosition(Vec3f(0, 0, -6000)); 105 109 106 110 // Star … … 113 117 planet.setModel("space/planet.ms3d"); 114 118 planet.scale = Vec3f(60); 115 planet.setAngularVelocity( 0, -0.01, 0);119 planet.setAngularVelocity(Vec3f(0, -0.01, 0)); 116 120 117 121 //planet.getModel().clearAttribute("gl_Normal"); trunk/src/demo1/ship.d
r66 r67 59 59 60 60 void update(float delta) 61 { debug scope(failure) writef("Backtrace xx ",__FILE__,"(",__LINE__,")\n"); 62 63 super.update(delta); 61 { super.update(delta); 64 62 65 63 // Set the acceleration speed … … 83 81 void fade(BaseNode self) 84 82 { SpriteNode node = cast(SpriteNode)self; 85 node.setColor( 1, 1, 1, node.getLifetime()/5);83 node.setColor(Color(1, 1, 1, node.getLifetime()/5)); 86 84 float scale = std.math.sqrt(5.0f)-std.math.sqrt(node.getLifetime()) + .4; 87 85 node.setScale(scale); 88 node.setVelocity(node.getVelocity().scale(max(1-delta*ldamp*2, 0.0f)));89 86 } 90 87 puff.onUpdate(&fade); … … 92 89 puff = new SpriteNode(ship.getScene(), puff); 93 90 puff.setPosition(ship.getAbsolutePosition()+Vec3f(-.8, 0, 2.5).rotate(ship.getAbsoluteTransform())); 94 95 96 91 97 92 trunk/src/demo2/main.d
r65 r67 96 96 97 97 if(key == SDLK_c){ 98 std.gc.fullCollect(); //FIX!98 std.gc.fullCollect(); 99 99 writefln("garbage collected"); 100 100 } trunk/src/yage/core/all.d
r51 r67 15 15 public 16 16 { import yage.core.array; 17 import yage.core.color; 17 18 import yage.core.freelist; 18 19 import yage.core.math; trunk/src/yage/core/math.d
r51 r67 23 23 * compare equal. This allows 0.00001 and 0 to be almost equal. */ 24 24 bool almostEqual(float a, float b, float fudge=0.0001) 25 { if (fabs(a-b) <= fudge) 25 { 26 if (fabs(a-b) <= fudge) 26 27 return true; 27 28 … … 33 34 return true; 34 35 return false; 36 37 //return fdim(a, b) < fudge; 35 38 } 36 39 unittest trunk/src/yage/core/types.d
r59 r67 14 14 import yage.core.vector:Vec4f; 15 15 private extern (C) void *memcpy(void *, void *, uint); 16 17 18 19 /**20 * A struct used to represent a color.21 * Colors are represented in RGBA format.22 * Note that uints and dwords store the bytes in reverse,23 * so Color(0x6633ff00).hex == "00FF3366"24 * All Colors default to transparent black.25 * Example:26 * --------------------------------27 * uint red = Color("red").ui;28 * Vec4f blue = Color("0000FF").vec4f;29 * writefln(Color("blue")); // outputs "0000FF00"30 * writefln(Color(0x00FF0000)); // outputs "0000FF00"31 * --------------------------------32 */33 struct Color34 {35 private static real frac = 1.0f/255;36 37 union38 { ubyte[4] ub;/// Get the Color as an array of ubyte39 uint ui; /// Get the Color as a uint40 dword dw; /// Get the Color as a dword41 struct { ubyte r, g, b, a; } /// Access each color component.42 }43 44 /// Initialize45 static Color opCall(int r, int g,int b, int a=255)46 { Color res;47 res.r=r;48 res.b=b;49 res.g=g;50 res.a=a;51 return res;52 }53 /// Ditto54 static Color opCall(float r, float g, float b, float a=1)55 { Color res;56 res.r=cast(ubyte)clamp(r*255, 0.0f, 255.0f);57 res.b=cast(ubyte)clamp(b*255, 0.0f, 255.0f);58 res.g=cast(ubyte)clamp(g*255, 0.0f, 255.0f);59 res.a=cast(ubyte)clamp(a*255, 0.0f, 255.0f);60 return res;61 }62 63 64 /// Convert dword to Color65 static Color opCall(dword dw)66 { Color res;67 res.dw = dw;68 return res;69 }70 71 /// Convert uint to Color72 static Color opCall(uint ui)73 { return Color(dword(ui));74 }75 76 /// Convert ubyte[] to Color77 static Color opCall(ubyte[] v)78 { Color res;79 for (int i=0; i<max(v.length, 4); i++)80 res.ub[i] = cast(ubyte)(v[i]);81 return res;82 }83 84 /// Convert int[] to Color85 static Color opCall(int[] v)86 { Color res;87 for (int i=0; i<max(v.length, 4); i++)88 res.ub[i] = cast(ubyte)(v[i]);89 return res;90 }91 92 /// Convert float[] to Color93 static Color opCall(float[] f)94 { Color res;95 for (int i=0; i<min(f.length, 4); i++)96 res.ub[i] = cast(ubyte)clamp(f[i]*255, 0.0f, 255.0f);97 return res;98 }99 100 /// Convert Vec3f to Color101 static Color opCall(Vec3f v)102 { return Color(v.v);103 }104 105 /// Convert Vec4f to Color106 static Color opCall(Vec4f v)107 { return Color(v.v);108 }109 110 /**111 * Convert a string to a color.112 * The string can be a 6 or 8 digit hexadecimal or an English color name.113 * Black, blue, brown, cyan, gold, gray/grey, green, indigo, magenta, orange,114 * pink, purple, red, violet, white, and yellow are supported.115 * See: <a href="http://www.w3schools.com/css/css_colornames.asp">CSS color names</a>116 * Params:117 * string = The string to convert.*/118 static Color opCall(char[] string)119 {120 // An english color name121 switch (std.string.tolower(string))122 { case "black": return Color(0xFF000000);123 case "blue": return Color(0xFFFF0000);124 case "brown": return Color(0xFFA52A2A);125 case "cyan": return Color(0xFFFFFF00);126 case "gold": return Color(0xFF00D7FF);127 case "gray":128 case "grey": return Color(0xFF808080);129 case "green": return Color(0xFF008000);130 case "indigo": return Color(0xFF82004B);131 case "magenta": return Color(0xFFFF00FF);132 case "orange": return Color(0xFF00A5FF);133 case "pink": return Color(0xFFCBC0FF);134 case "purple": return Color(0xFF800080);135 case "red": return Color(0xFF0000FF);136 case "violet": return Color(0xFFEE82EE);137 case "white": return Color(0xFFFFFFFF);138 case "yellow": return Color(0xFF00FFFF);139 default: break;140 }141 142 // Append alpha to 6-digit hex string.143 if (string.length == 6)144 string ~= "FF";145 146 // Convert string one char at a a time.147 Color result;148 int digit;149 foreach (int i, char h; string)150 { if (i>=8)151 break;152 153 digit=0; // will be 0-15154 if (47 < h && h < 58) // 0-9155 digit = (h-48);156 else if (64 < h && h < 71) // A-F157 digit = (h-55);158 else if (96 < h && h < 103) // a-f159 digit = (h-87);160 else161 throw new Exception("Invalid character '" ~ h ~"' for Color()");162 result.ub[i/2] += digit * (15*((i+1)%2)+1); // gets low or high nibble163 }164 return result;165 }166 167 168 /// Get the Color as an array of float.169 float[] f()170 { float[4] res;171 res[0] = r * frac;172 res[1] = g * frac;173 res[2] = b * frac;174 res[3] = a * frac;175 return res.dup;176 }177 178 /// Get the Color as a Vec3f.179 Vec3f vec3f()180 { Vec3f res;181 res.v[0] = r * frac;182 res.v[1] = g * frac;183 res.v[2] = b * frac;184 return res;185 }186 187 /// Get the Color as a Vec4f.188 Vec4f vec4f()189 { Vec4f res;190 res.v[0] = r * frac;191 res.v[1] = g * frac;192 res.v[2] = b * frac;193 res.v[3] = a * frac;194 return res;195 }196 197 /**198 * Get the color as a string.199 * Params:200 * lower = return lower case hexadecimal digits*/201 char[] hex(bool lower=false)202 { if (lower)203 return formatString("%.8x", bswap(ui));204 return formatString("%.8X", bswap(ui));205 }206 /// ditto207 char[] toString()208 { return hex();209 }210 211 unittest212 { assert(Color.sizeof == 4);213 214 // Test initializers215 assert(Color([0, 102, 51, 255]).hex == "006633FF");216 assert(Color([0.0f, 0.4f, 0.2f, 1.0f]).hex == "006633FF");217 assert(Color(0xFF336600).hex == "006633FF");218 219 // Test converters220 assert(Color("abcdef97").hex == "ABCDEF97");221 assert(Color("006633FF").vec4f == Vec4f(0.0f, 0.4f, 0.2f, 1.0f));222 assert(Color("006633FF").ui == 0xFF336600);223 }224 }225 226 16 227 17 trunk/src/yage/core/vector.d
r59 r67 13 13 import yage.core.math; 14 14 import yage.core.quatrn; 15 15 16 /** 16 17 * This is a template to create a vector of any type with any number of elements. … … 19 20 * Example: 20 21 * -------------------------------- 21 * Vec!( real, 4) a; // a is a four-component real vector.22 * Vec!(4, real) a; // a is a four-component real vector. 22 23 * --------------------------------*/ 23 struct Vec( T, int K)24 struct Vec(int S, T) 24 25 { 25 alias Vec!( T, K) VTK;26 alias Vec!(S, T) VST; 26 27 27 28 union 28 { T v[ K] = 0; // same as x, y, z, etc.29 static if( K==2)29 { T v[S] = 0; // same as x, y, z, etc. 30 static if(S==2) 30 31 { struct { T x, y; } 31 32 } 32 static if( K==3)33 static if(S==3) 33 34 { struct { T x, y, z; } 34 35 struct { T r, g, b; } 35 36 } 36 static if( K==4)37 static if(S==4) 37 38 { struct { T r, g, b, a; } 38 39 struct { T x, y, z, w; } … … 46 47 47 48 /// Create a zero vector 48 static V TKopCall()49 { V TKres;49 static VST opCall() 50 { VST res; 50 51 return res; 51 52 } 52 53 53 54 /// Create a vector with all values as s. 54 static V TKopCall(T s)55 { V TKres;55 static VST opCall(T s) 56 { VST res; 56 57 foreach(inout T e; res.v) 57 58 e = s; … … 60 61 61 62 /// Create a new vector with the values s0, s1, s2, ... 62 static V TK opCall(T[K] s ...)63 { V TKres;64 res.v[0.. K] = s[0..K];65 return res; 66 } 67 68 /// Create a new vector with the values of s; s must be at least of length K.69 static V TKopCall(T[] s)70 { assert(s.length>= K);71 V TKres;72 res.v[0.. K] = s[0..K];63 static VST opCall(T[S] s ...) 64 { VST res; 65 res.v[0..S] = s[0..S]; 66 return res; 67 } 68 69 /// Create a new vector with the values of s; s must be at least of length S. 70 static VST opCall(T[] s) 71 { assert(s.length>=S); 72 VST res; 73 res.v[0..S] = s[0..S]; 73 74 return res; 74 75 } 75 76 76 77 /// 77 V TK add(VTKs)78 { V TKres;78 VST add(VST s) 79 { VST res; 79 80 for (int i=0; i<v.length; i++) 80 81 res.v[i] = v[i]+s.v[i]; … … 83 84 84 85 /// The _angle between this vector and s, in radians. 85 float angle(V TKs)86 float angle(VST s) 86 87 { return acos(dot(s)/(length()*s.length())); 87 88 } 88 89 89 /// 90 V TKclamp(T min, T max)91 { V TKres;92 for (int i=0; i< K; i++)90 /// Clamp all values between min and max. 91 VST clamp(T min, T max) 92 { VST res; 93 for (int i=0; i<S; i++) 93 94 { if (res.v[i]<min) res.v[i] = min; 94 95 else if (res.v[i]>max) res.v[i] = max; … … 100 101 101 102 /// Return the _dot product of this vector and s. 102 float dot(V TKs)103 float dot(VST s) 103 104 { float res=0; 104 105 for (int i=0; i<v.length; i++) … … 131 132 132 133 /// Create a new vector with the values of s; s must be at least of length 3. 133 V TK projection(VTKs)134 VST projection(VST s) 134 135 { return s.scale(dot(s)/s.length2()); 135 136 } 136 137 138 /// 137 139 T* ptr() 138 140 { return v.ptr; … … 140 142 141 143 /// Scale (multiply) this vector. 142 V TKscale(float s)143 { V TKres = *this;144 VST scale(float s) 145 { VST res = *this; 144 146 for (int i=0; i<v.length; i++) 145 147 res.v[i] *= s; … … 147 149 } 148 150 /// ditto 149 V TK scale(VTKs)150 { V TKres = *this;151 VST scale(VST s) 152 { VST res = *this; 151 153 for (int i=0; i<v.length; i++) 152 154 res.v[i] *= s.v[i]; … … 160 162 } 161 163 /// ditto 162 void set(V TKs)163 { v[0.. K] = s.v[0..K];164 void set(VST s) 165 { v[0..S] = s.v[0..S]; 164 166 } 165 167 166 168 /// ditto 167 void set(T[ K] s ...)168 { v[0.. K] = s[0..K];169 void set(T[S] s ...) 170 { v[0..S] = s[0..S]; 169 171 } 170 172 … … 172 174 char[] toString() 173 175 { char[] result = "<"; 174 for (int i=0; i< K; i++)176 for (int i=0; i<S; i++) 175 177 result ~= formatString("%.4f ", v[i]); 176 178 result ~= ">"; … … 179 181 } 180 182 181 alias Vec!( int, 2) Vec2i; /// A two-component int Vec182 alias Vec!( int, 3) Vec3i; /// A three-component int Vec183 alias Vec!( int, 4) Vec4i; /// A four-component int Vec184 alias Vec!( float, 2) Vec2f; /// A two-component float Vec183 alias Vec!(2, int) Vec2i; /// A two-component int Vec 184 alias Vec!(3, int) Vec3i; /// A three-component int Vec 185 alias Vec!(4, int) Vec4i; /// A four-component int Vec 186 alias Vec!(2, float) Vec2f; /// A two-component float Vec 185 187 //alias Vec3f Vec3f; // Defined below 186 alias Vec!( float, 4) Vec4f; /// A four-component float Vec188 alias Vec!(4, float) Vec4f; /// A four-component float Vec 187 189 188 190 /** trunk/src/yage/gui/style.d
r55 r67 4 4 module yage.gui.style; 5 5 6 import yage.core. types;6 import yage.core.color; 7 7 import yage.core.vector; 8 8 import yage.resource.material; trunk/src/yage/node/base.d
r66 r67 100 100 char[] toString() { return toString(false); } 101 101 char[] toString(bool recurse) /// Ditto 102 { static int indent; 102 { 103 104 static int indent; 103 105 char[] pad = new char[indent*3]; 104 106 pad[0..length] = ' '; … … 129 131 */ 130 132 void update(float delta) 131 { // Cache the current relative and absolute position/rotation for rendering. 133 { 134 // Cache the current relative and absolute position/rotation for rendering. 132 135 // This prevents rendering a halfway-updated scenegraph. 133 136 cache[scene.transform_write].transform = transform; trunk/src/yage/node/light.d
r66 r67 84 84 /// Overridden to remove the light from the Scene's arary of lights 85 85 void remove() 86 { debug scope( failure ) writef("Backtrace xx ",__FILE__,"(",__LINE__,")\n");86 { 87 87 scene.removeLight(light_index); 88 88 super.remove(); trunk/src/yage/node/moveable.d
r32 r67 32 32 protected bool velocity_dirty=true; // The absolute velocity vectors need to be recalculated. 33 33 34 // Suppose rendering and scene-graph updating are in different threads34 // Rendering and scene-graph updates run in different threads. 35 35 // If the scene is rendered halfway through updating, rendering glitches may occur. 36 36 // Therefore, the scene-graph implements a sort of "triple buffering". … … 44 44 protected Cache cache[3]; 45 45 46 // Incomplete 47 void lookAt(Vec3f target, Vec3f up) 48 { Vec3f f = target.normalize(); 49 up = up.normalize(); 50 51 Vec3f s = f.cross(up).normalize(); 52 Vec3f u = s.cross(f); 53 54 setRotation(0, 0, 0); 55 rotate(u); 46 /** 47 * Move and rotate by the transformation Matrix. 48 * In other words, apply t as a transformation Matrix. */ 49 void transformation(Matrix t) 50 { transform.postMultiply(t); 51 setTransformDirty(); 56 52 } 57 53 … … 67 63 return &transform_abs; 68 64 } 69 65 70 66 /** 71 67 * Return the relative transformation Matrix of this Node. This Matrix stores the position … … 79 75 return transform; 80 76 } 77 void setTransform(Matrix transform) /// Ditto 78 { this.transform = transform; 79 setTransformDirty(); 80 } 81 81 82 /** 82 83 * Get the absolute transformation Matrix of this Node, calculating it if necessary. … … 85 86 * instead of the current version. This can be used to avoid working with a half-updated scenegraph.*/ 86 87 Matrix getAbsoluteTransform(bool cached = false) 87 { debug scope(failure) writef("Backtrace xx ",__FILE__,"(",__LINE__,")\n"); 88 89 if (cached) // the transform_abs cache is never dirty 88 { if (cached) // the transform_abs cache is never dirty 90 89 return cache[scene.transform_read].transform_abs; 91 90 if (transform_dirty) … … 93 92 return transform_abs; 94 93 } 95 96 /** 97 * Get the position of this Node relative to its parent's location.94 95 /** 96 * Get / set the position of this Node relative to its parent's location. 98 97 * Note that changing the values of the return vector will not affect the Node's position. */ 99 98 Vec3f getPosition() 100 99 { return Vec3f(transform.v[12..15]); 101 100 } 101 void setPosition(Vec3f position) 102 { transform.v[12..15] = position.v[0..3]; 103 } 104 102 105 /** 103 106 * Get the absolute position of this Node, calculating it if necessary. … … 106 109 { return Vec3f(getAbsoluteTransform().v[12..15]); 107 110 } 108 109 111 110 112 /** 111 113 * Get the rotation of this Node relative to its parent's rotation. … … 114 116 { return transform.toAxis(); 115 117 } 118 void setRotation(Vec3f axis) /// Ditto 119 { transform.set(axis); 120 setTransformDirty(); 121 } 122 116 123 /** 117 124 * Get the absolute rotation of this Node, calculating it if necessary. … … 121 128 } 122 129 123 124 /// Set this Node's relative transformation Matrix. 125 void setTransform(Matrix transform) 126 { this.transform = transform; 127 setTransformDirty(); 128 } 129 130 131 /// Set the position of this node relative to its parent's position and rotation. 132 void setPosition(float x, float y, float z) 133 { transform.v[12]=x; 134 transform.v[13]=y; 135 transform.v[14]=z; 136 setTransformDirty(); 137 } 138 /// Ditto 139 void setPosition(Vec3f position) 140 { setPosition(position.x, position.y, position.z); 141 } 142 143 144 /// Set the rotation of this Node relative to its parent's rotation, using an axis angle. 145 void setRotation(float x, float y, float z) 146 { setRotation(Vec3f(x, y, z)); 147 } 148 /// Ditto 149 void setRotation(Vec3f axis) 150 { transform.set(axis); 151 setTransformDirty(); 152 } 153 154 155 /** 156 * Move and rotate by the transformation Matrix. 157 * In other words, apply t as a transformation Matrix. */ 158 void transformation(Matrix t) 159 { transform.postMultiply(t); 160 setTransformDirty(); 161 } 162 163 /// Move this Node relative to its parent. 164 void move(float x, float y, float z) 165 { move(Vec3f(x, y, z)); 166 } 167 /// Ditto 168 void move(Vec3f distance) 169 { transform.v[12]+=distance.x; 170 transform.v[13]+=distance.y; 171 transform.v[14]+=distance.z; 172 setTransformDirty(); 173 } 174 175 /// Move this Node relative to the direction it's pointing (relative to its rotation). 176 void moveRelative(float x, float y, float z) 177 { moveRelative(Vec3f(x, y, z)); 178 } 179 /// Ditto 180 void moveRelative(Vec3f direction) 181 { transform = transform.moveRelative(direction); 182 setTransformDirty(); 183 } 184 185 186 /// Rotate this Node relative to its current rotation axis, using an axis angle 187 void rotate(float x, float y, float z) 188 { rotate(Vec3f(x, y, z)); 189 } 190 /// Ditto 191 void rotate(Vec3f axis) 192 { transform = transform.rotate(axis); 193 setTransformDirty(); 194 } 195 196 197 /// Rotate this Node around the absolute worldspace axis, using an axis angle. 198 void rotateAbsolute(float x, float y, float z) 199 { rotateAbsolute(Vec3f(x, y, z)); 200 } 201 /// Ditto 202 void rotateAbsolute(Vec3f axis) 203 { transform = transform.rotateAbsolute(axis); 204 setTransformDirty(); 205 } 206 207 208 /// Get the velocity of this Node relative to its parent. 209 Vec3f getVelocity() 130 /// Get / set the velocity of this Node relative to its parent's linear and angular velocity. 131 void setVelocity(Vec3f velocity) 132 { linear_velocity = velocity; 133 } 134 Vec3f getVelocity() /// Ditto 210 135 { return linear_velocity; 211 136 } … … 218 143 } 219 144 220 /// Set the velocity of this Node relative to its parent's linear and angular velocity. 221 void setVelocity(float x, float y, float z) 222 { linear_velocity.set(x, y, z); 223 } 224 /// Ditto 225 void setVelocity(Vec3f velocity) 226 { linear_velocity = velocity; 227 } 228 229 /** 230 * Return the angular velocity axis; the Node rotates around this axis and 231 * the length of this is the rotations per second in radians. */ 232 Vec3f getAngularVelocity() 145 /** 146 * Get/set this Node's angular velocity relative to it's parent's rotation and angular velocity. 147 * This is represented in an axis-angle vector where the direction is the axis of rotation and the 148 * length is the rotation in radians. */ 149 Vec3f getAngularVelocity() 233 150 { return angular_velocity; 234 } 235 236 /// Set the angular velocity axis relative to this Node's current rotation. 237 void setAngularVelocity(float x, float y, float z) 238 { angular_velocity.set(x, y, z); 239 } 240 /// Ditto 241 void setAngularVelocity(Vec3f axis) 242 { angular_velocity = axis; 151 } 152 void setAngularVelocity(Vec3f axis) /// Ditto 153 { angular_velocity = axis; 154 } 155 156 157 158 // Incomplete 159 // Might also consider a function to return a rotation vector needed to rotate to look at target. 160 void lookAt(Vec3f target, Vec3f up) 161 { Vec3f f = target.normalize(); 162 up = up.normalize(); 163 164 Vec3f s = f.cross(up).normalize(); 165 Vec3f u = s.cross(f); 166 167 setRotation(Vec3f(0, 0, 0)); 168 rotate(u); 169 } 170 171 /// Move this Node relative to its parent. 172 void move(Vec3f distance) 173 { transform.v[12]+=distance.x; 174 transform.v[13]+=distance.y; 175 transform.v[14]+=distance.z; 176 setTransformDirty(); 177 } 178 179 /// Move this Node relative to the direction it's pointing (relative to its rotation). 180 void moveRelative(Vec3f direction) 181 { transform = transform.moveRelative(direction); 182 setTransformDirty(); 183 } 184 185 /// Rotate this Node relative to its current rotation axis, using an axis angle 186 void rotate(Vec3f axis) 187 { transform = transform.rotate(axis); 188 setTransformDirty(); 189 } 190 191 /// Rotate this Node around the absolute worldspace axis, using an axis angle. 192 void rotateAbsolute(Vec3f axis) 193 { transform = transform.rotateAbsolute(axis); 194 setTransformDirty(); 243 195 } 244 196 245 197 /// Accelerate the Node in the direction specified 246 void accelerate(float x, float y, float z)247 { accelerate(Vec3f(x, y, z));248 }249 /// Ditto250 198 void accelerate(Vec3f v) 251 { linear_velocity += v; 199 { linear_velocity += v; 252 200 } 253 201 254 202 /// Accelerate relative to the way this Node is rotated (pointed). 255 void accelerateRelative(float x, float y, float z)256 { accelerateRelative(Vec3f(x, y, z));257 }258 /// Ditto259 203 void accelerateRelative(Vec3f v) 260 { linear_velocity += v.rotate(transform); 204 { linear_velocity += v.rotate(transform); 261 205 } 262 206 263 207 /// Accelerate the angular velocity of the Node by this axis. 264 void angularAccelerate(float x, float y, float z)265 { angularAccelerate(Vec3f(x, y, z));266 }267 /// Ditto268 208 void angularAccelerate(Vec3f axis) 269 { angular_velocity += axis; 209 { angular_velocity += axis; 270 210 } 271 211 … … 273 213 * Accelerate the rotation of this Node, interpreting the acceleration axis 274 214 * in terms of absolute worldspace coordinates. */ 275 void angularAccelerateAbsolute(float x, float y, float z)276 { angularAccelerateAbsolute(Vec3f(x, y, z));277 }278 /// Ditto279 215 void angularAccelerateAbsolute(Vec3f axis) 280 { angular_velocity += axis.rotate(getAbsoluteTransform().inverse()); 281 } 282 283 284 285 286 216 { angular_velocity += axis.rotate(getAbsoluteTransform().inverse()); 217 } 287 218 } trunk/src/yage/node/node.d
r66 r67 131 131 * This provides an easy way to change the color of a Node without having to modify all materials individually. 132 132 * Default color is white and opaque (all 1's).*/ 133 Color getColor() { return color; } 134 void setColor(Color color) { this.color = color; } /// Ditto 135 void setColor(float r, float g, float b, float a=1) { color = Color(r, g, b, a); } /// Ditto 133 Color getColor() 134 { return color; 135 } 136 void setColor(Color color) /// Ditto 137 { this.color = color; 138 } 136 139 137 140 /** … … 139 142 * The default value is float.infinity, but a lower number will cause the Node to be removed 140 143 * from the scene graph after that amount of time, as its lifetime is decreased with every Scene update.*/ 141 float getLifetime() { return lifetime; } 142 void setLifetime(float seconds) { lifetime = seconds; } /// Ditto 143 144 float getLifetime() 145 { return lifetime; 146 } 147 void setLifetime(float seconds) /// Ditto 148 { lifetime = seconds; 149 } 150 151 144 152 /// Get an array of lights that were enabled in the last call to enableLights(). 145 LightNode[] getLights()153 LightNode[] getLights() 146 154 { return lights; 147 155 } … … 162 170 * Get / set the scale of this Node in the x, y, and z directions. 163 171 * The default is (1, 1, 1). Unlike position and rotation, scale is not inherited. */ 164 void setScale(float x, float y, float z) { scale.set(x, y, z); } 165 void setScale(Vec3f scale) { setScale(scale.x, scale.y, scale.z); } /// ditto 166 void setScale(float scale){ setScale(scale, scale, scale); } /// ditto 167 Vec3f getScale() { return scale; } /// ditto 172 void setScale(float x, float y, float z) 173 { scale.set(x, y, z); 174 } 175 void setScale(Vec3f scale) /// ditto 176 { setScale(scale.x, scale.y, scale.z); 177 } 178 void setScale(float scale) /// ditto 179 { setScale(scale, scale, scale); 180 } 181 Vec3f getScale() /// ditto 182 { return scale; 183 } 168 184 169 185 /** 170 186 * Gt /set whether this Node will be rendered. This has nothing to do with frustum culling. 171 187 * Setting a Node as invisible will not make its children invisible also. */ 172 void setVisible(bool visible) { this.visible = visible; } 173 bool getVisible() { return visible; } /// ditto 188 void setVisible(bool visible) 189 { this.visible = visible; 190 } 191 bool getVisible() /// ditto 192 { return visible; 193 } 174 194 175 195 176 196 /// Remove this Node. This function should be used instead of delete. 177 197 void remove() 178 { if (parent && this in parent.children) 179 parent.children.remove(this); 180 198 { 181 199 // this needs to happen because some children (like lights) may need to do more in their remove() function. 182 200 foreach(Node c; children) 183 201 c.remove(); 202 203 if (parent && this in parent.children) 204 parent.children.remove(this); 184 205 } 185 206 … … 191 212 in { assert(_parent !is null); 192 213 }body 193 { if (parent && this in parent.children) 214 { 215 if (parent && this in parent.children) 194 216 parent.children.remove(this); 195 217 … … 208 230 * It normally doesn't need to be called manually.*/ 209 231 void update(float delta) 210 { lifetime-= delta; 232 { 233 lifetime-= delta; 211 234 212 235 // Move by linear velocity if not zero. trunk/src/yage/node/scene.d
r57 r67 49 49 protected bool fog_enabled = false; 50 50 protected float speed_of_sound = 343; // 343m/s is the speed of sound in air at sea level.
