public Vertex3 CrossProduct(Vertex3 other) { return(new Vertex3(Y * other.Z - Z * other.Y, Z * other.X - X * other.Z, X * other.Y - Y * other.X)); }
public void Substract(Vertex3 other) { X -= other.X; Y -= other.Y; Z -= other.Z; }
protected override void OnKeyPress(KeyPressEventArgs e) { base.OnKeyPress(e); var lookingDirection = new Vertex3(Camera.LookingPoint.X - Camera.EyePoint.X, Camera.LookingPoint.Y - Camera.EyePoint.Y, Camera.LookingPoint.Z - Camera.EyePoint.Z); lookingDirection = lookingDirection.Normalize(); if (e.KeyChar == 'w') { Camera.EyePoint.Z += lookingDirection.Z; Camera.LookingPoint.Z += lookingDirection.Z; Camera.EyePoint.X += lookingDirection.X; Camera.LookingPoint.X += lookingDirection.X; } else if (e.KeyChar == 's') { Camera.EyePoint.Z -= lookingDirection.Z; Camera.LookingPoint.Z -= lookingDirection.Z; Camera.EyePoint.X -= lookingDirection.X; Camera.LookingPoint.X -= lookingDirection.X; } else if (e.KeyChar == 'a') { Camera.EyePoint.X -= 1; Camera.LookingPoint.X -= 1; } else if (e.KeyChar == 'd') { Camera.EyePoint.X += 1; Camera.LookingPoint.X += 1; } else if (e.KeyChar == 'f') { if (_fogEnabled) { GL.Disable(EnableCap.Fog); _fogEnabled = false; } else { GL.Enable(EnableCap.Fog); _fogEnabled = true; } } else if (e.KeyChar == 'm') { if (_light0Enabled) { GL.Disable(EnableCap.Light0); _light0Enabled = false; } else { GL.Enable(EnableCap.Light0); _light0Enabled = true; } } else if (e.KeyChar == 'k') { if (_light1Enabled) { GL.Disable(EnableCap.Light1); _light1Enabled = false; } else { GL.Enable(EnableCap.Light1); _light1Enabled = true; } } else if (e.KeyChar == 'l') { if (_light2Enabled) { GL.Disable(EnableCap.Light2); _light2Enabled = false; } else { GL.Enable(EnableCap.Light2); _light2Enabled = true; } } }
public void Add(Vertex3 other) { X += other.X; Y += other.Y; Z += other.Z; }
protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.LoadIdentity(); var lookat = Camera.MakeLookingMatrix(); GL.LoadMatrix(ref lookat); GL.PushMatrix(); InitLights(); InitFog(); var minVertex = new Vertex3(-12.0, 0.0, 0.0); var maxVertex = new Vertex3(12.0, 10.0, -23.0); var centerVertex = new Vertex3(); centerVertex.Add(minVertex); centerVertex.Add(maxVertex); centerVertex.Divide(2); GL.PushMatrix(); GL.Translate(centerVertex.X, centerVertex.Y, centerVertex.Z); GL.Scale(maxVertex.X * 0.5 - minVertex.X * 0.5, maxVertex.Y * 0.5 - minVertex.Y * 0.5, maxVertex.Z * 0.5 - minVertex.Z * 0.5); foreach (var obj in RoomModel.Objects.Values) { obj.Render(); } GL.PopMatrix(); GL.PushMatrix(); GL.Translate(0, (SofaModel.MaximumVertex.Y - SofaModel.MinimumVertex.Y) / 2.0, -20); GL.Rotate(90, 0, 1, 0); foreach (var obj in SofaModel.Objects.Values) { obj.Render(); } GL.PopMatrix(); GL.PushMatrix(); GL.Translate(-(SofaModel.MaximumVertex.X - SofaModel.MinimumVertex.X) - (ChairModel.MaximumVertex.X - ChairModel.MinimumVertex.X), (ChairModel.MaximumVertex.Y - ChairModel.MinimumVertex.Y) / 2.0, -20); foreach (var obj in ChairModel.Objects.Values) { obj.Render(); } GL.PopMatrix(); GL.PushMatrix(); GL.Translate((SofaModel.MaximumVertex.X - SofaModel.MinimumVertex.X) + (ChairModel.MaximumVertex.X - ChairModel.MinimumVertex.X), (ChairModel.MaximumVertex.Y - ChairModel.MinimumVertex.Y) / 2.0, -20); foreach (var obj in ChairModel.Objects.Values) { obj.Render(); } GL.PopMatrix(); GL.PushMatrix(); GL.Translate(0, 1.5 * (TvTableModel.MaximumVertex.Y - TvTableModel.MinimumVertex.Y), -5); GL.Scale(3, 3, 2); foreach (var obj in TvTableModel.Objects.Values) { obj.Render(); } GL.PopMatrix(); GL.PushMatrix(); GL.Translate(0, 3 * (TvTableModel.MaximumVertex.Y - TvTableModel.MinimumVertex.Y) + (SonyTvModel.MaximumVertex.Y - SonyTvModel.MinimumVertex.Y) / 2.0, -5); GL.Rotate(90, 0, 1, 0); foreach (var obj in SonyTvModel.Objects.Values) { obj.Render(); } GL.PopMatrix(); GL.PushMatrix(); GL.Translate(-12, (DoorModel.MaximumVertex.Y - DoorModel.MinimumVertex.Y) / 2.0, -15); foreach (var obj in DoorModel.Objects.Values) { obj.Render(); } GL.PopMatrix(); GL.PushMatrix(); GL.Scale(1, 2, 1); GL.Translate(-10, (LampModel.MaximumVertex.Y - LampModel.MinimumVertex.Y) / 2.0, -21); foreach (var obj in LampModel.Objects.Values) { obj.Render(); } GL.PopMatrix(); GL.PushMatrix(); GL.Scale(1, 2, 1); GL.Translate(10, (LampModel.MaximumVertex.Y - LampModel.MinimumVertex.Y) / 2.0, -21); foreach (var obj in LampModel.Objects.Values) { obj.Render(); } GL.PopMatrix(); GL.PushMatrix(); GL.Translate(12, 0, -11); GL.Scale(2, 1.8, 2); GL.Translate(-(PianoModel.MaximumVertex.X - PianoModel.MinimumVertex.X), (PianoModel.MaximumVertex.Y - PianoModel.MinimumVertex.Y) / 2.0, 0); GL.Rotate(180, 0, 1, 0); foreach (var obj in PianoModel.Objects.Values) { obj.Render(); } GL.PopMatrix(); GL.PushMatrix(); GL.Translate(0, (LampModel.MaximumVertex.Y - LampModel.MinimumVertex.Y) / 2.0, -22.7); GL.Translate(0, (SofaModel.MaximumVertex.Y - SofaModel.MinimumVertex.Y), 0); GL.Translate(0, 2, 0); GL.Rotate(-90, 0, 1, 0); foreach (var obj in PaintingModel.Objects.Values) { obj.Render(); } GL.PopMatrix(); SwapBuffers(); }