Changeset 71
- Timestamp:
- 05/28/08 23:08:25 (5 months ago)
- Files:
-
- trunk/bin/sdl.txt (added)
- trunk/bin/yage3d.exe (modified) (previous)
- trunk/doc/api/yage.node.movable.html (added)
- trunk/doc/api/yage.node.visible.html (added)
- trunk/src/demo1/gameobj.d (modified) (2 diffs)
- trunk/src/demo1/main.d (modified) (1 diff)
- trunk/src/demo1/ship.d (modified) (3 diffs)
- trunk/src/demo2/gameobj.d (modified) (2 diffs)
- trunk/src/demo2/main.d (modified) (1 diff)
- trunk/src/demo2/ship.d (modified) (1 diff)
- trunk/src/yage/core/all.d (modified) (1 diff)
- trunk/src/yage/core/tree.d (added)
- trunk/src/yage/core/xml.d (modified) (1 diff)
- trunk/src/yage/gui/surface.d (modified) (10 diffs)
- trunk/src/yage/node/graph.d (modified) (2 diffs)
- trunk/src/yage/node/model.d (modified) (2 diffs)
- trunk/src/yage/node/node.d (modified) (6 diffs)
- trunk/src/yage/node/sprite.d (modified) (1 diff)
- trunk/src/yage/node/terrain.d (modified) (3 diffs)
- trunk/src/yage/node/visible.d (modified) (5 diffs)
- trunk/src/yage/system/device.d (modified) (2 diffs)
- trunk/src/yage/system/render.d (modified) (4 diffs)
- trunk/src/yage/util/misc.d (modified) (3 diffs)
- trunk/src/yage/util/spring.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/demo1/gameobj.d
r70 r71 47 47 void setMass(float mass) 48 48 { this.mass = mass; 49 rock.setS cale(Vec3f(pow(mass, .33333)/2));49 rock.setSize(Vec3f(pow(mass, .33333)/2)); 50 50 radius = pow(mass, .3333)*.75*4; 51 51 } … … 63 63 SpriteNode flare = new SpriteNode(this); 64 64 flare.setMaterial("fx/flare1.xml"); 65 flare.setS cale(Vec3f(2));65 flare.setSize(Vec3f(2)); 66 66 67 67 if (timer is null) trunk/src/demo1/main.d
r70 r71 111 111 SpriteNode star = new SpriteNode(l1); 112 112 star.setMaterial("space/star.xml"); 113 star.setS cale(Vec3f(2500));113 star.setSize(Vec3f(2500)); 114 114 115 115 // Planet 116 116 auto planet = new ModelNode(scene); 117 117 planet.setModel("space/planet.ms3d"); 118 planet.s cale = Vec3f(60);118 planet.setSize(Vec3f(60)); 119 119 planet.setAngularVelocity(Vec3f(0, -0.01, 0)); 120 120 trunk/src/demo1/ship.d
r70 r71 35 35 ship = new ModelNode(pitch); 36 36 ship.setModel("scifi/fighter.ms3d"); 37 ship.s cale = Vec3f(.25);37 ship.setSize(Vec3f(.25)); 38 38 39 39 spring = new Spring(ship); … … 75 75 puff.setMaterial(Resource.material("fx/smoke.xml")); 76 76 puff.setLifetime(5); 77 puff.setS cale(Vec3f(.4));77 puff.setSize(Vec3f(.4)); 78 78 //puff.setVelocity(getVelocity() - Vec3f(0, 0, -10).rotate(ship.getAbsoluteTransform())); 79 79 puff.setPosition(ship.getAbsolutePosition()+Vec3f(.8, 0, 2.5).rotate(ship.getAbsoluteTransform())); … … 83 83 node.setColor(Color(1, 1, 1, node.getLifetime()/5)); 84 84 float scale = std.math.sqrt(5.0f)-std.math.sqrt(node.getLifetime()) + .4; 85 node.setS cale(scale);85 node.setSize(scale); 86 86 } 87 87 puff.onUpdate(&fade); trunk/src/demo2/gameobj.d
r70 r71 47 47 void setMass(float mass) 48 48 { this.mass = mass; 49 rock.setS cale(Vec3f(pow(mass, .33333)/2));49 rock.setSize(Vec3f(pow(mass, .33333)/2)); 50 50 radius = pow(mass, .3333)*.75*4; 51 51 } … … 63 63 SpriteNode flare = new SpriteNode(this); 64 64 flare.setMaterial("fx/flare1.xml"); 65 flare.setS cale(Vec3f(2));65 flare.setSize(Vec3f(2)); 66 66 67 67 if (timer is null) trunk/src/demo2/main.d
r70 r71 202 202 SpriteNode star = new SpriteNode(l1); 203 203 star.setMaterial("space/star.xml"); 204 star.setS cale(Vec3f(2500));204 star.setSize(Vec3f(2500)); 205 205 206 206 // Planet 207 207 auto planet = new ModelNode(scene); 208 208 planet.setModel("space/planet.ms3d"); 209 planet.s cale = Vec3f(600);209 planet.setSize(Vec3f(600)); 210 210 planet.setAngularVelocity(Vec3f(0, -0.01, 0)); 211 211 trunk/src/demo2/ship.d
r70 r71 34 34 ship = new ModelNode(pitch); 35 35 ship.setModel("obj/tie2.obj"); 36 ship.s cale = Vec3f(.25);36 ship.setSize(Vec3f(.25)); 37 37 38 38 spring = new Spring(ship); trunk/src/yage/core/all.d
r67 r71 25 25 import yage.core.repeater; 26 26 import yage.core.timer; 27 import yage.core.tree; 27 28 import yage.core.types; 28 29 import yage.core.vector; trunk/src/yage/core/xml.d
r28 r71 7 7 * documents. 8 8 * 9 * It might eventually be good to rewrite this to throw Exceptions on any parse 10 * errors--it already catches some. 9 * This hasn't been profiled and probably isn't that efficient. 11 10 * 12 11 * History: trunk/src/yage/gui/surface.d
r57 r71 28 28 29 29 /** 30 * A surface will be similar to an HTML DOM element, including having text inside it,30 * Surfaces are similar to HTML DOM elements, including having text inside it, 31 31 * margin, padding, a border, and a background texture, including textures from a camera. 32 32 * Surfaces will exist in a hierarchical structure, with each having a parent and an array of children. 33 * The children will be positioned relative to the borders of their parent. */ 33 * Surfacs are positioned relative to their parent. 34 * A style struct defines most of the styles associated with the Surface. */ 34 35 class Surface{ 35 36 static final Style defaultStyle; … … 37 38 38 39 //Change from GPUTexture to Texture or Material 39 private GPUTexture texture; 40 41 Surface[] subs; 40 protected GPUTexture texture; 41 42 Surface parent; 43 Surface[] children; 42 44 //Not sure if I should have a reference to Parent or not, but for now, I will. 43 Surface parent;45 44 46 45 47 Vec2f topLeft;//rid self of these … … 52 54 53 55 //these are for calculating 54 pr ivateVec2i locationAdd;56 protected Vec2i locationAdd; 55 57 56 58 //used for the texture … … 139 141 parent = p; 140 142 if(parent is null){ 141 Device. subs~= this;143 Device.children ~= this; 142 144 this.recalculate(); 143 145 } 144 146 else{ 145 parent. subs~= this;147 parent.children ~= this; 146 148 this.recalculate(); 147 149 } … … 171 173 172 174 private void recalculateSubs(){ 173 foreach(sub ;this.subs)175 foreach(sub; this.children) 174 176 sub.recalculate(position1, position2, size); 175 177 } … … 480 482 // subs.radixSort((Surface s){return s.style.zIndex;} ); 481 483 482 foreach(sub; subs)484 foreach(sub; children) 483 485 sub.draw(); 484 486 } … … 491 493 void raise(){ //Could be cleaner, whatever, I'll fix it later 492 494 if(parent is null){ 493 uint index = findIndex(this, Device. subs);494 for(; index < Device. subs.length - 1; index++)495 Device. subs[index] = Device.subs[index+1];496 Device. subs[$-1] = this;495 uint index = findIndex(this, Device.children); 496 for(; index < Device.children.length - 1; index++) 497 Device.children[index] = Device.children[index+1]; 498 Device.children[$-1] = this; 497 499 } 498 500 else{ 499 uint index = findIndex(this, parent. subs);500 for(; index < parent. subs.length - 1; index++)501 parent. subs[index] = parent.subs[index+1];502 parent. subs[$-1] = this;501 uint index = findIndex(this, parent.children); 502 for(; index < parent.children.length - 1; index++) 503 parent.children[index] = parent.children[index+1]; 504 parent.children[$-1] = this; 503 505 } 504 506 if(onFocus) onFocus(this); … … 534 536 535 537 bool isSub(Surface surf){ 536 foreach(sub; subs){538 foreach(sub; children){ 537 539 if (sub == surf) return true; 538 540 } … … 544 546 //Could be better, a method perhaps... 545 547 Surface findSurface(int x, int y){ 546 foreach_reverse(sub; Device. subs){548 foreach_reverse(sub; Device.children){ 547 549 if(sub.position1.x <= x && x <= sub.position2.x && sub.position1.y <= y && y <= sub.position2.y){ 548 550 return findSurface(sub, x, y); … … 553 555 //Could be better, a method perhaps... 554 556 Surface findSurface(Surface surface,int x, int y){ 555 foreach_reverse(sub; surface. subs){557 foreach_reverse(sub; surface.children){ 556 558 if(sub.position1.x <= x && x <= sub.position2.x && sub.position1.y <= y && y <= sub.position2.y){ 557 559 return findSurface(sub, x, y); trunk/src/yage/node/graph.d
r70 r71 101 101 102 102 /// Overridden to cache the radius if changed by the scale. 103 void scale(Vec3f scale) 104 { this.scale = scale; 105 radius = model.getDimensions().scale(scale).length(); 106 } 107 108 Vec3f scale() 109 { return super.scale; 103 void setSize(Vec3f size) 104 { this.size = size; 105 radius = model.getDimensions().scale(size).length(); 106 } 107 Vec3f getSize() /// Ditto 108 { return super.size; 110 109 } 111 110 … … 229 228 model.getMeshes()[0].setTriangles(triangles); 230 229 231 radius = model.getDimensions().scale(s cale).max();230 radius = model.getDimensions().scale(size).max(); 232 231 233 232 // Cache model in video memory trunk/src/yage/node/model.d
r70 r71 48 48 void setModel(Model model) 49 49 { this.model = model; 50 radius = model.getDimensions().scale(s cale).length();50 radius = model.getDimensions().scale(size).length(); 51 51 } 52 52 … … 60 60 61 61 /// Overridden to cache the radius if changed by the scale. 62 void s cale(Vec3f s)63 { super.s cale = Vec3f(s.x, s.y, s.z);62 void setSize(Vec3f s) 63 { super.size = Vec3f(s.x, s.y, s.z); 64 64 if (model) 65 radius = model.getDimensions().scale(scale).max(); 66 } 67 68 Vec3f scale() 69 { return super.scale; 65 radius = model.getDimensions().scale(size).max(); 66 } 67 Vec3f getSize() /// Ditto 68 { return super.size; 70 69 } 71 70 trunk/src/yage/node/node.d
r70 r71 11 11 import std.bind; 12 12 import yage.core.all; 13 import yage.core.tree; 13 14 import yage.node.visible; 14 15 import yage.node.scene; … … 44 45 * // to 0, 0, 0, instead of a. 45 46 * --------------------------------*/ 46 abstract class Node 47 abstract class Node : Tree!(Node) 47 48 { 48 49 // These are public for easy internal access. 49 50 Scene scene; // The Scene that this node belongs to. 50 Node parent;51 Node[Node] children;52 51 protected float lifetime = float.infinity; // in seconds 53 52 protected void delegate(Node self) on_update = null; // called on update … … 89 88 90 89 /// Construct as a child of parent, a copy of original and recursivly copy all children. 91 this(Node parent, MovableNode original)90 this(Node parent, Node original) 92 91 { this(parent); 93 92 … … 135 134 136 135 /** 137 * Add a child Node.138 * Automatically detaches it from any other nodes.139 * Returns: A self reference.*/140 Node addChild(VisibleNode child)141 in {assert(child !is this);}142 body143 { child.setParent(this);144 return this;145 }146 147 /// Get an array of this Node's children148 Node[Node] getChildren()149 { return children;150 }151 152 /**153 136 * Get / set the lifeime of a VisibleNode (in seconds). 154 137 * The default value is float.infinity, but a lower number will cause the VisibleNode to be removed … … 162 145 163 146 /** 164 * Get / set the parent of this Node (what it's attached to). 165 * Setting a new parent removes it from its old parent's children and returns a self-reference. */ 166 Node getParent() 167 { return parent; 168 } 147 * Overridden from Tree to set scene and mark transform dirty. */ 169 148 Node setParent(Node _parent) /// Ditto 170 in { assert(_parent !is null); 171 }body 172 { 173 if (parent && this in parent.children) 174 parent.children.remove(this); 175 176 // Add to new parent 177 parent = _parent; 178 parent.children[this] = this; 179 scene = parent.scene; 149 { scene = _parent.scene; 180 150 setTransformDirty(); 181 return this;151 return super.setParent(_parent); 182 152 } 183 153 … … 256 226 return result; 257 227 } 258 259 /// Remove this Node. This function should be used instead of delete.260 void remove()261 { // this needs to happen because some children (like lights) may need to do more in their remove() function.262 foreach(Node c; children)263 c.remove();264 265 if (parent && this in parent.children)266 parent.children.remove(this);267 }268 228 269 229 /** trunk/src/yage/node/sprite.d
r70 r71 43 43 /// Return the distance to the furthest point of the SpriteNode. 44 44 float getRadius() 45 { return 1.414213562*s cale.max();45 { return 1.414213562*size.max(); 46 46 } 47 47 trunk/src/yage/node/terrain.d
r70 r71 33 33 * -------------------------------- 34 34 * TerrainNode a = new TerrainNode(scene); // Child of scene 35 * a.setS cale(1000, 100, 1000); // Make it a decent size35 * a.setSize(1000, 100, 1000); // Make it a decent size 36 36 * a.setMaterial("terrain/islands.xml"); 37 37 * a.setHeightMap("terrain/islands-height.png"); … … 84 84 * Generate the 3D landscape rendered for this Node, from a heighmap image. 85 85 * The terrain generated always fits inside a 1x1x1 cube. 86 * Use setS cale() to adjust to a comfortable size.86 * Use setSize() to adjust to a comfortable size. 87 87 * Params: 88 88 * grayscale = An image to load. It will be converted to a grayscale image … … 157 157 158 158 Vec3f scale() 159 { return super.s cale;159 { return super.size; 160 160 } 161 161 trunk/src/yage/node/visible.d
r70 r71 33 33 { 34 34 protected bool visible = true; 35 protected Vec3f s cale;35 protected Vec3f size; 36 36 protected Color color; // RGBA, used for glColor4f() 37 37 … … 42 42 this(Node parent) 43 43 { visible = false; 44 s cale = Vec3f(1);44 size = Vec3f(1); 45 45 color = Color("white"); 46 46 super(parent); … … 51 51 { super(parent, original); 52 52 visible = original.visible; 53 s cale = original.scale;53 size = original.size; 54 54 color = original.color; 55 55 } … … 88 88 /// Get the radius of this VisibleNode's culling sphere. 89 89 float getRadius() 90 { return 1.732050807*s cale.max(); // a value of zero would not be rendered since it's always smaller than the pixel threshold.90 { return 1.732050807*size.max(); // a value of zero would not be rendered since it's always smaller than the pixel threshold. 91 91 } // This is the radius of a 1x1x1 cube 92 92 … … 94 94 * Get / set the scale of this VisibleNode in the x, y, and z directions. 95 95 * The default is (1, 1, 1). Unlike position and rotation, scale is not inherited. */ 96 void setS cale(float x, float y, float z)97 { s cale.set(x, y, z);96 void setSize(float x, float y, float z) 97 { size.set(x, y, z); 98 98 } 99 void setS cale(Vec3f scale) /// ditto100 { setS cale(scale.x, scale.y, scale.z);99 void setSize(Vec3f size) /// ditto 100 { setSize(size.x, size.y, size.z); 101 101 } 102 void setS cale(float scale) /// ditto103 { setS cale(scale, scale, scale);102 void setSize(float size) /// ditto 103 { setSize(size, size, size); 104 104 } 105 Vec3f getS cale() /// ditto106 { return s cale;105 Vec3f getSize() /// ditto 106 { return size; 107 107 } 108 108 trunk/src/yage/system/device.d
r56 r71 63 63 public: 64 64 65 static Surface[] subs;65 static Surface[] children; 66 66 67 67 /// Unload SDL at exit. … … 338 338 size.y = height; 339 339 340 foreach(sub ;this. subs) sub.recalculate(Vec2i(0, 0), size, size);340 foreach(sub ;this.children) sub.recalculate(Vec2i(0, 0), size, size); 341 341 342 342 // For some reason, SDL Linux requires a call to SDL_SetVideoMode for a screen resize that's 343 // larger than the current screen. (need to try this with latest version of SDL, als ytry SDL lock surface)343 // larger than the current screen. (need to try this with latest version of SDL, also try SDL lock surface) 344 344 // This same code would crash the engine on windows. 345 345 // This code may now be un-needed and needs to be retested. trunk/src/yage/system/render.d
r70 r71 83 83 glPushMatrix(); 84 84 glMultMatrixf(n.getAbsoluteTransform(true).v.ptr); 85 glScalef(n.getScale().x, n.getScale().y, n.getScale().z); 85 Vec3f size = n.getSize(); 86 glScalef(size.x, size.y, size.z); 86 87 n.enableLights(); 87 88 … … 89 90 { case "yage.node.model.ModelNode": 90 91 model((cast(ModelNode)n).getModel(), n); 91 //writefln((cast(ModelNode)n).getModel().getSource());92 92 break; 93 93 case "yage.node.sprite.SpriteNode": … … 140 140 /* 141 141 for (int i=0; i<3; i++) 142 { at.vertices[i] = abs_transform*v[tri.v[i]].scale(node.getS cale());142 { at.vertices[i] = abs_transform*v[tri.v[i]].scale(node.getSize()); 143 143 at.texcoords[i] = &t[tri.v[i]]; 144 144 at.normals[i] = &n[tri.v[i]]; … … 211 211 { AlphaTriangle at; 212 212 for (int i=0; i<3; i++) 213 { at.vertices[i] = abs_transform*v[tri.v[i]].scale(node.getS cale());213 { at.vertices[i] = abs_transform*v[tri.v[i]].scale(node.getSize()); 214 214 at.texcoords[i] = &t[tri.v[i]]; 215 215 at.normals[i] = &n[tri.v[i]]; trunk/src/yage/util/misc.d
r70 r71 55 55 56 56 a.setModel(Resource.model("space/asteroid1.ms3d")); 57 a.s cale = Vec3f(value5*value5*value5*value5*value5*value5*value5*1.1 + .2);57 a.setSize(Vec3f(value5*value5*value5*value5*value5*value5*value5*1.1 + .2)); 58 58 a.rotate(Vec3f(value4*12, value2*12, value3*12)); 59 a.setAngularVelocity(Vec3f(random(-.2, .2), random(-.2, .2), random(-.2, .2)));59 // a.setAngularVelocity(Vec3f(random(-.2, .2), random(-.2, .2), random(-.2, .2))); 60 60 } 61 61 } … … 74 74 75 75 a.setModel(Resource.model("../media/planet/phobos.ms3d")); 76 a.s cale = Vec3f(value5*value5*.4 + .2);76 a.setSize(Vec3f(value5*value5*.4 + .2)); 77 77 a.rotate(Vec3f(value4*12, value2*7, value3*11)); 78 78 } … … 91 91 92 92 a.setModel(Resource.model("../media/planet/phobos.ms3d")); 93 a.s cale = Vec3f(value5*value5*.4 + .2);93 a.setSize(Vec3f(value5*value5*.4 + .2)); 94 94 a.rotate(Vec3f(value4*12, value2*7, value*11)); 95 95 } trunk/src/yage/util/spring.d
r70 r71 57 57 tail.setRotation(head.getAbsoluteRotation()); 58 58 59 Vec3f dist = head.getAbsolutePosition() - tail.getAbsolutePosition() + distance.rotate(head.getAbsoluteTransform());60 Vec3f vel = dist.scale( min(stiffness, 1/delta)); // scale by 1/delta when framerate is low to prevent jerkiness.59 Vec3f dist = head.getAbsolutePosition() + distance.rotate(head.getAbsoluteTransform()) - tail.getAbsolutePosition(); 60 Vec3f vel = dist.scale(stiffness); 61 61 62 62 if (vel.length*delta > dist.length) 63 vel = dist; 64 tail. setVelocity(vel);63 vel = dist; 64 tail.move(vel*delta); 65 65 } 66 66 }
