Changeset 66
- Timestamp:
- 05/18/08 14:24:40 (4 months ago)
- Files:
-
- trunk/bin/yage3d.exe (modified) (previous)
- trunk/src/demo1/gameobj.d (modified) (2 diffs)
- trunk/src/demo1/ship.d (modified) (1 diff)
- trunk/src/demo2/gameobj.d (modified) (2 diffs)
- trunk/src/yage/node/base.d (modified) (5 diffs)
- trunk/src/yage/node/light.d (modified) (1 diff)
- trunk/src/yage/node/node.d (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/demo1/gameobj.d
r65 r66 31 31 class Asteroid : GameObject 32 32 { 33 ModelNode rock; 34 33 35 float radius; // cached 34 36 35 37 this (BaseNode parent) 36 38 { super(parent); 37 ModelNoderock = new ModelNode(this);39 rock = new ModelNode(this); 38 40 rock.setModel(Resource.model("space/asteroid1.ms3d")); 39 41 } … … 45 47 void setMass(float mass) 46 48 { this.mass = mass; 47 children[0].setScale(Vec3f(pow(mass, .33333)/2));49 rock.setScale(Vec3f(pow(mass, .33333)/2)); 48 50 radius = pow(mass, .3333)*.75*4; 49 51 } trunk/src/demo1/ship.d
r65 r66 72 72 { 73 73 accelerate(Vec3f(0, 0, -speed).rotate(pitch.getTransform()).rotate(getTransform())); 74 Vec3f vel = Vec3f(0, 0, -.8).rotate(pitch.getAbsoluteRotation()).scale(getVelocity().length());75 74 76 75 // Engine smoke 77 76 SpriteNode puff = new SpriteNode(ship.getScene()); 78 77 puff.setMaterial(Resource.material("fx/smoke.xml")); 79 puff.setLifetime( 1);78 puff.setLifetime(5); 80 79 puff.setScale(Vec3f(.4)); 81 //puff.setVelocity( vel);80 //puff.setVelocity(getVelocity() - Vec3f(0, 0, -10).rotate(ship.getAbsoluteTransform())); 82 81 puff.setPosition(ship.getAbsolutePosition()+Vec3f(.8, 0, 2.5).rotate(ship.getAbsoluteTransform())); 82 83 void fade(BaseNode self) 84 { SpriteNode node = cast(SpriteNode)self; 85 node.setColor(1, 1, 1, node.getLifetime()/5); 86 float scale = std.math.sqrt(5.0f)-std.math.sqrt(node.getLifetime()) + .4; 87 node.setScale(scale); 88 node.setVelocity(node.getVelocity().scale(max(1-delta*ldamp*2, 0.0f))); 89 } 90 puff.onUpdate(&fade); 83 91 84 92 puff = new SpriteNode(ship.getScene(), puff); 85 93 puff.setPosition(ship.getAbsolutePosition()+Vec3f(-.8, 0, 2.5).rotate(ship.getAbsoluteTransform())); 86 94 95 96 97 87 98 sound.play(); 88 99 } trunk/src/demo2/gameobj.d
r65 r66 31 31 class Asteroid : GameObject 32 32 { 33 ModelNode rock; 34 33 35 float radius; // cached 34 36 35 37 this (BaseNode parent) 36 38 { super(parent); 37 ModelNoderock = new ModelNode(this);39 rock = new ModelNode(this); 38 40 rock.setModel(Resource.model("space/asteroid1.ms3d")); 39 41 } … … 45 47 void setMass(float mass) 46 48 { this.mass = mass; 47 children[0].setScale(Vec3f(pow(mass, .33333)/2));49 rock.setScale(Vec3f(pow(mass, .33333)/2)); 48 50 radius = pow(mass, .3333)*.75*4; 49 51 } trunk/src/yage/node/base.d
r64 r66 25 25 Scene scene; // The Scene that this node belongs to. 26 26 BaseNode parent; 27 Node[] children; 28 int index = -1; // index of this node in parent array 27 Node[Node] children; 29 28 30 29 protected void delegate(BaseNode self) on_update = null; // called on update … … 49 48 50 49 /// Get an array of this Node's children 51 Node[ ] getChildren()50 Node[Node] getChildren() 52 51 { return children; 53 }54 55 /**56 * Get the index of this Node in its parent's array.57 * Returns -1 if this node is a Scene.*/58 int getIndex()59 { return index;60 52 } 61 53 … … 137 129 */ 138 130 void update(float delta) 139 { debug scope(failure) writef("Backtrace xx ",__FILE__,"(",__LINE__,")\n"); 140 141 // Cache the current relative and absolute position/rotation for rendering. 131 { // Cache the current relative and absolute position/rotation for rendering. 142 132 // This prevents rendering a halfway-updated scenegraph. 143 133 cache[scene.transform_write].transform = transform; … … 148 138 on_update(this); 149 139 150 // Iterate in reverse to ensure we hit all of them, since the last item 151 // is moved over the current item when removing from an array. 152 foreach_reverse(Node c; children) 140 foreach(Node c; children) 153 141 c.update(delta); 154 142 } … … 174 162 // could this function be called by two different threads on the same Node? 175 163 // and then the path gets messed up? 176 debug scope(failure) writef("Backtrace xx ",__FILE__,"(",__LINE__,")\n");177 178 164 BaseNode path[16384] = void; // surely no one will have a scene graph deeper than this! 179 165 BaseNode node = this; trunk/src/yage/node/light.d
r59 r66 75 75 super.setParent(parent); 76 76 if (old !is scene) 77 { if ((old !is null) && (index != -1))77 { if ((old !is null)) 78 78 old.removeLight(light_index); 79 79 scene.addLight(this); trunk/src/yage/node/node.d
r65 r66 70 70 /// Construct this Node as a child of parent. 71 71 this(BaseNode parent) 72 { debug scope(failure) writef("Backtrace xx ",__FILE__,"(",__LINE__,")\n"); 73 visible = false; 72 { visible = false; 74 73 scale = Vec3f(1); 75 74 color = Color("white"); … … 83 82 * original = This Node will be an exact copy of original.*/ 84 83 this(BaseNode parent, Node original) 85 { 86 debug scope(failure) writef("Backtrace xx ",__FILE__,"(",__LINE__,")\n"); 87 this(parent); 84 { this(parent); 88 85 89 86 visible = original.visible; … … 91 88 color = original.color; 92 89 lifetime = original.lifetime; 90 on_update = original.on_update; 93 91 94 92 // From BaseNode … … 178 176 /// Remove this Node. This function should be used instead of delete. 179 177 void remove() 180 { debug scope(failure) writef("Backtrace xx ",__FILE__,"(",__LINE__,")\n"); 181 182 if (index != -1) 183 { yage.core.all.remove(parent.children, index, false); 184 if (index < parent.children.length) 185 parent.children[index].index = index; 186 index = -1; // so remove can't be called twice. 187 } 178 { if (parent && this in parent.children) 179 parent.children.remove(this); 180 188 181 // this needs to happen because some children (like lights) may need to do more in their remove() function. 189 182 foreach(Node c; children) … … 198 191 in { assert(_parent !is null); 199 192 }body 200 { debug scope(failure) writef("Backtrace xx ",__FILE__,"(",__LINE__,")\n"); 201 202 if (index!=-1) 203 { yage.core.array.remove(children, index, false); 204 if (index < parent.children.length) // if not removed from the end. 205 parent.children[index].index = index; // update external index. 206 }// Add to new parent 193 { if (parent && this in parent.children) 194 parent.children.remove(this); 195 196 // Add to new parent 207 197 parent = _parent; 208 parent.children ~= this; 209 index = parent.children.length-1; 198 parent.children[this] = this; 210 199 scene = parent.scene; 211 200 setTransformDirty(); … … 219 208 * It normally doesn't need to be called manually.*/ 220 209 void update(float delta) 221 { debug scope( failure ) writef("Backtrace xx ",__FILE__,"(",__LINE__,")\n"); 222 223 lifetime-= delta; 210 { lifetime-= delta; 224 211 225 212 // Move by linear velocity if not zero. … … 248 235 * Also perhaps use axis sorting for faster calculations. */ 249 236 void enableLights(ubyte number=8) 250 { debug scope(failure) writef("Backtrace xx ",__FILE__,"(",__LINE__,")\n"); 251 237 { 252 238 if (number>Device.getLimit(DEVICE_MAX_LIGHTS)) 253 239 number = Device.getLimit(DEVICE_MAX_LIGHTS);
