Changeset 180
- Timestamp:
- 05/16/10 00:42:49 (2 years ago)
- Files:
-
- trunk/res/readme.txt (modified) (1 diff)
- trunk/res/space/fighter.dae (added)
- trunk/res/terrain/islands-height.png (deleted)
- trunk/res/terrain/islands.jpg (deleted)
- trunk/src/demo1/main.d (modified) (1 diff)
- trunk/src/demo1/ship.d (modified) (1 diff)
- trunk/src/demo2/main.d (modified) (4 diffs)
- trunk/src/yage/core/math/matrix.d (modified) (6 diffs)
- trunk/src/yage/core/object2.d (modified) (2 diffs)
- trunk/src/yage/scene/camera.d (modified) (2 diffs)
- trunk/src/yage/scene/model.d (modified) (2 diffs)
- trunk/src/yage/scene/movable.d (modified) (1 diff)
- trunk/src/yage/scene/terrain.d (modified) (2 diffs)
- trunk/src/yage/scene/visible.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/res/readme.txt
r176 r180 25 25 space/asteroid.dae Eric Poggel, public domain 26 26 space/star.xml Eric Poggel, public domain 27 s cifi/fighter.dae http://www.psionic3d.co.uk -- model and textures27 space/fighter.dae http://www.psionic3d.co.uk -- model and textures 28 28 can be used for freeware, shareware, or commercial 29 29 games etc. trunk/src/demo1/main.d
r179 r180 83 83 planet = scene.addChild(new ModelNode("space/planet.dae")); 84 84 planet.setSize(Vec3f(60)); 85 //planet.setSize(Vec3f(.5)); 86 //planet.setScale(Vec3f(.5)); 87 //planet.setId("planet"); 85 88 planet.setAngularVelocity(Vec3f(0, -0.01, 0)); 86 89 trunk/src/demo1/ship.d
r175 r180 45 45 46 46 ship = pitch.addChild(new ModelNode()); 47 ship.setModel("s cifi/fighter.dae");47 ship.setModel("space/fighter.dae"); 48 48 ship.setSize(Vec3f(.25)); 49 49 trunk/src/demo2/main.d
r176 r180 36 36 // Ship 37 37 auto ship = scene.addChild(new ModelNode()); 38 ship.setModel("s cifi/fighter.dae");38 ship.setModel("space/fighter.dae"); 39 39 ship.setAngularVelocity(Vec3f(0, 1, 0)); 40 40 ship.setScale(Vec3f(1)); … … 48 48 49 49 // Events for main surface. 50 bool grabbed = true;51 50 view.onKeyDown = delegate bool(Surface self, int key, int modifier){ 52 51 if (key == SDLK_ESCAPE) … … 55 54 }; 56 55 view.onMouseDown = delegate bool(Surface self, byte buttons, Vec2i coordinates, char[] href) { 57 grabbed = !grabbed; 58 if (grabbed) 59 self.grabMouse(); 60 else 61 self.releaseMouse(); 56 self.grabMouse(!self.getGrabbedMouse()); 62 57 return true; 63 58 }; … … 65 60 // Lights 66 61 auto l1 = scene.addChild(new LightNode()); 67 l1.setPosition(Vec3f(0, 30, -30));62 l1.setPosition(Vec3f(0, 200, -30)); 68 63 69 64 // For Testing trunk/src/yage/core/math/matrix.d
r179 r180 80 80 test("Inverse 2", Matrix(), c*c.inverse(), c); 81 81 test("Identity", c, c*Matrix()); // [Below] compared this way because non-rotation values are lost. 82 // These fail on all dmd after 0.17783 //test("toQuatrn & toAxis", c.toAxis().toMatrix(), c.toQuatrn().toMatrix(), c);84 //Matrix res = c;85 //res.set(c.toQuatrn());86 //test("Set Rotation", res, c);87 88 foreach (Matrix d; m)89 { test("Multiply & Inverse", c, c*d*d.inverse(), d);90 // These fail on all dmd after 0.17791 //test("MoveRelative", c, c.moveRelative(d.toAxis()).moveRelative(d.toAxis().negate()), d);92 //test("Rotate Matrix", c, c.rotate(d).rotate(d.inverse()), d);93 //test("Rotate Quatrn", c, c.rotate(d.toQuatrn()).rotate(d.toQuatrn().inverse()), d);94 //test("Rotate Axis", c, c.rotate(d.toAxis()).rotate(d.toAxis().negate()), d);95 96 // These don't pass for Matrices 7, 8, and 997 //test("Rotate Absolute Matrix", c, c.rotateAbsolute(d).rotateAbsolute(d.inverse()), d);98 //test("Rotate Absolute Quatrn", c, c.rotateAbsolute(d.toQuatrn()).rotateAbsolute(d.toQuatrn().inverse()), d);99 //test("Rotate Absolute Axis", c, c.rotateAbsolute(d.toAxis()).rotateAbsolute(d.toAxis().inverse()), d);100 }101 82 } 102 83 } … … 169 150 scale.v00 = rx_length; 170 151 scale.v11 = ry_length; 171 scale.v22 = rz_length; 152 scale.v22 = rz_length; 172 153 } 173 154 unittest … … 199 180 } 200 181 182 /** 183 * Get the position component of the Matrix as a Vector. */ 184 Vec3f getPosition() 185 { return Vec3f(v[12..15]); 186 } 187 188 /** 189 * Extract the scale Vector from the rotation component of the Matrix. 190 * Scale components will always be positive. */ 191 Vec3f getScale() 192 { return Vec3f( 193 Vec3f(v[0..3]).length(), 194 Vec3f(v[4..7]).length(), 195 Vec3f(v[8..11]).length()); 196 } 197 unittest 198 { Matrix m; 199 Vec3f s = Vec3f(1, 2, 4); 200 m.setScalePreservingRotation(s); 201 assert(m.getScale() == s); 202 } 203 204 201 205 /** 202 206 * Return a copy of this Matrix that has been inverted. … … 339 343 } 340 344 341 /**342 * Get the position component of the Matrix as a Vector. */343 Vec3f getPosition()344 { return Vec3f(v[12..15]);345 }346 347 /**348 * Extract the scale Vector from the rotation component of the Matrix.349 * Scale components will always be positive. */350 Vec3f getScale()351 {352 // Matrix position, rotation, scale;353 //decompose(position, rotation, scale);354 //return Vec3f(scale[0], scale[5], scale[10]);355 356 return Vec3f(357 Vec3f(v[0..3]).length(),358 Vec3f(v[4..7]).length(),359 Vec3f(v[8..11]).length()360 );361 }362 unittest363 { Matrix m;364 Vec3f s = Vec3f(1, 2, 4);365 m.setScalePreservingRotation(s);366 assert(m.getScale() == s);367 }368 369 345 /// 370 346 float* ptr() … … 407 383 Matrix position, rotation, scale; 408 384 decompose(position, rotation, scale); 409 /* 410 rotation = rotation.rotate(rot).rotate(scale); 411 position.setRotation(rotation); // faster version of return scale * (rotation * position) 412 return position; 413 */ 414 415 return scale.transformAffine(position.transformAffine(rotation)); 385 return scale.transformAffine(position.transformAffine(rotation.rotate(rot))); 416 386 } 417 387 unittest … … 603 573 * rotation values already present in the scale part of the Matrix. */ 604 574 void setScalePreservingRotation(Vec3f scale) 605 { Matrix position, rotation, mscale; 606 decompose(position, rotation, mscale); 607 mscale[0] = scale.x; 608 mscale[5] = scale.y; 609 mscale[10] = scale.z; 610 setRotation(rotation.rotate(mscale)); 611 612 // TODO: This may be faster 613 /*Matrix result = *this; 575 { // Perform a partial decomposition and reset the scale 576 Matrix rotation, mscale; 577 578 // Extract the orientation basis vectors 614 579 Vec3f rx = Vec3f(v[0..3]); 615 580 Vec3f ry = Vec3f(v[4..7]); 616 581 Vec3f rz = Vec3f(v[8..11]); 617 float rx_length = rx.length();618 float ry_length = ry.length();619 float rz_length = rz.length();620 582 621 583 // Divide the basis vectors by their lengths to normalize them. 622 result.v[0..3] = rx.scale(1/rx_length).v[]; 623 result.v[4..7] = ry.scale(1/ry_length).v[]; 624 result.v[8..11]= rz.scale(1/rz_length).v[]; 625 626 Matrix mscale = Matrix(); 627 mscale.v00 = rx_length*scale.x; 628 mscale.v11 = ry_length*scale.y; 629 mscale.v22 = rz_length*scale.z; 630 631 return result.transformAffine(mscale); 632 */ 584 rotation.v[0..3] = rx.scale(1/rx.length()).v[]; 585 rotation.v[4..7] = ry.scale(1/ry.length()).v[]; 586 rotation.v[8..11]= rz.scale(1/rz.length()).v[]; 587 588 // Take the lengths of the basis vectors to find the scale factors. 589 mscale.v[0] = scale.x; 590 mscale.v[5] = scale.y; 591 mscale.v[10] = scale.z; 592 setRotation(rotation.rotate(mscale)); 633 593 } 634 594 trunk/src/yage/core/object2.d
r178 r180 6 6 module yage.core.object2; 7 7 8 import tango.math.random.Kiss;9 import tango.util.Convert;8 //import tango.math.random.Kiss; 9 //import tango.util.Convert; 10 10 import yage.core.format; 11 import yage.system.log; 11 12 12 13 debug { … … 14 15 } 15 16 16 /* 17 * Unused. */ 17 /** 18 * Base class of many Yage objects. 19 * Adds no additional weight. */ 18 20 class YageObject 19 {} 21 { 22 // These maps prevent the id system from adding any additional weight per object. 23 static YageObject[char[]] objects; 24 static char[][YageObject] objectsReverse; 25 26 ~this() 27 { if (this in objectsReverse) 28 { objects.remove(getId()); 29 objectsReverse.remove(this); 30 } 31 } 32 33 /** 34 * Get or set a unique identifier string associated with this object. 35 * Later, if another object is assigned the same id, this object will no longer be associated with it. */ 36 char[] getId() 37 { auto ptr = this in objectsReverse; 38 if (ptr) 39 return *ptr; 40 return ""; 41 } 42 void setId(char[] id) /// ditto 43 { if (id.length) 44 { 45 // If id already exists on another object 46 auto ptr = id in objects; 47 if (ptr) 48 objectsReverse.remove(*ptr); 49 50 // If this object previously had another id 51 char[] oldId = getId(); 52 if (oldId.length) 53 objects.remove(oldId); 54 55 objects[id] = this; 56 objectsReverse[this] = id; 57 } 58 else if (this in objectsReverse) 59 { objects.remove(getId()); 60 objectsReverse.remove(this); 61 } 62 } 63 64 /** 65 * Get the object previously assigned to the unique id string. 66 * If no object exists, null will be returned. */ 67 static YageObject getById(char[] id) 68 { auto ptr = id in objects; 69 if (ptr) 70 return *ptr; 71 return null; 72 } 73 74 unittest 75 { class Foo : YageObject {} 76 77 Foo a = new Foo(); 78 Foo b = new Foo(); 79 a.setId("a"); 80 b.setId("b"); 81 assert(a.getId()=="a"); 82 assert(b.getId()=="b"); 83 b.setId("a"); 84 assert(b.getId()=="a"); 85 assert(a.getId()==""); 86 b.setId(""); 87 assert(b.getId()==""); 88 assert(objects.length==0); 89 assert(objectsReverse.length==0); 90 91 a.setId("a"); 92 b.setId("b"); 93 delete a; 94 delete b; 95 assert(objects.length==0); 96 assert(objectsReverse.length==0); 97 } 98 } 20 99 21 100 /** trunk/src/yage/scene/camera.d
r179 r180 150 150 position[] = vnode.cache[scene.transform_read].transform_abs.v[12..15]; 151 151 152 float r = -(vnode.getRadius() * vnode.getScale().max()); 152 float r = -vnode.getRadius(); 153 153 154 154 155 vnode.onscreen = true; … … 176 177 float dist = sqrt(x*x + y*y+z*z); 177 178 float pixelHeight = 2*height * -r/dist; 178 //if (r*r*height*height*threshold < x*x + y*y + z*z) // equivalent to r/dist < pixel threshold 179 180 if (pixelHeight < .6667) 179 if (r*r*height*height*threshold < x*x + y*y + z*z) // equivalent to r/dist < pixel threshold 181 180 vnode.onscreen = false; 182 181 else // Onscreen and big enough to draw trunk/src/yage/scene/model.d
r175 r180 138 138 /// Overridden to cache the radius if changed by the scale. 139 139 override void setSize(Vec3f s) /// Ditto 140 { super.setSize(s);140 { 141 141 if (model) 142 radius = model.getRadius()*size.max(); 142 radius = radius / size.max() * s.max(); 143 super.setSize(s); 143 144 } 144 145 … … 148 149 * the most distant vertex. There is no setRadius() */ 149 150 float getRadius() 150 { return radius ;151 { return radius * getScale().max(); 151 152 } 152 153 trunk/src/yage/scene/movable.d
r179 r180 113 113 * Note that scale is inherited by children. Use get/setSize() of VisibleNode for a similar effect that'snot inherited.*/ 114 114 Vec3f getScale() 115 { return Vec3f(transform.v[0], transform.v[5], transform.v[10]); 115 { //return Vec3f(transform.v[0], transform.v[5], transform.v[10]); 116 return transform.getScale(); 116 117 } 117 118 void setScale(Vec3f scale) /// ditto; trunk/src/yage/scene/terrain.d
r153 r180 6 6 7 7 module yage.scene.terrain; 8 9 10 import yage.core.math.vector; 11 import yage.resource.geometry; 12 import yage.resource.image; 13 import yage.resource.material; 14 import yage.scene.camera; 15 import yage.scene.node; 16 import yage.scene.visible; 17 18 class TerrainNode : VisibleNode 19 { 20 21 protected Geometry[][] mipmaps; 22 23 this() 24 { 25 } 26 27 void setGeometry(T)(Image2!(T, 1) image=null, Vec3f delegate(float r, float s) func=null, Vec2f resolution=Vec2f(256)) 28 { 29 mipmaps.length = 3; // determined by resolution 30 mipmaps[0].length = 1; 31 mipmaps[1].length = 4; 32 mipmaps[2].length = 16; 33 34 assert(image || func); 35 } 36 37 38 void setMaterials(Material[] materials, float[][][] amounts) 39 { 40 } 41 42 /** 43 * 44 * Params: 45 * camera = 46 * lod = Size of a block of terrain in pixels 47 * Returns: 48 */ 49 Geometry[] getVisibleMipmaps(CameraNode camera, float lod=10) 50 { 51 return null; 52 } 53 54 } 55 56 8 57 /+ 9 58 This module needs to be brought up to date with the rest of the Yage API before it 10 59 will work. 11 12 import tango.util.Convert;13 60 14 61 import yage.resource.manager; … … 16 63 import yage.resource.model; 17 64 import yage.resource.mesh; 18 import yage.resource.image; 19 import yage.scene.node; 20 import yage.scene.visible; 65 21 66 import yage.core.math.matrix; 22 import yage.core.math.vector;23 67 import yage.system.system; 24 68 import yage.system.log; trunk/src/yage/scene/visible.d
r179 r180 70 70 71 71 /** 72 * Get the radius of this VisibleNode's culling sphere. Includes size but notscale.72 * Get the radius of this VisibleNode's culling sphere. Includes both size and scale. 73 73 * Classes that inherit VisibleNode must provide this function to specify their radius, or they will not be rendered. */ 74 74 float getRadius() … … 131 131 132 132 foreach (l; all_lights) 133 { l.intensity = l.getBrightness(position, getRadius() *getScale().max()).vec3f.average();133 { l.intensity = l.getBrightness(position, getRadius()).vec3f.average(); 134 134 if (l.intensity >= 1/256f) // smallest noticeable brightness for 8-bit per channel color (1/256f). 135 135 addSorted!(LightNode, float)(lights, l, false, (LightNode a){return a.intensity;}, number );
