public override void Draw(GraphicsDevice device, ThreeDScene scene) { if (_isConstructed == false) { ConstructCube(); } var cubeEffect = new BasicEffect(device, null); Vector3 cameraPosition = new Vector3(0, 3, 4); Vector3 modelPosition = Vector3.Zero; float rotation = 0.0f; float aspectRatio = 0.0f; cubeEffect.World = Matrix.CreateRotationY(MathHelper.ToRadians(rotation)) * Matrix.CreateRotationX(MathHelper.ToRadians(rotation)) * Matrix.CreateTranslation(modelPosition); // Set the View matrix which defines the camera and what it's looking at cubeEffect.View = Matrix.CreateLookAt(cameraPosition, modelPosition, Vector3.Up); // Set the Projection matrix which defines how we see the scene (Field of view) cubeEffect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspectRatio, 1.0f, 1000.0f); // Enable textures on the Cube Effect. this is necessary to texture the model cubeEffect.TextureEnabled = true; cubeEffect.Texture = m_Texture; // Enable some pretty lights cubeEffect.EnableDefaultLighting(); using (VertexBuffer buffer = new VertexBuffer( device, typeof(VertexPositionNormalTexture), NUM_VERTICES, BufferUsage.WriteOnly)) { // Load the buffer buffer.SetData(_vertices); // Send the vertex buffer to the device //device.SetVertexBuffer(buffer); device.Vertices[0].SetSource(buffer, 0, VertexPositionNormalTexture.SizeInBytes); device.VertexDeclaration = new VertexDeclaration(device, VertexPositionNormalTexture.VertexElements); } // apply the effect and render the cube foreach (EffectPass pass in cubeEffect.CurrentTechnique.Passes) { pass.Begin(); // Draw the primitives from the vertex buffer to the device as triangles device.DrawPrimitives(PrimitiveType.TriangleList, 0, NUM_TRIANGLES); pass.End(); } }
public override void Draw(GraphicsDevice device, ThreeDScene scene) { if (_isConstructed == false) ConstructCube(); var cubeEffect = new BasicEffect(device, null); Vector3 cameraPosition = new Vector3(0, 3, 4); Vector3 modelPosition = Vector3.Zero; float rotation = 0.0f; float aspectRatio = 0.0f; cubeEffect.World = Matrix.CreateRotationY(MathHelper.ToRadians(rotation)) * Matrix.CreateRotationX(MathHelper.ToRadians(rotation)) * Matrix.CreateTranslation(modelPosition); // Set the View matrix which defines the camera and what it's looking at cubeEffect.View = Matrix.CreateLookAt(cameraPosition, modelPosition, Vector3.Up); // Set the Projection matrix which defines how we see the scene (Field of view) cubeEffect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspectRatio, 1.0f, 1000.0f); // Enable textures on the Cube Effect. this is necessary to texture the model cubeEffect.TextureEnabled = true; cubeEffect.Texture = m_Texture; // Enable some pretty lights cubeEffect.EnableDefaultLighting(); using (VertexBuffer buffer = new VertexBuffer( device, typeof(VertexPositionNormalTexture), NUM_VERTICES, BufferUsage.WriteOnly)) { // Load the buffer buffer.SetData(_vertices); // Send the vertex buffer to the device //device.SetVertexBuffer(buffer); device.Vertices[0].SetSource(buffer, 0, VertexPositionNormalTexture.SizeInBytes); device.VertexDeclaration = new VertexDeclaration(device, VertexPositionNormalTexture.VertexElements); } // apply the effect and render the cube foreach (EffectPass pass in cubeEffect.CurrentTechnique.Passes) { pass.Begin(); // Draw the primitives from the vertex buffer to the device as triangles device.DrawPrimitives(PrimitiveType.TriangleList, 0, NUM_TRIANGLES); pass.End(); } }
public override void Draw(GraphicsDevice device, ThreeDScene scene) { if (m_Sim == null) { return; } device.VertexDeclaration = new VertexDeclaration(device, VertexPositionNormalTexture.VertexElements); var world = World; foreach (var effect in m_Effects) { effect.World = world; effect.View = scene.Camera.View; effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.Pi / 4.0f, (float)device.PresentationParameters.BackBufferWidth / (float)device.PresentationParameters.BackBufferHeight, 1.0f, 100.0f); effect.Projection = scene.Camera.Projection; effect.Texture = m_Sim.HeadTexture; effect.TextureEnabled = true; effect.CommitChanges(); effect.Begin(); foreach (var pass in effect.CurrentTechnique.Passes) { pass.Begin(); foreach (Face Fce in m_Sim.HeadMesh.FaceData) { if (m_Sim.HeadMesh.VertexTexNormalPositions != null) { VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3]; Vertex[0] = m_Sim.HeadMesh.VertexTexNormalPositions[Fce.VertexA]; Vertex[1] = m_Sim.HeadMesh.VertexTexNormalPositions[Fce.VertexB]; Vertex[2] = m_Sim.HeadMesh.VertexTexNormalPositions[Fce.VertexC]; Vertex[0].TextureCoordinate = m_Sim.HeadMesh.VertexTexNormalPositions[Fce.VertexA].TextureCoordinate; Vertex[1].TextureCoordinate = m_Sim.HeadMesh.VertexTexNormalPositions[Fce.VertexB].TextureCoordinate; Vertex[2].TextureCoordinate = m_Sim.HeadMesh.VertexTexNormalPositions[Fce.VertexC].TextureCoordinate; GameFacade.GraphicsDevice.DrawUserPrimitives <VertexPositionNormalTexture>(PrimitiveType.TriangleList, Vertex, 0, 1); } } pass.End(); } effect.End(); } }
private List <TreeNode> ExploreScene(ThreeDScene container) { var result = new List <TreeNode>(); foreach (var child in container.GetElements()) { var node = new TreeNode(child.ToString()); ItemMap.Add(node, child); result.Add(node); } return(result); }
public CoreGameScreen() { ucp = new UIUCP(); ucp.Y = ScreenHeight - 210; this.Add(ucp); gizmo = new UIGizmo(); gizmo.X = ScreenWidth - 500; gizmo.Y = ScreenHeight - 300; this.Add(gizmo); ///** City Scene **/ var scene = new ThreeDScene(); //scene.Camera.Position = new Vector3(0, -14.1759f, 10f); scene.Camera.Position = new Vector3(0, 0, 17.0f); scene.Camera.Target = Vector3.Zero; scene.Camera.Up = Vector3.Up; ////, new Vector3(0, 0, 0), Vector3.Up var city = new CitySceneElement(); city.Initialize(); //city.RotationX = (float)MathUtils.DegreeToRadian(347); //city.Scale = new Vector3(1.24f); scene.Camera.Target = new Vector3( ((city.City.Width * city.Geom.CellWidth) / 2), -((city.City.Height * city.Geom.CellHeight) / 2), 0.0f); scene.Camera.Position = Vector3.Transform( new Vector3( scene.Camera.Target.X, scene.Camera.Target.Y, city.City.Width / GameFacade.GraphicsDevice.Viewport.Width), Microsoft.Xna.Framework.Matrix.CreateRotationY((float)MathUtils.DegreeToRadian(-200))); scene.Add(city); GameFacade.Scenes.AddScene(scene); }
public override void Draw(GraphicsDevice device, ThreeDScene scene) { var camera = new Camera(new Vector3(0, -14.1759f, 10f), new Vector3(0, 0, 0), Vector3.Up); var gd = GameFacade.GraphicsDevice; gd.VertexDeclaration = new VertexDeclaration(gd, TerrainVertex.VertexElements); effect.CurrentTechnique = effect.Techniques["TerrainSplat"]; if (zoomedIn) { effect.Parameters["xTextureBlend"].SetValue(TextureBlend); effect.Parameters["xTextureTerrain"].SetValue(TextureTerrain); } else { effect.Parameters["xTextureGrass"].SetValue(TextureGrass); effect.Parameters["xTextureSnow"].SetValue(TextureSnow); effect.Parameters["xTextureSand"].SetValue(TextureSand); effect.Parameters["xTextureRock"].SetValue(TextureRock); effect.Parameters["xTextureWater"].SetValue(TextureWater); } //; //var worldMatrix = Matrix.Identity * Matrix.CreateTranslation(transX, 0, transY) * Matrix.CreateScale(zoom) * Matrix.CreateRotationX(MathHelper.ToRadians(degs)); effect.Parameters["xWorld"].SetValue(World); effect.Parameters["xView"].SetValue(scene.Camera.View); effect.Parameters["xProjection"].SetValue(GameFacade.Scenes.ProjectionMatrix); effect.Parameters["xEnableLighting"].SetValue(true); effect.Parameters["xAmbient"].SetValue(0.8f); effect.Parameters["xLightDirection"].SetValue(lightDirection); effect.CommitChanges(); //GraphicsDevice.BlendState = BlendState.Opaque; effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); Geom.Draw(gd); pass.End(); } effect.End(); }
public UISim() { SimRender = new SimRenderer(); SimRender.ID = "SimRender"; SimScene = new ThreeDScene(); SimScene.ID = "SimScene"; SimScene.Camera = new Camera(Vector3.Backward * ViewScale, Vector3.Zero, Vector3.Right); SimScene.Add(SimRender); //GameFacade.Scenes.AddScene(SimScene); /** Default settings **/ SimRender.Scale = new Vector3(0.6f); SimRender.RotationY = (float)MathUtils.DegreeToRadian(25); SimRender.RotationX = (float)MathUtils.DegreeToRadian(RotationStartAngle); // //var scene = new TSOClient.ThreeD.ThreeDScene(); //scene.Add(a); GameFacade.Scenes.AddExternalScene(SimScene); }
private void SetSelectedScene(ThreeDScene scene) { if (scene == null) { tabCamera.Enabled = false; return; } tabCamera.Enabled = true; SelectedScene = null; cameraX.Value = (decimal)scene.Camera.Position.X; cameraY.Value = (decimal)scene.Camera.Position.Y; cameraZ.Value = (decimal)scene.Camera.Position.Z; cameraTargetX.Value = (decimal)scene.Camera.Target.X; cameraTargetY.Value = (decimal)scene.Camera.Target.Y; cameraTargetZ.Value = (decimal)scene.Camera.Target.Z; SelectedScene = scene; }
private void SetupGUI() { menuStrip1 = new System.Windows.Forms.MenuStrip(); fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); closeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); TopPanel = new System.Windows.Forms.Panel(); ThreeDPanel = new System.Windows.Forms.Panel(); textBox1 = new System.Windows.Forms.TextBox(); MainElementHost = new System.Windows.Forms.Integration.ElementHost(); ViewPort = new Viewport3D(); InitializeGuiComponents(); Scene = new ThreeDScene(MForm); MainElementHost.Child = ViewPort; ViewPort.Children.Clear(); ViewPort.Children.Add(Scene.GetMainModelVisual3D()); ViewPort.Camera = Scene.GetCamera(); // Scene.RefFrame.MakeNewGeometryModels(); Scene.SolarS.MakeNewGeometryModels(); }
public override void Draw(GraphicsDevice device, ThreeDScene scene) { if (m_Sim == null) { return; } device.VertexDeclaration = new VertexDeclaration(device, VertexPositionNormalTexture.VertexElements); var world = World;// *Matrix.CreateRotationX(m_Rotation); foreach (var effect in m_Effects) { effect.World = world;//GameFacade.Scenes.WorldMatrix * Matrix.CreateScale(3.0f);// *Microsoft.Xna.Framework.Matrix.CreateTranslation( // new Microsoft.Xna.Framework.Vector3(m_Sim.HeadXPos, m_Sim.HeadYPos, 0.0f)); effect.View = scene.Camera.View; //effect.Projection = GameFacade.Scenes.ProjectionMatrix; effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.Pi / 4.0f, (float)device.PresentationParameters.BackBufferWidth / (float)device.PresentationParameters.BackBufferHeight, 1.0f, 100.0f); //var aspect = GameFacade.GraphicsDevice.Viewport.AspectRatio; /*var ratioX = 1024.0f / 1024.0f; * var ratioY = 10.0f / 768.0f; * var projectionX = 0.0f - (1.0f * ratioX); * var projectionY = 0.0f - (1.0f * ratioY); * effect.Projection = Matrix.CreatePerspectiveOffCenter(projectionX, projectionX + 1.0f, (projectionY / aspect), (projectionY+1.0f) / aspect, 1.0f, 100.0f); */ effect.Projection = scene.Camera.Projection; effect.Texture = m_Sim.HeadTexture; effect.TextureEnabled = true; //effect.EnableDefaultLighting(); //foreach (var technique in effect.Techniques) //{ // effect.CurrentTechnique = technique; effect.CommitChanges(); effect.Begin(); foreach (var pass in effect.CurrentTechnique.Passes) { pass.Begin(); foreach (Face Fce in m_Sim.HeadMesh.Faces) { if (m_Sim.HeadMesh.VertexTexNormalPositions != null) { VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3]; Vertex[0] = m_Sim.HeadMesh.VertexTexNormalPositions[Fce.AVertexIndex]; Vertex[1] = m_Sim.HeadMesh.VertexTexNormalPositions[Fce.BVertexIndex]; Vertex[2] = m_Sim.HeadMesh.VertexTexNormalPositions[Fce.CVertexIndex]; Vertex[0].TextureCoordinate = m_Sim.HeadMesh.VertexTexNormalPositions[Fce.AVertexIndex].TextureCoordinate; Vertex[1].TextureCoordinate = m_Sim.HeadMesh.VertexTexNormalPositions[Fce.BVertexIndex].TextureCoordinate; Vertex[2].TextureCoordinate = m_Sim.HeadMesh.VertexTexNormalPositions[Fce.CVertexIndex].TextureCoordinate; GameFacade.GraphicsDevice.DrawUserPrimitives <VertexPositionNormalTexture>(PrimitiveType.TriangleList, Vertex, 0, 1); } } pass.End(); } effect.End(); } }
public override void Draw(GraphicsDevice device, ThreeDScene scene) { if (m_Sim == null) { return; } if (!m_IsInvalidated) { device.VertexDeclaration = new VertexDeclaration(device, VertexPositionNormalTexture.VertexElements); device.RenderState.CullMode = CullMode.None; var world = World; foreach (var effect in m_Effects) { effect.World = world; effect.View = scene.Camera.View; effect.Projection = scene.Camera.Projection; /** Head **/ foreach (var binding in m_Sim.HeadBindings) { effect.Texture = binding.Texture; effect.TextureEnabled = true; effect.CommitChanges(); effect.Begin(); foreach (var pass in effect.CurrentTechnique.Passes) { pass.Begin(); binding.Mesh.Draw(device); pass.End(); } effect.End(); } foreach (var binding in m_Sim.BodyBindings) { effect.Texture = binding.Texture; effect.TextureEnabled = true; effect.CommitChanges(); effect.Begin(); foreach (var pass in effect.CurrentTechnique.Passes) { pass.Begin(); binding.Mesh.Draw(device); pass.End(); } effect.End(); } //Only draw idle bindings for now... foreach (var binding in m_Sim.LeftHandBindings.IdleBindings) { effect.Texture = binding.Texture; effect.TextureEnabled = true; effect.CommitChanges(); effect.Begin(); foreach (var pass in effect.CurrentTechnique.Passes) { pass.Begin(); binding.Mesh.Draw(device); pass.End(); } effect.End(); } foreach (var binding in m_Sim.RightHandBindings.IdleBindings) { effect.Texture = binding.Texture; effect.TextureEnabled = true; effect.CommitChanges(); effect.Begin(); foreach (var pass in effect.CurrentTechnique.Passes) { pass.Begin(); binding.Mesh.Draw(device); pass.End(); } effect.End(); } } } }