Changeset 582

Show
Ignore:
Timestamp:
05/29/08 12:44:10 (7 months ago)
Author:
LeoD
Message:

rotated aabb and more stuff

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/defend/game/Game.d

    r579 r582  
    294294        //dumpGCStats(); 
    295295         
     296        sceneGraph.debugVisible = true; 
     297         
    296298        taskManager.addRepeatedTask(&InputChannel.global.update, 100); 
    297299        taskManager.addRepeatedTask(&gameObjects.update, 30); 
  • trunk/src/defend/game/hud/MiniMap.d

    r576 r582  
    141141    bool pointInside(vec2i pos) 
    142142    { 
    143         return pos.x >= position.x && pos.x < position.x + width && 
    144                pos.y >= position.y && pos.y < position.y + height; 
     143        return pos.x > position.x && pos.x < position.x + width && 
     144               pos.y > position.y && pos.y < position.y + height; 
    145145    } 
    146146     
  • trunk/src/defend/game/hud/Mouse.d

    r581 r582  
    77import gen.math.Vector; 
    88import gen.math.Matrix; 
     9import gen.math.Rectangle; 
    910import gen.math.BoundingBox; 
    1011import gen.rend.Renderer; 
     
    1415import gen.scene.Graph; 
    1516import gen.scene.ModelNode; 
    16 import gen.scene.ParticleSystem; 
    1717import gen.util.Profiler; 
    1818import gen.util.Memory; 
     
    181181                   obj.selected != selectedNeed || 
    182182                   obj.typeInfo.objectType != lastClickObjectType || 
    183                    !obj.mayBeOrdered) 
     183                   !obj.mayBeOrdered || 
     184                   (selectionBuffer.length && selectionBuffer[0].owner != obj.owner)) 
    184185                    continue; 
    185186                 
     
    648649                   &result.x, &result.y, &result.z); 
    649650 
    650         return vec2i(cast(int)result.x, cast(int)result.y); 
     651        return vec2i(cast(int)result.x, renderer.height - cast(int)result.y); 
    651652    } 
    652653 
     
    723724 
    724725                    auto pos = getScreenPos(obj.realPos); 
    725                     pos.y = renderer.height - pos.y
     726                    //auto rect = obj.screenRect
    726727 
    727728                    if((pos.x >= minX && pos.x <= maxX && 
     
    780781 
    781782            obj.screenPos = getScreenPos(obj.realPos); 
    782             obj.screenPos.y = cast(int)renderer.height - obj.screenPos.y; 
     783 
     784            auto bbox = obj.sceneNode.boundingBox; 
     785 
     786            with(bbox) 
     787            { 
     788                obj.screenPos_[0] = getScreenPos(min); 
     789                obj.screenPos_[1] = getScreenPos(vec3(max.x, min.y, min.z)); 
     790                obj.screenPos_[2] = getScreenPos(vec3(min.x, max.y, min.z)); 
     791                obj.screenPos_[3] = getScreenPos(vec3(max.x, max.y, min.z)); 
     792                obj.screenPos_[4] = getScreenPos(vec3(min.x, min.y, max.z)); 
     793                obj.screenPos_[5] = getScreenPos(vec3(max.x, min.y, max.z)); 
     794                obj.screenPos_[6] = getScreenPos(vec3(min.x, max.y, max.z)); 
     795                obj.screenPos_[7] = getScreenPos(max); 
     796            } 
     797             
     798            obj.screenRect = Rectangle!(int)(int.max, int.max, int.min, int.min); 
     799 
     800            with(obj.screenRect) 
     801            { 
     802                foreach(x; obj.screenPos_) 
     803                { 
     804                    left = min(left, x.x); 
     805                    right = max(right, x.x); 
     806                    top = min(top, x.y); 
     807                    bottom = max(bottom, x.y); 
     808                } 
     809            } 
    783810        } 
    784811 
    785812        // TODO: Don't use GL directly 
     813        renderer.setRenderState(RenderState.Blending, true); 
     814        renderer.setBlendFunc(BlendFunc.SrcAlpha, BlendFunc.OneMinusSrcAlpha); 
     815         
    786816        glBegin(GL_QUADS); 
    787817 
     
    795825            const int BORDER_SIZE = 1; 
    796826 
    797             if(obj.screenPos.x < 0 || obj.screenPos.y < 0 || obj.screenPos.x > renderer.width || 
     827            /+if(obj.screenPos.x < 0 || obj.screenPos.y < 0 || obj.screenPos.x > renderer.width || 
    798828               obj.screenPos.y - BAR_HEIGHT > renderer.height - HUD_HEIGHT) 
    799                continue; 
    800  
    801             auto start = obj.screenPos; 
     829               continue;+/ 
     830 
     831            /+auto start = obj.screenPos; 
    802832            start.x -= 15; 
    803833            start.y -= 30; 
    804834 
    805             auto end = vec2i(start.x + BAR_WIDTH, start.y + BAR_HEIGHT); 
    806  
    807             glColor3f(1, 1, 1); 
     835            auto end = vec2i(start.x + BAR_WIDTH, start.y + BAR_HEIGHT);+/ 
     836 
     837            auto start = obj.screenRect.begin; 
     838            auto end = obj.screenRect.end; 
     839             
     840            //end.y -= (end.y - start.y) * 0.9; 
     841            //end.x -= (end.x - start.x) * 0.5; 
     842 
     843            // white border 
     844            /+glColor4f(1, 1, 1, 0.5); 
    808845 
    809846            glVertex2f(start.x, start.y); 
    810847            glVertex2f(start.x, end.y); 
    811848            glVertex2f(end.x, end.y); 
    812             glVertex2f(end.x, start.y); 
    813  
     849            glVertex2f(end.x, start.y);+/ 
     850 
     851            /+// green bar 
    814852            glColor3f(1, 0, 0); 
    815853             
     
    819857            glVertex2f(end.x - BORDER_SIZE, start.y + BORDER_SIZE); 
    820858 
     859            // red bar 
    821860            { 
    822861                glColor3f(0, 1, 0); 
     
    830869                glVertex2f(endX - BORDER_SIZE, end.y - BORDER_SIZE); 
    831870                glVertex2f(endX - BORDER_SIZE, start.y + BORDER_SIZE); 
     871            }+/ 
     872 
     873            glColor4f(0, 0, 1, 0.8); 
     874             
     875            foreach(x; obj.screenPos_) 
     876            { 
     877                glVertex2f(x.x, x.y); 
     878                glVertex2f(x.x, x.y + 3); 
     879                glVertex2f(x.x + 3, x.y + 3); 
     880                glVertex2f(x.x + 3, x.y); 
    832881            } 
    833882 
     
    836885 
    837886        glEnd(); 
     887 
     888        renderer.setRenderState(RenderState.Blending, false); 
    838889 
    839890        if(status == Status.AreaSelection) 
     
    847898            glBegin(GL_LINES); 
    848899            glColor3f(1, 1, 1); 
    849  
     900             
     901            // top 
    850902            glVertex2f(minX, minY); 
    851903            glVertex2f(maxX, minY); 
    852904 
     905            // bottom 
     906            glVertex2f(minX, maxY); 
     907            glVertex2f(maxX, maxY); 
     908 
     909            // left 
    853910            glVertex2f(minX, minY); 
    854911            glVertex2f(minX, maxY); 
    855912 
    856             glVertex2f(minX, maxY); 
    857             glVertex2f(maxX, maxY); 
    858  
    859             glVertex2f(maxX, maxY); 
    860             glVertex2f(maxX, minY); 
     913            // right 
     914            glVertex2f(maxX - 1, minY); 
     915            glVertex2f(maxX - 1, maxY); 
     916             
    861917            glEnd(); 
     918             
     919            renderer.setRenderState(RenderState.Blending, true); 
     920            renderer.setBlendFunc(BlendFunc.SrcAlpha, BlendFunc.OneMinusSrcAlpha); 
     921             
     922            glBegin(GL_QUADS); 
     923             
     924            glColor4f(0, 0, 0.5, 0.1); 
     925             
     926            glVertex2f(minX + 1, minY + 1); 
     927            glVertex2f(minX + 1, maxY - 1); 
     928            glVertex2f(maxX - 1, maxY - 1); 
     929            glVertex2f(maxX - 1, minY + 1); 
     930             
     931            glEnd(); 
     932             
     933            glColor3f(1, 1, 1); 
     934             
     935            renderer.setRenderState(RenderState.Blending, false); 
    862936        } 
    863937 
  • trunk/src/defend/sim/Core.d

    r581 r582  
    694694    // For selection 
    695695    vec2i screenPos; 
     696    vec2i[8] screenPos_; 
     697    Rectangle!(int) screenRect; 
    696698 
    697699    object_status_t status() { return _status; } 
  • trunk/src/defend/sim/SceneNode.d

    r580 r582  
    3535    void calcBoundingBox() 
    3636    { 
    37         //bbox = model.boundingBox; 
     37        // doesn't include the parents rotation D: 
     38        bbox =  modelInstance.boundingBox.xform(matrixRotation); 
    3839 
    3940        bbox.min *= scaling; 
     
    6162        foreach(mesh; model.meshes) 
    6263            new GameObjectMesh(this, mesh); 
    63             
     64         
    6465        calcBoundingBox(); 
    6566    } 
     
    7374    override void update() 
    7475    { 
    75         bbox = modelInstance.boundingBox; 
    76         calcBoundingBox();  
     76        if(recalcModelview || modelInstance.newBoundingBox) 
     77           calcBoundingBox(); 
    7778    } 
    7879     
     
    8081    { 
    8182        visible = camera.frustum.boundingBoxVisible(bbox) && !fogOfWarCulled; 
    82          
    83         debug if(sceneGraph.debugNodeVisible(this)) 
     83        //visible = true; 
     84         
     85        debug if(sceneGraph.debugNodeVisible(this) && visible) 
    8486            sceneGraph.addToRender(RenderPass.Debug, this); 
    8587    } 
     
    8991        renderer.pushMatrix(); 
    9092        //renderer.mulMatrix(absoluteModelview); 
    91         renderer.drawBoundingBox(bbox, vec3(1, 0, 1)); 
     93        renderer.drawBoundingBox(bbox, vec3(0, 0.5, 1)); 
    9294        renderer.popMatrix(); 
    9395    } 
  • trunk/src/defend/sim/obj/Unit.d

    r581 r582  
    250250            else 
    251251            { 
    252                 assert(false, "there is no need for this!"); 
     252                //assert(false, "there is no need for this!"); // yes there is. 
     253                // happens when somebody suddenly puts a building in our way 
    253254             
    254255                // Test if this our last tile 
  • trunk/src/defend/terrain/Generator.d

    r581 r582  
    7070        { 
    7171            localCreate(cast(player_id_t)0, "house", 30, 30);            
    72             localCreate(cast(player_id_t)0, "sheep", 32, 29); 
     72            //localCreate(cast(player_id_t)0, "sheep", 32, 29); 
    7373             
    7474            if(players.isPlayer(cast(player_id_t)1)) 
  • trunk/src/defend/terrain/Map.d

    r581 r582  
    115115                    if(within(neighbor)) 
    116116                        calcTileCost(neighbor); 
    117  
    118117                } 
    119118 
     
    282281    body 
    283282    { 
     283        //scope bench = new Benchmark("path"); 
     284     
    284285        // needs to be totally rewritten :/ 
    285286        // posPool is shit. 
     
    441442        for(int i = 0; i < 4; i ++) 
    442443        { 
    443             MapPos[] tileList = posPool.allocate();; 
     444            MapPos[] tileList = posPool.allocate(); 
    444445            scope(exit) posPool.free(tileList); 
    445446            uint listIndex; 
  • trunk/src/defend/terrain/Terrain.d

    r579 r582  
    308308             
    309309            // Create a bounding box surrounding all the patches in this area 
     310            //logger.info("new cull node"); 
     311             
    310312            auto cullNode = new CullNode(parent); 
    311313             
     
    428430            renderer.setTexture(0, null); 
    429431 
    430             // debugging if the unit sight ranges are scaled correctly 
    431             /+renderer.setRenderState(RenderState.Wireframe, true); 
    432             renderer.setRenderState(RenderState.Blending, true); 
    433             renderer.setColor(vec4(1, 1, 1, 0.5)); 
    434              
    435             renderer.translate(0, 0.1, 0); 
    436              
    437             foreach(patch; patches) 
    438                 if(patch.visible) patch.render(); 
    439              
    440             renderer.setRenderState(RenderState.Blending, false); 
    441             renderer.setRenderState(RenderState.Wireframe, false);+/ 
    442  
    443432            debug if(sceneGraph.debugNodeVisible(this)) 
    444                 foreach(patch; patches) if(patch.visible) 
    445                     renderer.drawBoundingBox(patch.boundingBox, vec3(0, 0.7, 1)); 
    446              
    447             /+for(uint x = 0; x < dimension.x; x++) 
    448             { 
    449                 for(uint y = 0; y < dimension.y; y++) 
     433            { 
     434                //foreach(patch; patches) if(patch.visible) 
     435                //  renderer.drawBoundingBox(patch.boundingBox, vec3(0, 0.7, 1)); 
     436                     
     437                renderer.setRenderState(RenderState.Wireframe, true); 
     438                renderer.setRenderState(RenderState.Blending, true); 
     439                renderer.setColor(vec4(1, 1, 1, 0.5)); 
     440 
     441                renderer.translate(0, 0.1, 0); 
     442 
     443                foreach(patch; patches) 
     444                    if(patch.visible) patch.render(); 
     445 
     446                renderer.setRenderState(RenderState.Blending, false); 
     447                renderer.setRenderState(RenderState.Wireframe, false); 
     448                             
     449                version(none) for(uint x = 0; x < dimension.x; x++) 
    450450                { 
    451                     auto visible = fogOfWar.isVisible(x, y); 
    452                      
    453                     if(visible) 
     451                    for(uint y = 0; y < dimension.y; y++) 
    454452                    { 
    455                         auto pos = getWorldPos(x, y); 
    456                         renderer.drawLine(pos, pos + vec3(0, 1, 0), vec3(1, 0, 0)); 
     453                        auto visible = fogOfWar.isVisible(x, y); 
     454                         
     455                        if(visible) 
     456                        { 
     457                            auto pos = getWorldPos(x, y); 
     458                            renderer.drawLine(pos, pos + vec3(0, 1, 0), vec3(1, 0, 0)); 
     459                        } 
    457460                    } 
    458461                } 
    459             }+/ 
     462            } 
    460463             
    461464            renderer.popMatrix(); 
  • trunk/src/gen/math/BoundingBox.d

    r580 r582  
    22 
    33import gen.math.Vector; 
     4import gen.math.Matrix; 
    45import gen.math.Misc; 
    56 
    67struct BoundingBox(T) 
    78{ 
    8     Vec3!(T) min = { x: 10_000, y: 10_000, z: 10_000 }; 
    9     Vec3!(T) max = { x: -10_000, y: -10_000, z: -10_000 }; 
     9    Vec3!(T) min = { x: T.max, y: T.max, z: T.max }; 
     10    Vec3!(T) max = { x: T.min, y: T.min, z: T.min }; 
    1011    Vec3!(T) center = Vec3!(T).zero; 
    1112     
     
    5657        BoundingBox result = *this; 
    5758        result.expand(amount); 
     59         
     60        return result; 
     61    } 
     62     
     63    /+void xform(Mat4!(T) m) 
     64    { 
     65        auto box = *this; 
     66        min = max = m.getTranslation(); 
     67 
     68        // Examine each of the 9 matrix elements 
     69        // and compute the new AABB 
     70 
     71        if (m.col[1].row[1] > 0.0f) { 
     72            min.x += m.col[1].row[1] * box.min.x; max.x += m.col[1].row[1] * box.max.x; 
     73        } else { 
     74            min.x += m.col[1].row[1] * box.max.x; max.x += m.col[1].row[1] * box.min.x; 
     75        } 
     76 
     77        if (m.col[1].row[2] > 0.0f) { 
     78            min.y += m.col[1].row[2] * box.min.x; max.y += m.col[1].row[2] * box.max.x; 
     79        } else { 
     80            min.y += m.col[1].row[2] * box.max.x; max.y += m.col[1].row[2] * box.min.x; 
     81        } 
     82 
     83        if (m.col[1].row[3] > 0.0f) { 
     84            min.z += m.col[1].row[3] * box.min.x; max.z += m.col[1].row[3] * box.max.x; 
     85        } else { 
     86            min.z += m.col[1].row[3] * box.max.x; max.z += m.col[1].row[3] * box.min.x; 
     87        } 
     88 
     89        if (m.col[2].row[1] > 0.0f) { 
     90            min.x += m.col[2].row[1] * box.min.y; max.x += m.col[2].row[1] * box.max.y; 
     91        } else { 
     92            min.x += m.col[2].row[1] * box.max.y; max.x += m.col[2].row[1] * box.min.y; 
     93        } 
     94 
     95        if (m.col[2].row[2] > 0.0f) { 
     96            min.y += m.col[2].row[2] * box.min.y; max.y += m.col[2].row[2] * box.max.y; 
     97        } else { 
     98            min.y += m.col[2].row[2] * box.max.y; max.y += m.col[2].row[2] * box.min.y; 
     99        } 
     100 
     101        if (m.col[2].row[3] > 0.0f) { 
     102            min.z += m.col[2].row[3] * box.min.y; max.z += m.col[2].row[3] * box.max.y; 
     103        } else { 
     104            min.z += m.col[2].row[3] * box.max.y; max.z += m.col[2].row[3] * box.min.y; 
     105        } 
     106 
     107        if (m.col[3].row[1] > 0.0f) { 
     108            min.x += m.col[3].row[1] * box.min.z; max.x += m.col[3].row[1] * box.max.z; 
     109        } else { 
     110            min.x += m.col[3].row[1] * box.max.z; max.x += m.col[3].row[1] * box.min.z; 
     111        } 
     112 
     113        if (m.col[3].row[2] > 0.0f) { 
     114            min.y += m.col[3].row[2] * box.min.z; max.y += m.col[3].row[2] * box.max.z; 
     115        } else { 
     116            min.y += m.col[3].row[2] * box.max.z; max.y += m.col[3].row[2] * box.min.z; 
     117        } 
     118 
     119        if (m.col[3].row[3] > 0.0f) { 
     120            min.z += m.col[3].row[3] * box.min.z; max.z += m.col[3].row[3] * box.max.z; 
     121        } else { 
     122            min.z += m.col[3].row[3] * box.max.z; max.z += m.col[3].row[3] * box.min.z; 
     123        } 
     124    }+/ 
     125 
     126    BoundingBox xform(Mat4!(T) m) 
     127    {    
     128        BoundingBox result; 
     129        result.addPoint(m.xform(min)); 
     130        result.addPoint(m.xform(vec3(max.x, min.y, min.z))); 
     131        result.addPoint(m.xform(vec3(min.x, max.y, min.z))); 
     132        result.addPoint(m.xform(vec3(max.x, max.y, min.z))); 
     133        result.addPoint(m.xform(vec3(min.x, min.y, max.z))); 
     134        result.addPoint(m.xform(vec3(max.x, min.y, max.z))); 
     135        result.addPoint(m.xform(vec3(min.x, max.y, max.z))); 
     136        result.addPoint(m.xform(max)); 
    58137         
    59138        return result; 
  • trunk/src/gen/model/Mesh.d

    r580 r582  
    1717{ 
    1818    BoundingBox!(float) boundingBox; 
    19  
     19     
    2020    this() 
    2121    { 
     
    2626    { 
    2727        mesh.render(); 
     28    } 
     29 
     30    bool newBoundingBox() 
     31    { 
     32        return false; 
    2833    } 
    2934 
  • trunk/src/gen/model/ModelMD2.d

    r581 r582  
    144144            isAnimating = false; 
    145145        } 
     146         
     147        override bool newBoundingBox() 
     148        { 
     149            return true; 
     150        } 
    146151    } 
    147152     
  • trunk/src/gen/scene/CullNode.d

    r578 r582  
    1111{ 
    1212    BoundingBox!(float) boundingBox; 
     13    vec3 color = vec3.one; 
    1314 
    1415    this(SceneNode parent) 
     
    2728    { 
    2829        visible = camera.frustum.boundingBoxVisible(boundingBox); 
     30        return; 
    2931         
    3032        debug 
     
    3739    debug override void render() 
    3840    { 
    39         renderer.drawBoundingBox(boundingBox, vec3(0.5, 0.5, 0)); 
     41        renderer.drawBoundingBox(boundingBox, color); 
    4042    } 
    4143} 
  • trunk/src/gen/scene/Node.d

    r580 r582  
    141141        if(v == rotation) 
    142142            return; 
    143          
     143 
    144144        _rotation = v; 
    145145        matrixRotation = mat4.zRotation(_rotation.z) * mat4.yRotation(_rotation.y) * mat4.xRotation(_rotation.x); 
  • trunk/src/gen/util/Array.d

    r580 r582  
    139139    void fill(T value, uint x, uint y, uint w, uint h) 
    140140    { 
    141         data[x + y * width .. (x + w) + (y + h) * width] = value; 
     141        //data[x + y * width .. (x + w) + (y + h) * width] = value; 
    142142         
    143         //foreach(ref x; iterate(x, y, w, h)) 
    144         //    x = value; 
     143        foreach(ref x; iterate(x, y, w, h)) 
     144          x = value; 
    145145    } 
    146146     
  • trunk/src/gen/util/File.d

    r535 r582  
    2626void withReadFile(Alloc = DefaultAllocator, T)(char[] path, void delegate(T[]) dg) 
    2727{ 
    28     auto data = readFile(path); 
     28    auto data = readFile!(Alloc)(path); 
    2929    scope(exit) free!(Alloc, ubyte)(data); 
    3030     
  • trunk/src/xf/omg/core/LinearAlgebra.d

    r580 r582  
    512512 
    513513struct Matrix(flt_, int rows_, int cols_) { 
    514   static assert ((rows == cols || rows + 1 == cols) && rows >= 2 && cols <= 4); 
     514//    static assert ((rows == cols || rows + 1 == cols) && rows >= 2 && cols <= 4); 
    515515    const bool isExtended = rows + 1 == cols; 
    516516     
  • trunk/src/xf/omg/util/Meta.d

    r541 r582  
    1616} 
    1717 
     18 
    1819template Repeat(T, int count) { 
    1920    static if (!count) {