public override void render(float elapsedTime) { Device d3dDevice = GuiController.Instance.D3dDevice; //Obtener rotacion de mesh (pasar a radianes) float rotation = FastMath.ToRad((float)GuiController.Instance.Modifiers["rotation"]); //Rotar mesh y rotar OBB. A diferencia del AABB, nosotros tenemos que mantener el OBB actualizado segun cada movimiento del mesh Vector3 lastRot = mesh.Rotation; float rotationDiff = rotation - lastRot.Y; mesh.rotateY(rotationDiff); obb.rotate(new Vector3(0, rotationDiff, 0)); //Actualizar posicion Vector3 position = (Vector3)GuiController.Instance.Modifiers["position"]; Vector3 lastPos = mesh.Position; Vector3 posDiff = position - lastPos; mesh.move(posDiff); obb.move(posDiff); //Renderizar modelo mesh.render(); //Renderizar obb obb.render(); }
public override void init() { Microsoft.DirectX.Direct3D.Device d3dDevice = GuiController.Instance.D3dDevice; //Cuerpo principal que se controla con el teclado box = TgcBox.fromSize(new Vector3(0, 10, 0), new Vector3(10, 10, 10), Color.Blue); //triangulo triangle = new CustomVertex.PositionColored[3]; triangle[0] = new CustomVertex.PositionColored(-100, 0, 0, Color.Red.ToArgb()); triangle[1] = new CustomVertex.PositionColored(0, 0, 50, Color.Green.ToArgb()); triangle[2] = new CustomVertex.PositionColored(0, 100, 0, Color.Blue.ToArgb()); triagleAABB = TgcBoundingBox.computeFromPoints(new Vector3[] { triangle[0].Position, triangle[1].Position, triangle[2].Position }); //box2 box2 = TgcBox.fromSize(new Vector3(-50, 10, -20), new Vector3(15, 15, 15), Color.Violet); //sphere sphere = new TgcBoundingSphere(new Vector3(30, 20, -20), 15); //OBB: computar OBB a partir del AABB del mesh. TgcSceneLoader loader = new TgcSceneLoader(); TgcMesh meshObb = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Meshes\\Vehiculos\\StarWars-ATST\\StarWars-ATST-TgcScene.xml").Meshes[0]; obb = TgcObb.computeFromAABB(meshObb.BoundingBox); meshObb.dispose(); obb.move(new Vector3(100, 0, 30)); obb.setRotation(new Vector3(0, FastMath.PI / 4, 0)); //Configurar camara en Tercer Persona GuiController.Instance.ThirdPersonCamera.Enable = true; GuiController.Instance.ThirdPersonCamera.setCamera(box.Position, 30, -75); }
public override void Render() { PreRender(); //Obtener rotacion de mesh (pasar a radianes) var rotation = FastMath.ToRad((float)Modifiers["rotation"]); //Rotar mesh y rotar OBB. A diferencia del AABB, nosotros tenemos que mantener el OBB actualizado segun cada movimiento del mesh var lastRot = mesh.Rotation; var rotationDiff = rotation - lastRot.Y; mesh.rotateY(rotationDiff); obb.rotate(new Vector3(0, rotationDiff, 0)); //Actualizar posicion var position = (Vector3)Modifiers["position"]; var lastPos = mesh.Position; var posDiff = position - lastPos; mesh.move(posDiff); obb.move(posDiff); //Renderizar modelo mesh.render(); //Renderizar obb obb.render(); PostRender(); }
public override void Init() { //Cuerpo principal que se controla con el teclado box = TgcBox.fromSize(new Vector3(0, 10, 0), new Vector3(10, 10, 10), Color.Blue); //triangulo triangle = new CustomVertex.PositionColored[3]; triangle[0] = new CustomVertex.PositionColored(-100, 0, 0, Color.Red.ToArgb()); triangle[1] = new CustomVertex.PositionColored(0, 0, 50, Color.Green.ToArgb()); triangle[2] = new CustomVertex.PositionColored(0, 100, 0, Color.Blue.ToArgb()); triagleAABB = TgcBoundingBox.computeFromPoints(new[] { triangle[0].Position, triangle[1].Position, triangle[2].Position }); //box2 box2 = TgcBox.fromSize(new Vector3(-50, 10, -20), new Vector3(15, 15, 15), Color.Violet); //sphere sphere = new TgcBoundingSphere(new Vector3(30, 20, -20), 15); //OBB: computar OBB a partir del AABB del mesh. var loader = new TgcSceneLoader(); var meshObb = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Meshes\\Vehiculos\\StarWars-ATST\\StarWars-ATST-TgcScene.xml") .Meshes[0]; obb = TgcObb.computeFromAABB(meshObb.BoundingBox); meshObb.dispose(); obb.move(new Vector3(100, 0, 30)); obb.setRotation(new Vector3(0, FastMath.PI / 4, 0)); //Configurar camara en Tercer Persona camaraInterna = new TgcThirdPersonCamera(box.Position, 30, -75); Camara = camaraInterna; }