public virtual void Draw(Matrix currentViewMatrix, Matrix projectionMatrix, Vector3 cameraPosition) { Matrix worldMatrix = GetWorldMatrix(); LODMap.GetRenderer().DrawModel(this.model, this.texture, this.IsTransparant, this.CanPlace, this.HasMouseFocus, this.GetWorldMatrix(), currentViewMatrix, projectionMatrix, cameraPosition, "Textured"); if (ShowBoundingBox) { DrawBoundingBox(currentViewMatrix, cameraPosition); } }
public void AdjustCameraAltitude(GameTime gameTime) { float intendedCameraHeight = 0; if (DoFixedAltitude) { intendedCameraHeight = 75; } else { // keeps camera at a set height above the terrain. //double intendedCameraHeight = (worldMap.getCellHeightFromWorldCoor(this.GetCameraPostion().X, -this.GetCameraPostion().Z)) + Camera.CameraHeightOffset; intendedCameraHeight = (LODMap.getCellHeightFromWorldCoor(this.GetCameraPostion().X, this.GetCameraPostion().Z)) + Camera.CameraHeightOffset; } // int intendedCameraHeight = worldMap.getAltitude(cameraPosition.X, cameraPosition.Z) + CameraHeightOffset; //if (intendedCameraHeight < (WorldMap.waterHeight + CameraHeightOffset)) if (intendedCameraHeight < (LODTerrain.LODTerrain.waterHeight + CameraHeightOffset)) { // intendedCameraHeight = WorldMap.waterHeight + CameraHeightOffset; intendedCameraHeight = LODTerrain.LODTerrain.waterHeight + CameraHeightOffset; } if (this.cameraHeight < intendedCameraHeight) { this.cameraHeight += (float)(riseSpeed * gameTime.ElapsedGameTime.TotalSeconds); if (this.cameraHeight > intendedCameraHeight) { this.cameraHeight = intendedCameraHeight; } } else if (this.cameraHeight > intendedCameraHeight) { this.cameraHeight -= (float)(dropSpeed * gameTime.ElapsedGameTime.TotalSeconds); if (this.cameraHeight < intendedCameraHeight) { this.cameraHeight = intendedCameraHeight; } } }
public void UpdateViewMatrix() { Matrix cameraRotation = Matrix.CreateRotationX(this.updownRot) * Matrix.CreateRotationY(this.leftrightRot); //Matrix cameraRotation = Matrix.CreateRotationX(-MathHelper.Pi/6) * Matrix.CreateRotationY(leftrightRot); Vector3 cameraOriginalTarget = new Vector3(0, 0, -1); // here Vector3 cameraOriginalUpVector = new Vector3(0, 1, 0); Vector3 cameraRotatedTarget = Vector3.Transform(cameraOriginalTarget, cameraRotation); Vector3 cameraFinalTarget = this.GetCameraPostion() + cameraRotatedTarget; LookAt = cameraRotatedTarget; // cameraFinalTarget; Vector3 cameraRotatedUpVector = Vector3.Transform(cameraOriginalUpVector, cameraRotation); this.viewMatrix = Matrix.CreateLookAt(this.GetCameraPostion(), cameraFinalTarget, cameraRotatedUpVector); Vector3 rotatedVector = Vector3.Transform(new Vector3(0, -1, 0), cameraRotation); // this.viewMatrixBackShifted = Matrix.CreateLookAt(this.GetCameraPostion() + 100 * rotatedVector, cameraFinalTarget, cameraRotatedUpVector); this.viewMatrixBackShifted = Matrix.CreateLookAt(this.GetPointBehindCamera(100), cameraFinalTarget, cameraRotatedUpVector); Vector3 reflCameraPosition = this.GetCameraPostion(); //flCameraPosition.Y = -this.GetCameraPostion().Y + (WorldMap.waterHeight * 2); reflCameraPosition.Y = -this.GetCameraPostion().Y + (LODTerrain.LODTerrain.waterHeight * 2); Vector3 reflTargetPos = cameraFinalTarget; //reflTargetPos.Y = -cameraFinalTarget.Y + (WorldMap.waterHeight * 2); reflTargetPos.Y = -cameraFinalTarget.Y + (LODTerrain.LODTerrain.waterHeight * 2); Vector3 forwardVector = reflTargetPos - reflCameraPosition; sideVector = Vector3.Transform(new Vector3(1, 0, 0), cameraRotation); Vector3 reflectionCamUp = Vector3.Cross(sideVector, forwardVector); //worldMap.GetRenderer().reflectionViewMatrix = Matrix.CreateLookAt(reflCameraPosition, reflTargetPos, reflectionCamUp); LODMap.GetRenderer().reflectionViewMatrix = Matrix.CreateLookAt(reflCameraPosition, reflTargetPos, reflectionCamUp); }
public void AddToCameraPosition(Vector3 vectorToAdd) { Matrix cameraRotation = Matrix.CreateRotationX(0) * Matrix.CreateRotationY(leftrightRot); Vector3 rotatedVector = Vector3.Transform(vectorToAdd, cameraRotation); MoveCamera(GetCameraPostion() + moveSpeed * rotatedVector); float camX = GetCameraPostion().X; float camZ = GetCameraPostion().Z; if (camX < 0) { camX = 0; } //if (camX > (worldMap.getMapWidth())) { camX = (worldMap.getMapWidth()); } if (camX > (LODMap.getMapWidth())) { camX = (LODMap.getMapWidth()); } /* * if (camZ > 0) { camZ = 0; } * //if (camZ < -((worldMap.getMapHeight()) - 1)) { camZ = -((worldMap.getMapHeight()) - 1); } * if (camZ < -((LODMap.getMapHeight()) - 1)) { camZ = -((LODMap.getMapHeight()) - 1); } */ if (camZ < 0) { camZ = 0; } if (camZ > ((LODMap.getMapHeight()) - 1)) { camZ = ((LODMap.getMapHeight()) - 1); } MoveCamera(new Vector3(camX, (float)cameraHeight, camZ)); UpdateViewMatrix(); }
public virtual void DrawShadow(Matrix currentViewMatrix, Matrix projectionMatrix, Vector3 cameraPosition) { Matrix worldMatrix = GetWorldMatrix(); LODMap.GetRenderer().DrawShadow(this.model, this.GetWorldMatrix(), currentViewMatrix, projectionMatrix, "Textured"); }