Changeset 561
- Timestamp:
- 05/23/08 11:12:39 (8 months ago)
- Files:
-
- trunk/src/defend/Camera.d (modified) (9 diffs)
- trunk/src/defend/FogOfWar.d (modified) (5 diffs)
- trunk/src/defend/Graphics.d (modified) (3 diffs)
- trunk/src/defend/demo/Demo.d (modified) (2 diffs)
- trunk/src/defend/game/Game.d (modified) (2 diffs)
- trunk/src/defend/game/hud/MiniMap.d (modified) (4 diffs)
- trunk/src/defend/game/hud/Mouse.d (modified) (3 diffs)
- trunk/src/defend/objects/SceneNode.d (modified) (1 diff)
- trunk/src/defend/terrain/Terrain.d (modified) (3 diffs)
- trunk/src/gen/math/BoundingBox.d (modified) (1 diff)
- trunk/src/gen/rend/opengl/Wrapper.d (modified) (1 diff)
- trunk/src/gen/scene/Node.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/defend/Camera.d
r544 r561 16 16 import gen.util.Wrapper; 17 17 18 import defend.objects.Core; 18 19 import defend.terrain.Patch; 19 20 import defend.terrain.Terrain; … … 27 28 float minDistance = 15; 28 29 30 GameObjectManager gameObjects; 31 29 32 Frustum!(float) _frustum; 30 33 … … 71 74 void inputMoveUp(KeyboardInput input) 72 75 { 76 if(input.mod & KeyboardInput.Modifier.LCtrl) 77 { 78 pitch += inputSpeed(input) * 0.05; 79 return; 80 } 81 73 82 scroll(vec3(0, 0, inputSpeed(input))); 74 83 } … … 76 85 void inputMoveDown(KeyboardInput input) 77 86 { 87 if(input.mod & KeyboardInput.Modifier.LCtrl) 88 { 89 pitch -= inputSpeed(input) * 0.05; 90 return; 91 } 92 78 93 scroll(vec3(0, 0, -inputSpeed(input))); 79 94 } … … 83 98 minDistance -= inputSpeed(input); 84 99 85 if(minDistance < 2.5)86 minDistance = 2.5;100 if(minDistance < 1.1) 101 minDistance = 1.1; 87 102 } 88 103 … … 137 152 return true; 138 153 }); 139 140 154 } 141 155 … … 150 164 151 165 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); 154 168 155 169 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); 161 174 162 175 _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); 169 182 170 183 frustum.create(_modelview, projection); … … 174 187 mixin MAllocator; 175 188 176 this() 177 { 189 this(GameObjectManager gameObjects) 190 { 191 this.gameObjects = gameObjects; 178 192 _frustum = new Frustum!(float); 179 193 … … 195 209 196 210 position = vec3(0, 0, 0); 197 rotate(vec3(-1, 0 .0, 0));211 rotate(vec3(-1, 0, 0)); 198 212 } 199 213 trunk/src/defend/FogOfWar.d
r560 r561 25 25 vec2i dimension; // terrain's dimension 26 26 27 bool enable; 28 27 29 Framebuffer framebuffer; 28 30 Framebuffer visibleBuffer; … … 33 35 Texture circleTexture; 34 36 35 bool f oo;37 bool firstVisited; 36 38 37 39 void updateVisibleTexture() … … 79 81 { 80 82 setFramebuffer(visitedBuffer); 81 83 if(!firstVisited) { clear(); firstVisited = true; } 84 82 85 auto shader = Shader.get("data/shaders/copyVisibleFog.cfg"); 83 86 setShader(shader); … … 163 166 164 167 public: 165 this(GameObjectManager gameObjects, Texture lightmap, vec2i dimension )168 this(GameObjectManager gameObjects, Texture lightmap, vec2i dimension, bool enable = true) 166 169 { 167 170 logger = Log["fogofwar"]; … … 170 173 this.lightmap = lightmap; 171 174 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 } 180 187 } 181 188 182 189 ~this() 183 190 { 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 } 189 199 } 190 200 191 201 Texture texture() 192 202 { 193 return framebuffer.texture;203 return enable ? framebuffer.texture : lightmap; 194 204 } 195 205 } trunk/src/defend/Graphics.d
r560 r561 20 20 import defend.Camera : MainCamera; 21 21 import defend.FogOfWar : FogOfWar; 22 import defend.objects.Core : GameObjectManager; 22 23 import defend.objects.SceneNode : GameObjectMesh; 23 24 … … 52 53 } 53 54 54 void init( )55 void init(GameObjectManager gameObjects) 55 56 { 56 57 // Preallocate objects … … 83 84 } 84 85 85 _mainCamera = new MainCamera ;86 _mainCamera = new MainCamera(gameObjects); 86 87 _mainCamera.projection = mat4.perspective(defendConfig("screen").integer("fov"), 87 88 renderer.config.aspect, 1, 300); trunk/src/defend/demo/Demo.d
r547 r561 63 63 64 64 void init() 65 { 66 graphics = new Graphics; 67 graphics.init(); 68 65 { 69 66 demoPlayer = new DemoPlayer(demoFile); 70 67 demoPlayer.TerrainInformation.connect(&onTerrainInformation); … … 74 71 75 72 gameObjects = new GameObjectManager(demoPlayer, players, simulation); 73 74 graphics = new Graphics; 75 graphics.init(gameObjects); 76 76 77 77 demoPlayer.init(); trunk/src/defend/game/Game.d
r551 r561 243 243 logMemoryUsage(); 244 244 logObjectUsage(); 245 246 // Initialize graphics247 graphics = new Graphics;248 graphics.init();249 245 250 246 logger.info("initializing communication"); … … 259 255 } 260 256 logger.info("communication process finished"); 257 258 // Initialize graphics 259 graphics = new Graphics; 260 graphics.init(gameObjects); 261 261 262 262 // Move the camera to the first object we find trunk/src/defend/game/hud/MiniMap.d
r551 r561 39 39 40 40 renderer.pushMatrix(MatrixType.Projection); 41 renderer.setViewport(Rect(0, 0, width - 1, height - 1));41 renderer.setViewport(Rect(0, 0, width, height)); 42 42 43 43 GLint[4] viewport; … … 78 78 } 79 79 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); 81 81 sprite.scaling = vec2(128.0f / width, 128.0f / width); 82 82 … … 95 95 assert(sprite !is null); 96 96 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); 98 132 } 99 133 100 134 bool pointInside(vec2i pos) 101 135 { 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; 104 138 } 105 139 … … 109 143 assert(pointInside(pos)); 110 144 } 145 out(result) 146 { 147 assert(terrain.within(vec2us.from(result))); 148 } 111 149 body 112 150 { 113 151 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); 114 154 115 return vec2(scale.x / cast(float)width * offset.x, 116 scale.y - scale.y / cast(float)height * offset.y); 155 return result; 117 156 } 118 157 } trunk/src/defend/game/hud/Mouse.d
r551 r561 345 345 { 346 346 auto translated = miniMap.translatePoint(mouse.mousePos, 347 vec2i(terrain.dimension.x, 348 terrain.dimension.y)); 347 vec2i.from(terrain.dimension)); 349 348 350 349 gameObjects.order(gameObjects.gateway, selection, … … 355 354 } 356 355 357 if(overTerrain && selectionBuffer.length && selectionBuffer[0].mayBeOrdered) 356 if(overTerrain && selectionBuffer.length && selectionBuffer[0].mayBeOrdered && 357 mouse.mousePos.y <= renderer.height - HUD_HEIGHT) 358 358 { 359 359 GameObject target; … … 502 502 overTerrain = true; 503 503 504 mouseCube.hide = !overTerrain;504 mouseCube.hide = true; 505 505 506 506 auto pos = terrain.getWorldPos(mapPos); 507 507 508 mouseCube.translation = pos; 508 509 } trunk/src/defend/objects/SceneNode.d
r555 r561 72 72 } 73 73 74 BoundingBox!(float) boundingBox()74 override BoundingBox!(float) boundingBox() 75 75 { 76 76 return bbox; trunk/src/defend/terrain/Terrain.d
r551 r561 167 167 168 168 vec3 normal = getNormalForImage(x, z, size); 169 vec3 col = vec3(.15, 0.2, .3 5) * normal.y; // ambient169 vec3 col = vec3(.15, 0.2, .3) * normal.y; // ambient 170 170 171 171 if(!rayIntersection(ray)) … … 444 444 scope(exit) delete localShader; 445 445 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 446 454 renderer.setShader(localShader); 447 455 … … 450 458 renderer.setTexture(2, diffuseMaps[1]); 451 459 renderer.setTexture(3, diffuseMaps[2]); 452 renderer.setTexture(4, l ightmapTexture);460 renderer.setTexture(4, localLightmap); 453 461 454 462 localShader.setUniform("alphaMap", 0); trunk/src/gen/math/BoundingBox.d
r541 r561 6 6 struct BoundingBox(T) 7 7 { 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; 11 11 12 12 invariant trunk/src/gen/rend/opengl/Wrapper.d
r520 r561 7 7 import derelict.opengl.gl; 8 8 import derelict.opengl.glu; 9 import derelict.opengl.extension.arb.multitexture; 9 10 import derelict.opengl.extension.arb.vertex_buffer_object; 10 11 } trunk/src/gen/scene/Node.d
r541 r561 9 9 import gen.math.Matrix; 10 10 import gen.math.Vector; 11 import gen.math.BoundingBox; 11 12 import gen.scene.Camera; 12 13 import gen.list.TreeList; … … 182 183 183 184 } 185 186 BoundingBox!(float) boundingBox() 187 { 188 BoundingBox!(float) result; 189 return result; 190 } 184 191 185 192 // Render the node
