Changeset 180

Show
Ignore:
Timestamp:
05/16/10 00:42:49 (2 years ago)
Author:
JoeCoder
Message:

Fixed some build errors in Demo2.
Fixed culling issue with previous build.
Started work on an interface for a new TerrainNode?, but it's very primitive at this point.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/res/readme.txt

    r176 r180  
    2525space/asteroid.dae          Eric Poggel, public domain 
    2626space/star.xml              Eric Poggel, public domain 
    27 scifi/fighter.dae         http://www.psionic3d.co.uk -- model and textures 
     27space/fighter.dae         http://www.psionic3d.co.uk -- model and textures 
    2828                            can be used for freeware, shareware, or commercial 
    2929                            games etc. 
  • trunk/src/demo1/main.d

    r179 r180  
    8383        planet = scene.addChild(new ModelNode("space/planet.dae")); 
    8484        planet.setSize(Vec3f(60)); 
     85        //planet.setSize(Vec3f(.5)); 
     86        //planet.setScale(Vec3f(.5)); 
     87        //planet.setId("planet"); 
    8588        planet.setAngularVelocity(Vec3f(0, -0.01, 0)); 
    8689         
  • trunk/src/demo1/ship.d

    r175 r180  
    4545 
    4646        ship = pitch.addChild(new ModelNode()); 
    47         ship.setModel("scifi/fighter.dae"); 
     47        ship.setModel("space/fighter.dae"); 
    4848        ship.setSize(Vec3f(.25)); 
    4949 
  • trunk/src/demo2/main.d

    r176 r180  
    3636    // Ship  
    3737    auto ship = scene.addChild(new ModelNode()); 
    38     ship.setModel("scifi/fighter.dae"); 
     38    ship.setModel("space/fighter.dae"); 
    3939    ship.setAngularVelocity(Vec3f(0, 1, 0)); 
    4040    ship.setScale(Vec3f(1)); 
     
    4848     
    4949    // Events for main surface. 
    50     bool grabbed = true; 
    5150    view.onKeyDown = delegate bool(Surface self, int key, int modifier){ 
    5251        if (key == SDLK_ESCAPE) 
     
    5554    }; 
    5655    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()); 
    6257        return true; 
    6358    }; 
     
    6560    // Lights 
    6661    auto l1 = scene.addChild(new LightNode()); 
    67     l1.setPosition(Vec3f(0, 30, -30));     
     62    l1.setPosition(Vec3f(0, 200, -30));    
    6863 
    6964    // For Testing 
  • trunk/src/yage/core/math/matrix.d

    r179 r180  
    8080            test("Inverse 2", Matrix(), c*c.inverse(), c); 
    8181            test("Identity", c, c*Matrix()); // [Below] compared this way because non-rotation values are lost. 
    82             // These fail on all dmd after 0.177 
    83             //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.177 
    91                 //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 9 
    97                 //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             } 
    10182        } 
    10283    } 
     
    169150        scale.v00 = rx_length; 
    170151        scale.v11 = ry_length; 
    171         scale.v22 = rz_length;      
     152        scale.v22 = rz_length; 
    172153    } 
    173154    unittest 
     
    199180    } 
    200181 
     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     
    201205    /** 
    202206     * Return a copy of this Matrix that has been inverted. 
     
    339343    } 
    340344 
    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     unittest 
    363     {   Matrix m; 
    364         Vec3f s = Vec3f(1, 2, 4); 
    365         m.setScalePreservingRotation(s); 
    366         assert(m.getScale() == s); 
    367     } 
    368      
    369345    /// 
    370346    float* ptr() 
     
    407383        Matrix position, rotation, scale; 
    408384        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))); 
    416386    } 
    417387    unittest 
     
    603573     * rotation values already present in the scale part of the Matrix. */ 
    604574    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 
    614579        Vec3f rx = Vec3f(v[0..3]); 
    615580        Vec3f ry = Vec3f(v[4..7]); 
    616581        Vec3f rz = Vec3f(v[8..11]); 
    617         float rx_length = rx.length(); 
    618         float ry_length = ry.length(); 
    619         float rz_length = rz.length(); 
    620582         
    621583        // 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)); 
    633593    } 
    634594 
  • trunk/src/yage/core/object2.d

    r178 r180  
    66module yage.core.object2; 
    77 
    8 import tango.math.random.Kiss; 
    9 import tango.util.Convert; 
     8//import tango.math.random.Kiss; 
     9//import tango.util.Convert; 
    1010import yage.core.format; 
     11import yage.system.log; 
    1112 
    1213debug { 
     
    1415} 
    1516 
    16 /* 
    17  * Unused. */ 
     17/** 
     18 * Base class of many Yage objects. 
     19 * Adds no additional weight. */ 
    1820class 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
    2099 
    21100/** 
  • trunk/src/yage/scene/camera.d

    r179 r180  
    150150                position[] = vnode.cache[scene.transform_read].transform_abs.v[12..15];          
    151151             
    152             float r = -(vnode.getRadius() * vnode.getScale().max()); 
     152            float r = -vnode.getRadius(); 
     153             
    153154             
    154155            vnode.onscreen = true;           
     
    176177                float dist = sqrt(x*x + y*y+z*z); 
    177178                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 
    181180                    vnode.onscreen = false; 
    182181                else // Onscreen and big enough to draw 
  • trunk/src/yage/scene/model.d

    r175 r180  
    138138    /// Overridden to cache the radius if changed by the scale. 
    139139    override void setSize(Vec3f s) /// Ditto 
    140     {   super.setSize(s); 
     140    {    
    141141        if (model) 
    142             radius = model.getRadius()*size.max(); 
     142            radius = radius / size.max() * s.max(); 
     143        super.setSize(s); 
    143144    }    
    144145     
     
    148149     * the most distant vertex.  There is no setRadius() */ 
    149150    float getRadius() 
    150     {   return radius
     151    {   return radius * getScale().max()
    151152    } 
    152153 
  • trunk/src/yage/scene/movable.d

    r179 r180  
    113113     * Note that scale is inherited by children.  Use get/setSize() of VisibleNode for a similar effect that'snot inherited.*/ 
    114114    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(); 
    116117    } 
    117118    void setScale(Vec3f scale) /// ditto; 
  • trunk/src/yage/scene/terrain.d

    r153 r180  
    66 
    77module yage.scene.terrain; 
     8 
     9 
     10import yage.core.math.vector; 
     11import yage.resource.geometry; 
     12import yage.resource.image; 
     13import yage.resource.material; 
     14import yage.scene.camera; 
     15import yage.scene.node; 
     16import yage.scene.visible; 
     17 
     18class 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 
    857/+ 
    958This module needs to be brought up to date with the rest of the Yage API before it 
    1059will work. 
    11  
    12 import tango.util.Convert; 
    1360 
    1461import yage.resource.manager; 
     
    1663import yage.resource.model; 
    1764import yage.resource.mesh; 
    18 import yage.resource.image; 
    19 import yage.scene.node; 
    20 import yage.scene.visible; 
     65 
    2166import yage.core.math.matrix; 
    22 import yage.core.math.vector; 
    2367import yage.system.system; 
    2468import yage.system.log; 
  • trunk/src/yage/scene/visible.d

    r179 r180  
    7070 
    7171    /** 
    72      * Get the radius of this VisibleNode's culling sphere.  Includes size but not scale. 
     72     * Get the radius of this VisibleNode's culling sphere.  Includes both size and scale. 
    7373     * Classes that inherit VisibleNode must provide this function to specify their radius, or they will not be rendered. */  
    7474    float getRadius() 
     
    131131         
    132132        foreach (l; all_lights) 
    133         {   l.intensity = l.getBrightness(position, getRadius()*getScale().max()).vec3f.average(); 
     133        {   l.intensity = l.getBrightness(position, getRadius()).vec3f.average(); 
    134134            if (l.intensity >= 1/256f) // smallest noticeable brightness for 8-bit per channel color (1/256f). 
    135135                addSorted!(LightNode, float)(lights, l, false, (LightNode a){return a.intensity;}, number );