public override void draw(Graphics graphics, Camera camera, WorldLights worldLights) { if (Settings.debug) { distanceToCamera = (float)camera.Position.getMagnitude(); Matrix4 ModelViewProjection = camera.Frustum * camera.View * StaticMatrices.UniformScaleMatrix(scale); renderVertices = GameShapes.UnitAxes(); foreach (Vector4D vertex in renderVertices) { vertex.LeftMultiply(ModelViewProjection); if (Math.Abs(vertex.Z) < Math.Abs(vertex.W)) { vertex.divideByW(); vertex.moveOriginToCenterScreen(); } } PointF[] pointsAll = renderVertices.Select(x => x.getPointXY()).ToArray(); graphics.DrawLine(new Pen(Color.Cyan), pointsAll[0], pointsAll[1]); graphics.DrawLine(new Pen(Color.Magenta), pointsAll[0], pointsAll[2]); graphics.DrawLine(new Pen(Color.Yellow), pointsAll[0], pointsAll[3]); } }
/// <summary> /// For now, the whole game is initialized right here in the construcor. All it needs is a GDI graphics object. /// </summary> #region Constructor public GameHub(Graphics g) { /// New gadget I'm trying out to prevent repeat toggle key presses for pause and debug mode without causing pauses in engines. toggleKeyRepeatPreventer = new ToggleKeyRepeatPreventer(); toggleKeyRepeatPreventer.registerNewToggleKey('p'); toggleKeyRepeatPreventer.registerNewToggleKey('b'); Utilities.findScreenEdges(); System.Windows.Forms.Cursor.Hide(); /// Makes the games camera. Use an FPSCamera for walking or a FreeCamera for space ship like controls camera = new FreeCamera(new Vector4D(500, 20, -60, 1)); /// The WorldLights struct holds all of the lights for the game world. It is given to the graphics engine. lights = new WorldLights(); lights.AmbientLights = new AmbientLight[] { new AmbientLight(10, 10, 10) }; lights.DirectionalLights = new DirectionalLight[] { /*new DirectionalLight(new Vector3D(0, 1, 0), 0, 100, 0)*/ }; lights.PointLights = new PointLight[] { new PointLight(new Vector3D(100, 100, -200), 60000, 100, 170, 240, camera), new PointLight(new Vector3D(500, -100, 100), 30000, 200, 90, 210, camera) }; origin = new Origin(50); graphics = new GraphicsEngineGDI(16, g, camera, lights); physics = new PhysicsEngine(16); graphics.Initialize(); physics.Initialize(); testObjs = new GameEntity[128]; for (int i = 0; i < 128; i++) { testObjs[i] = new GameObject (i * 4 + 8, (i * 20) % 100, 8, // Position x, y, z, 0, 0, 0, // Velocity x, y, z, 0, 0, 0, // Rotation x, y, z, 10, 10, 10, // Scale x, y, z, GameShapes.UnitCubeGDI(), 10); // Mesh, Radius } /// Put our test cubes into the graphics engine for depth-sorted rendering graphics.addObjectsToRenderZSorted(testObjs.ToList()); graphics.addObjectToRenderZSorted(origin); graphics.addObjectToRenderZSorted(lights.PointLights[0]); graphics.addObjectToRenderZSorted(lights.PointLights[1]); /// User input is processed by the physics engine right now. physics.addControlRoutine(ParseInput); /// Put our test cubes into the physics engine. physics.addObjectsToMove(testObjs); }
public override void draw(Graphics graphics, Camera camera, WorldLights worldLights) { if (Settings.debug) { Vector4D centerVector = Vector4D.Zero(); centerVector.LeftMultiply(StaticMatrices.TranslationMatrix(position)); centerVector.LeftMultiply(camera.View); distanceToCamera = (float)centerVector.getMagnitude(); centerVector.LeftMultiply(camera.Frustum); centerVector.divideByW(); centerVector.moveOriginToCenterScreen(); Matrix4 mat = camera.Frustum * camera.View * StaticMatrices.TranslationMatrix(position) * StaticMatrices.ScaleMatrix(new Vector3D(intensity * .0005, intensity * .0005, intensity * .0005)); Vector4D[] vertices = GameShapes.Tetrahedron(); for (int i = 0; i < 4; i++) { vertices[i].LeftMultiply(mat); vertices[i].divideByW(); vertices[i].moveOriginToCenterScreen(); } PointF[] pointsAll = vertices.Select(x => x.getPointXY()).ToArray(); graphics.DrawLine(new Pen(Color.FromArgb((int)red, (int)green, (int)blue), 2), pointsAll[0], pointsAll[1]); graphics.DrawLine(new Pen(Color.FromArgb((int)red, (int)green, (int)blue), 2), pointsAll[0], pointsAll[2]); graphics.DrawLine(new Pen(Color.FromArgb((int)red, (int)green, (int)blue), 2), pointsAll[0], pointsAll[3]); graphics.DrawLine(new Pen(Color.FromArgb((int)red, (int)green, (int)blue), 2), pointsAll[1], pointsAll[2]); graphics.DrawLine(new Pen(Color.FromArgb((int)red, (int)green, (int)blue), 2), pointsAll[1], pointsAll[3]); graphics.DrawLine(new Pen(Color.FromArgb((int)red, (int)green, (int)blue), 2), pointsAll[2], pointsAll[3]); graphics.DrawString((intensity * .001).ToString() + "K", new Font("Arial", 12), new SolidBrush(Color.White), centerVector.getPointXY()); } }
public Origin(double scale) { this.scale = scale; renderVertices = GameShapes.UnitAxes(); distanceToCamera = 0; }
public override void reset() { axes = GameShapes.CameraAxes(); }
public FreeCamera(Vector4D position) : base(position) { axes = GameShapes.CameraAxes(); }