Changeset 561

Show
Ignore:
Timestamp:
05/23/08 11:12:39 (8 months ago)
Author:
LeoD
Message:

fogging the minimap

Files:

Legend:

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

    r544 r561  
    1616import gen.util.Wrapper; 
    1717 
     18import defend.objects.Core; 
    1819import defend.terrain.Patch; 
    1920import defend.terrain.Terrain; 
     
    2728    float minDistance = 15; 
    2829 
     30    GameObjectManager gameObjects; 
     31 
    2932    Frustum!(float) _frustum; 
    3033     
     
    7174    void inputMoveUp(KeyboardInput input) 
    7275    { 
     76        if(input.mod & KeyboardInput.Modifier.LCtrl) 
     77        { 
     78            pitch += inputSpeed(input) * 0.05; 
     79            return; 
     80        } 
     81     
    7382        scroll(vec3(0, 0, inputSpeed(input))); 
    7483    } 
     
    7685    void inputMoveDown(KeyboardInput input) 
    7786    { 
     87        if(input.mod & KeyboardInput.Modifier.LCtrl) 
     88        { 
     89            pitch -= inputSpeed(input) * 0.05; 
     90            return; 
     91        } 
     92     
    7893        scroll(vec3(0, 0, -inputSpeed(input))); 
    7994    } 
     
    8398        minDistance -= inputSpeed(input); 
    8499 
    85         if(minDistance < 2.5
    86             minDistance = 2.5
     100        if(minDistance < 1.1
     101            minDistance = 1.1
    87102    } 
    88103 
     
    137152            return true; 
    138153        }); 
    139  
    140154    } 
    141155 
     
    150164 
    151165        right = vec3(cosyaw * cosroll + sinyaw * sinpitch * 
    152                       sinroll, sinroll * cospitch, 
    153                       cosyaw * sinpitch * sinroll - sinyaw * cosroll); 
     166                    sinroll, sinroll * cospitch, 
     167                    cosyaw * sinpitch * sinroll - sinyaw * cosroll); 
    154168 
    155169        up = vec3(sinyaw * sinpitch * cosroll - cosyaw * sinroll, 
    156                    cosroll * cospitch, 
    157                    sinroll * sinyaw + cosroll * cosyaw * sinpitch); 
    158  
    159         dir = vec3(cospitch * sinyaw, -sinpitch, 
    160                     cospitch * cosyaw); 
     170                  cosroll * cospitch, 
     171                  sinroll * sinyaw + cosroll * cosyaw * sinpitch); 
     172 
     173        dir = vec3(cospitch * sinyaw, -sinpitch, cospitch * cosyaw); 
    161174 
    162175        _modelview = createMat4(right.x, up.x, dir.x, 0.0, 
    163                            right.y, up.y, dir.y, 0.0, 
    164                            right.z, up.z, dir.z, 0.0, 
    165                            -(vec3.dot(pos, right)), 
    166                            -(vec3.dot(pos, up)), 
    167                            -(vec3.dot(pos, dir)), 
    168                            1.0); 
     176                                right.y, up.y, dir.y, 0.0, 
     177                                right.z, up.z, dir.z, 0.0, 
     178                                -(vec3.dot(pos, right)), 
     179                                -(vec3.dot(pos, up)), 
     180                                -(vec3.dot(pos, dir)), 
     181                                1.0); 
    169182         
    170183        frustum.create(_modelview, projection); 
     
    174187    mixin MAllocator; 
    175188 
    176     this() 
    177     { 
     189    this(GameObjectManager gameObjects) 
     190    { 
     191        this.gameObjects = gameObjects; 
    178192        _frustum = new Frustum!(float); 
    179193 
     
    195209 
    196210        position = vec3(0, 0, 0); 
    197         rotate(vec3(-1, 0.0, 0)); 
     211        rotate(vec3(-1, 0, 0)); 
    198212    } 
    199213 
  • trunk/src/defend/FogOfWar.d

    r560 r561  
    2525    vec2i dimension; // terrain's dimension 
    2626     
     27    bool enable; 
     28     
    2729    Framebuffer framebuffer; 
    2830    Framebuffer visibleBuffer; 
     
    3335    Texture circleTexture; 
    3436 
    35     bool foo
     37    bool firstVisited
    3638 
    3739    void updateVisibleTexture() 
     
    7981        { 
    8082            setFramebuffer(visitedBuffer); 
    81  
     83            if(!firstVisited) { clear(); firstVisited = true; } 
     84     
    8285            auto shader = Shader.get("data/shaders/copyVisibleFog.cfg"); 
    8386            setShader(shader); 
     
    163166 
    164167public: 
    165     this(GameObjectManager gameObjects, Texture lightmap, vec2i dimension
     168    this(GameObjectManager gameObjects, Texture lightmap, vec2i dimension, bool enable = true
    166169    { 
    167170        logger = Log["fogofwar"]; 
     
    170173        this.lightmap = lightmap; 
    171174        this.dimension = dimension; 
    172          
    173         framebuffer = renderer.createFramebuffer(lightmap.dimension); 
    174         visibleBuffer = renderer.createFramebuffer(lightmap.dimension); 
    175         visitedBuffer = renderer.createFramebuffer(lightmap.dimension); 
    176         circleTexture = generateCircle(); 
    177         sprite = new Sprite(lightmap.dimension, true); 
    178          
    179         taskManager.addRepeatedTask(&update, 15); 
     175        this.enable = enable; 
     176         
     177        if(enable) 
     178        { 
     179            framebuffer = renderer.createFramebuffer(lightmap.dimension); 
     180            visibleBuffer = renderer.createFramebuffer(lightmap.dimension); 
     181            visitedBuffer = renderer.createFramebuffer(lightmap.dimension); 
     182            circleTexture = generateCircle(); 
     183            sprite = new Sprite(lightmap.dimension, true); 
     184             
     185            taskManager.addRepeatedTask(&update, 15); 
     186        } 
    180187    } 
    181188     
    182189    ~this() 
    183190    { 
    184         delete framebuffer; 
    185         delete visibleBuffer; 
    186         delete visitedBuffer; 
    187         delete circleTexture; 
    188         delete sprite; 
     191        if(enable) 
     192        { 
     193            delete framebuffer; 
     194            delete visibleBuffer; 
     195            delete visitedBuffer; 
     196            delete circleTexture; 
     197            delete sprite; 
     198        } 
    189199    } 
    190200 
    191201    Texture texture() 
    192202    { 
    193         return framebuffer.texture
     203        return enable ? framebuffer.texture : lightmap
    194204    } 
    195205} 
  • trunk/src/defend/Graphics.d

    r560 r561  
    2020import defend.Camera : MainCamera; 
    2121import defend.FogOfWar : FogOfWar; 
     22import defend.objects.Core : GameObjectManager; 
    2223import defend.objects.SceneNode : GameObjectMesh; 
    2324 
     
    5253    } 
    5354     
    54     void init(
     55    void init(GameObjectManager gameObjects
    5556    {    
    5657        // Preallocate objects 
     
    8384        } 
    8485         
    85         _mainCamera = new MainCamera
     86        _mainCamera = new MainCamera(gameObjects)
    8687        _mainCamera.projection = mat4.perspective(defendConfig("screen").integer("fov"), 
    8788                                                  renderer.config.aspect, 1, 300); 
  • trunk/src/defend/demo/Demo.d

    r547 r561  
    6363 
    6464    void init() 
    65     { 
    66         graphics = new Graphics; 
    67         graphics.init(); 
    68      
     65    {    
    6966        demoPlayer = new DemoPlayer(demoFile); 
    7067        demoPlayer.TerrainInformation.connect(&onTerrainInformation); 
     
    7471         
    7572        gameObjects = new GameObjectManager(demoPlayer, players, simulation); 
     73 
     74        graphics = new Graphics; 
     75        graphics.init(gameObjects); 
    7676 
    7777        demoPlayer.init(); 
  • trunk/src/defend/game/Game.d

    r551 r561  
    243243        logMemoryUsage(); 
    244244        logObjectUsage(); 
    245          
    246         // Initialize graphics 
    247         graphics = new Graphics; 
    248         graphics.init(); 
    249245 
    250246        logger.info("initializing communication"); 
     
    259255        } 
    260256        logger.info("communication process finished"); 
     257 
     258        // Initialize graphics 
     259        graphics = new Graphics; 
     260        graphics.init(gameObjects); 
    261261 
    262262        // Move the camera to the first object we find 
  • trunk/src/defend/game/hud/MiniMap.d

    r551 r561  
    3939 
    4040        renderer.pushMatrix(MatrixType.Projection); 
    41         renderer.setViewport(Rect(0, 0, width - 1, height - 1)); 
     41        renderer.setViewport(Rect(0, 0, width, height)); 
    4242 
    4343        GLint[4] viewport; 
     
    7878        } 
    7979         
    80         sprite = new Sprite(fogOfWar.texture, Rect(0, 0, width - 1, height - 1), true); 
     80        sprite = new Sprite(texture, Rect(0, 0, width - 1, height - 1), true); 
    8181        sprite.scaling = vec2(128.0f / width, 128.0f / width); 
    8282         
     
    9595        assert(sprite !is null); 
    9696 
    97         sprite.render(position); 
     97        renderer.setRenderState(RenderState.Blending, true); 
     98 
     99        renderer.setTexture(0, texture); 
     100        renderer.setTexture(1, fogOfWar.texture); 
     101         
     102        for(uint i = 0; i < 2; i++) 
     103        { 
     104            if(i == 1) renderer.setBlendFunc(BlendFunc.One, BlendFunc.One); 
     105         
     106            // TODO: don't use GL directly... D: 
     107            glBegin(GL_QUADS); 
     108            glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1); 
     109            glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0, 1); 
     110            glVertex3f(position.x, position.y, 0); 
     111            glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1); 
     112            glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1, 1); 
     113            glVertex3f(position.x + width, position.y, 0); 
     114            glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0); 
     115            glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1, 0); 
     116            glVertex3f(position.x + width, position.y + height, 0); 
     117            glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0); 
     118            glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0, 0); 
     119            glVertex3f(position.x, position.y + height, 0); 
     120            glEnd(); 
     121        } 
     122         
     123        renderer.setTexture(0, null); 
     124        renderer.setTexture(1, null); 
     125 
     126        /+sprite.render(position); 
     127         
     128        renderer.setBlendFunc(BlendFunc.DstColor, BlendFunc.OneMinusDstColor); 
     129        sprite.render(position, fogOfWar.texture);+/ 
     130         
     131        renderer.setRenderState(RenderState.Blending, false); 
    98132    } 
    99133     
    100134    bool pointInside(vec2i pos) 
    101135    { 
    102         return pos.x >= position.x && pos.x <= position.x + width && 
    103                pos.y >= position.y && pos.y <= position.y + height; 
     136        return pos.x >= position.x && pos.x < position.x + width && 
     137               pos.y >= position.y && pos.y < position.y + height; 
    104138    } 
    105139     
     
    109143        assert(pointInside(pos)); 
    110144    } 
     145    out(result) 
     146    { 
     147        assert(terrain.within(vec2us.from(result))); 
     148    } 
    111149    body 
    112150    { 
    113151        auto offset = pos - position; 
     152        auto result = vec2(scale.x / cast(float)width * offset.x, 
     153                           scale.y - scale.y / cast(float)height * offset.y); 
    114154         
    115         return vec2(scale.x / cast(float)width * offset.x, 
    116                     scale.y - scale.y / cast(float)height * offset.y); 
     155        return result; 
    117156    } 
    118157} 
  • trunk/src/defend/game/hud/Mouse.d

    r551 r561  
    345345            { 
    346346                auto translated = miniMap.translatePoint(mouse.mousePos, 
    347                                                          vec2i(terrain.dimension.x, 
    348                                                                terrain.dimension.y)); 
     347                                                         vec2i.from(terrain.dimension)); 
    349348                                                            
    350349                gameObjects.order(gameObjects.gateway, selection, 
     
    355354            } 
    356355 
    357             if(overTerrain && selectionBuffer.length && selectionBuffer[0].mayBeOrdered) 
     356            if(overTerrain && selectionBuffer.length && selectionBuffer[0].mayBeOrdered && 
     357               mouse.mousePos.y <= renderer.height - HUD_HEIGHT) 
    358358            { 
    359359                GameObject target; 
     
    502502            overTerrain = true; 
    503503 
    504         mouseCube.hide = !overTerrain
     504        mouseCube.hide = true
    505505 
    506506        auto pos = terrain.getWorldPos(mapPos); 
     507         
    507508        mouseCube.translation = pos; 
    508509    } 
  • trunk/src/defend/objects/SceneNode.d

    r555 r561  
    7272    } 
    7373     
    74     BoundingBox!(float) boundingBox() 
     74    override BoundingBox!(float) boundingBox() 
    7575    { 
    7676        return bbox; 
  • trunk/src/defend/terrain/Terrain.d

    r551 r561  
    167167                 
    168168                vec3 normal = getNormalForImage(x, z, size); 
    169                 vec3 col = vec3(.15, 0.2, .35) * normal.y; // ambient 
     169                vec3 col = vec3(.15, 0.2, .3) * normal.y; // ambient 
    170170                 
    171171                if(!rayIntersection(ray)) 
     
    444444        scope(exit) delete localShader; 
    445445     
     446        scope lightmapImage = new Image(lightmapTexture.dimension.x, lightmapTexture.dimension.y); 
     447        for(uint x = 0; x < lightmapTexture.dimension.x; x++) 
     448            for(uint y = 0; y < lightmapTexture.dimension.y; y++) 
     449                lightmapImage.setRGB(x, y, 128, 128, 128); 
     450     
     451        auto localLightmap = renderer.createTexture(lightmapImage); 
     452        scope(exit) delete localLightmap; 
     453     
    446454        renderer.setShader(localShader); 
    447455 
     
    450458        renderer.setTexture(2, diffuseMaps[1]); 
    451459        renderer.setTexture(3, diffuseMaps[2]); 
    452         renderer.setTexture(4, lightmapTexture); 
     460        renderer.setTexture(4, localLightmap); 
    453461         
    454462        localShader.setUniform("alphaMap", 0); 
  • trunk/src/gen/math/BoundingBox.d

    r541 r561  
    66struct BoundingBox(T) 
    77{ 
    8     Vec3!(T) min; //= Vec3!(T)( 10_000); 
    9     Vec3!(T) max; //= Vec3!(T)(-10_000); 
    10     Vec3!(T) center
     8    Vec3!(T) min = Vec3!(T).zero; //= Vec3!(T)( 10_000); 
     9    Vec3!(T) max = Vec3!(T).zero; //= Vec3!(T)(-10_000); 
     10    Vec3!(T) center = Vec3!(T).zero
    1111     
    1212    invariant 
  • trunk/src/gen/rend/opengl/Wrapper.d

    r520 r561  
    77    import derelict.opengl.gl; 
    88    import derelict.opengl.glu; 
     9    import derelict.opengl.extension.arb.multitexture; 
    910    import derelict.opengl.extension.arb.vertex_buffer_object; 
    1011} 
  • trunk/src/gen/scene/Node.d

    r541 r561  
    99import gen.math.Matrix; 
    1010import gen.math.Vector; 
     11import gen.math.BoundingBox; 
    1112import gen.scene.Camera; 
    1213import gen.list.TreeList; 
     
    182183         
    183184    } 
     185     
     186    BoundingBox!(float) boundingBox() 
     187    { 
     188        BoundingBox!(float) result; 
     189        return result; 
     190    } 
    184191 
    185192    // Render the node