public override void Update() { vida.Transform = TGCMatrix.Scaling(10, 10, 10) * new TGCMatrix(body.InterpolationWorldTransform); // vida.Transform = TGCMatrix.Scaling(10, 10, 10) * new TGCMatrix(body.InterpolationWorldTransform); vida.UpdateMeshTransform(); // vida.updateValues(); }
private void eliminarMesh() { TGCVector3 posicionDeBorrado = new TGCVector3(0, -4000, 0); mesh.Move(posicionDeBorrado); mesh.updateBoundingBox(); mesh.UpdateMeshTransform(); }
internal void HuirDe(Personaje personaje, float elapsedTime) { var posicionDeBorrado = new TGCVector3(ghost.Position.X + 2000, ghost.Position.Y, ghost.Position.Z - 5000); ghost.Move(posicionDeBorrado); ghost.updateBoundingBox(); ghost.UpdateMeshTransform(); }
private void eliminarMesh() { TGCVector3 posicionDeBorrado = new TGCVector3(0, -4000, 0); mesh.Move(posicionDeBorrado); mesh.updateBoundingBox(); mesh.UpdateMeshTransform(); //no hago el dispose aca porque sino lo tendria que sacar del TGCScene y no se si quiero hacer eso }
public void renderScene(float elapsedTime, string Technique) { //Dibujamos todos los meshes del escenario /*foreach (TgcMesh m in meshes) * { * m.Effect = effect; * m.Technique = Technique; * m.UpdateMeshTransform(); * m.render(); * }*/ var rnd = new Random(1); pasto.Effect = effect; pasto.Technique = Technique; for (var i = 0; i < 10; ++i) { for (var j = 0; j < 10; ++j) { pasto.Position = new TGCVector3(-i * 200 + rnd.Next(0, 50), 0, -j * 200 + rnd.Next(0, 50)); pasto.Scale = new TGCVector3(3, 4 + rnd.Next(0, 4), 5); pasto.UpdateMeshTransform(); //pasto.Transform = TGCMatrix.Identity*TGCMatrix.Scaling(3, 4 + rnd.Next(0, 4), 5) * TGCMatrix.Translation(-i * 200 + rnd.Next(0, 50), 0, -j * 200 + rnd.Next(0, 50)); pasto.Render(); } } arbusto.Effect = effect; arbusto.Technique = Technique; for (var i = 0; i < 5; ++i) { for (var j = 0; j < 5; ++j) { arbusto.Position = new TGCVector3(-i * 400 + rnd.Next(0, 50), 0, -j * 400 + rnd.Next(0, 50)); //arbusto.Transform = TGCMatrix.Identity*TGCMatrix.Translation(-i * 400 + rnd.Next(0, 50), 0, -j * 400 + rnd.Next(0, 50)); arbusto.UpdateMeshTransform(); arbusto.Render(); } } arbol.Effect = effect; arbol.Technique = Technique; for (var i = 0; i < 3; ++i) { for (var j = 0; j < 3; ++j) { arbol.Position = new TGCVector3(-i * 700 + rnd.Next(0, 50), 0, -j * 700 + rnd.Next(0, 50)); //arbol.Transform = TGCMatrix.Identity*TGCMatrix.Translation(-i * 700 + rnd.Next(0, 50), 0, -j * 700 + rnd.Next(0, 50)); arbol.UpdateMeshTransform(); arbol.Render(); } } }
public void Move(TgcMesh mesh, float movimiento) { moved++; if (moved <= movingRange) { director = new TGCVector3(0, 0, -movimiento); } else { director = new TGCVector3(0, 0, movimiento); } //mesh.Transform = TGCMatrix.Translation(director*100); //mesh.Move(director); var orbitaDeRotacion = 2.5f; //Muevo las plataformas var Mover = TGCMatrix.Translation(0, 0, -10); var Mover2 = TGCMatrix.Translation(0, 0, 65); //Punto por donde va a rotar var Trasladar = TGCMatrix.Translation(0, 0, 10); var Trasladar2 = TGCMatrix.Translation(0, 0, -10); //Aplico la rotacion var Rot = TGCMatrix.RotationX(orbitaDeRotacion); //Giro para que la caja quede derecha var RotInversa = TGCMatrix.RotationX(-orbitaDeRotacion); var transformacionBox = Mover * Trasladar * Rot * Trasladar * RotInversa; //transformacionBox2 = Mover2 * Trasladar2 * RotInversa * Trasladar2 * Rot; mesh.Transform = transformacionBox; mesh.UpdateMeshTransform(); //plataforma1.Update(transformacionBox); //plataforma2.Update(transformacionBox2); if (moved == movingRange * 2) { moved = 0; } }
public override void Render() { PreRender(); //Habilitar luz var lightEnable = (bool)Modifiers["lightEnable"]; Effect currentShader; if (lightEnable) { //Con luz: Cambiar el shader actual por el shader default que trae el framework para iluminacion dinamica con PhongShading currentShader = TgcShaders.Instance.TgcMeshPhongShader; } else { //Sin luz: Restaurar shader default currentShader = TgcShaders.Instance.TgcMeshShader; } //Aplicar al mesh el shader actual mesh.Effect = currentShader; //El Technique depende del tipo RenderType del mesh mesh.Technique = TgcShaders.Instance.getTgcMeshTechnique(mesh.RenderType); //Actualzar posicion de la luz var lightPos = (Vector3)Modifiers["lightPos"]; lightMesh.Position = lightPos; if (lightEnable) { //Cargar variables shader mesh.Effect.SetValue("lightPosition", TgcParserUtils.vector3ToFloat4Array(lightPos)); mesh.Effect.SetValue("eyePosition", TgcParserUtils.vector3ToFloat4Array(Camara.Position)); mesh.Effect.SetValue("ambientColor", ColorValue.FromColor((Color)Modifiers["ambient"])); mesh.Effect.SetValue("diffuseColor", ColorValue.FromColor((Color)Modifiers["diffuse"])); mesh.Effect.SetValue("specularColor", ColorValue.FromColor((Color)Modifiers["specular"])); mesh.Effect.SetValue("specularExp", (float)Modifiers["specularEx"]); } //No hace falta actualizar la matriz de transformacion ya que es un objeto estatico. //Renderizar modelo mesh.render(); lightMesh.UpdateMeshTransform(); //Renderizar mesh de luz lightMesh.render(); PostRender(); }
public override void Render() { PreRender(); //Dibujar todo. //Una vez actualizadas las diferentes posiciones internas solo debemos asignar la matriz de world. mesh.Transform = Matrix.Scaling(mesh.Scale) * Matrix.RotationYawPitchRoll(mesh.Rotation.Y, mesh.Rotation.X, mesh.Rotation.Z) * Matrix.Translation(mesh.Position); mesh.render(); //Actualmente los bounding box se actualizan solos en momento de hacer render, esto no es recomendado ya que trae overhead //Igualmente aqui podemos tener un objeto debug de nuestro mesh. mesh.BoundingBox.render(); box2.Transform = Matrix.Scaling(box2.Scale) * Matrix.RotationYawPitchRoll(box2.Rotation.Y, box2.Rotation.X, box2.Rotation.Z) * Matrix.Translation(box2.Position); box2.render(); //Los bounding volume por la forma actual de framework no realizan transformaciones entonces podemos hacer esto: //D3DDevice.Instance.Device.Transform.World = // Matrix.Scaling(new Vector3(sphere.Radius, sphere.Radius, sphere.Radius)) // * Matrix.Identity //No tienen sentido las rotaciones con la esfera. // * Matrix.Translation(sphere.Position); boundingSphere.render(); //Las mesh por defecto tienen el metodo UpdateMeshTransform que realiza el set por defecto. //Esto es igual que utilizar AutoTransform en true, con lo cual no es recomendado para casos complejos. meshObb.UpdateMeshTransform(); meshObb.render(); //La implementacion de Obb por el momento reconstruye el obb debug siempre. Practica no recomendada. obb.render(); //triangulo D3DDevice.Instance.Device.Transform.World = Matrix.Identity; D3DDevice.Instance.Device.VertexFormat = CustomVertex.PositionColored.Format; D3DDevice.Instance.Device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, triangle); PostRender(); }
public void Render(float elapsedTime) { //A cada mesh hay que aplicarle la matriz de interpolacion de world que se obtiene tras cada frame de simulacion //junto con cada transformacion que necesitemos. sphereMesh.Transform = TGCMatrix.Scaling(10, 10, 10) * new TGCMatrix(pokeball.InterpolationWorldTransform); sphereMesh.Render(); personaje.Transform = TGCMatrix.Scaling(0.5f, 0.5f, 0.5f) * new TGCMatrix(capsuleRigidBody.InterpolationWorldTransform) * TGCMatrix.Translation(new TGCVector3(0, -35, 0)); personaje.animateAndRender(elapsedTime); boxMesh.Transform = new TGCMatrix(box.InterpolationWorldTransform); boxMesh.Render(); boxMeshB.Transform = new TGCMatrix(boxB.InterpolationWorldTransform); boxMeshB.Render(); boxMeshB.Transform = new TGCMatrix(box45.InterpolationWorldTransform); boxMeshB.Render(); boxMeshB.Transform = new TGCMatrix(boxPush.InterpolationWorldTransform); boxMeshB.Render(); foreach (RigidBody peldanio in escalonesRigidBodies) { escalon.Transform = new TGCMatrix(peldanio.InterpolationWorldTransform); escalon.Render(); } columnaMesh.Transform = new TGCMatrix(columnaRigidBody.InterpolationWorldTransform); columnaMesh.Scale = new TGCVector3(1, 1.2f, 1); columnaMesh.UpdateMeshTransform(); columnaMesh.Render(); plataforma.Transform = new TGCMatrix(rigidBodyPlataforma.InterpolationWorldTransform); plataforma.Render(); }
public void Init(string MediaDir) { #region Configuracion Basica de World //Creamos el mundo fisico por defecto. collisionConfiguration = new DefaultCollisionConfiguration(); dispatcher = new CollisionDispatcher(collisionConfiguration); GImpactCollisionAlgorithm.RegisterAlgorithm(dispatcher); constraintSolver = new SequentialImpulseConstraintSolver(); overlappingPairCache = new DbvtBroadphase(); //AxisSweep3(new BsVector3(-5000f, -5000f, -5000f), new BsVector3(5000f, 5000f, 5000f), 8192); dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, constraintSolver, collisionConfiguration); dynamicsWorld.Gravity = new TGCVector3(0, -100f, 0).ToBulletVector3(); #endregion Configuracion Basica de World #region Capsula //Cuerpo rigido de una capsula basica capsuleRigidBody = BulletRigidBodyFactory.Instance.CreateCapsule(10, 50, new TGCVector3(200, 500, 200), 10, false); //Valores que podemos modificar a partir del RigidBody base capsuleRigidBody.SetDamping(0.1f, 0f); capsuleRigidBody.Restitution = 0.1f; capsuleRigidBody.Friction = 1; //Agregamos el RidigBody al World dynamicsWorld.AddRigidBody(capsuleRigidBody); #endregion Capsula #region Terreno //Creamos el RigidBody basico del Terreno var meshRigidBody = BulletRigidBodyFactory.Instance.CreateSurfaceFromHeighMap(triangleDataVB); //Agregamos algo de friccion al RigidBody ya que este va a interactuar con objetos moviles //del World meshRigidBody.Friction = 0.5f; //Agregamos el RigidBody del terreno al World dynamicsWorld.AddRigidBody(meshRigidBody); #endregion Terreno #region Esfera //Creamos una esfera para interactuar pokeball = BulletRigidBodyFactory.Instance.CreateBall(10f, 0.5f, new TGCVector3(100f, 500f, 100f)); pokeball.SetDamping(0.1f, 0.5f); pokeball.Restitution = 1f; //Agregamos la pokebola al World dynamicsWorld.AddRigidBody(pokeball); //Textura de pokebola var texturePokeball = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + @"Texturas\pokeball.jpg"); //Se crea una esfera de tamaño 1 para escalarla luego (en render) sphereMesh = new TGCSphere(1, texturePokeball, TGCVector3.Empty); //Tgc no crea el vertex buffer hasta invocar a update values. sphereMesh.updateValues(); #endregion Esfera #region Personaje //Cargamos personaje var skeletalLoader = new TgcSkeletalLoader(); personaje = skeletalLoader.loadMeshAndAnimationsFromFile( MediaDir + "SkeletalAnimations\\Robot\\Robot-TgcSkeletalMesh.xml", MediaDir + "SkeletalAnimations\\Robot\\", new[] { MediaDir + "SkeletalAnimations\\Robot\\Caminando-TgcSkeletalAnim.xml", MediaDir + "SkeletalAnimations\\Robot\\Parado-TgcSkeletalAnim.xml" }); //Le cambiamos la textura para diferenciarlo un poco personaje.changeDiffuseMaps(new[] { TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "SkeletalAnimations\\Robot\\Textures\\uvwGreen.jpg") }); //Configurar animacion inicial personaje.playAnimation("Parado", true); #endregion Personaje #region Cajas var sizeBox = 20f; //Textura de caja var textureBox = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + @"MeshCreator\Textures\Madera\cajaMadera2.jpg"); box = BulletRigidBodyFactory.Instance.CreateBox(new TGCVector3(sizeBox, sizeBox, sizeBox), 0, new TGCVector3(0, 12, 0), 0, 0, 0, 0.5f, true); dynamicsWorld.AddRigidBody(box); boxMesh = TGCBox.fromSize(new TGCVector3(40f, 40f, 40f), textureBox); boxMesh.updateValues(); sizeBox = 40f; boxB = BulletRigidBodyFactory.Instance.CreateBox(new TGCVector3(sizeBox, sizeBox, sizeBox), 0, new TGCVector3(100, 40, 0), 0, 0, 0, 0.5f, true); dynamicsWorld.AddRigidBody(boxB); boxMeshB = TGCBox.fromSize(new TGCVector3(80f, 80f, 80f), textureBox); boxMeshB.updateValues(); box45 = BulletRigidBodyFactory.Instance.CreateBox(new TGCVector3(sizeBox, sizeBox, sizeBox), 0, new TGCVector3(200, 40, 0), BulletSharp.MathUtil.SIMD_QUARTER_PI, 0, 0, 0.5f, true); dynamicsWorld.AddRigidBody(box45); boxPush = BulletRigidBodyFactory.Instance.CreateBox(new TGCVector3(sizeBox, sizeBox, sizeBox), 0.5f, new TGCVector3(-200, 60, 0), BulletSharp.MathUtil.SIMD_QUARTER_PI, 0, 0, 0.25f, true); dynamicsWorld.AddRigidBody(boxPush); boxMeshPush = TGCBox.fromSize(new TGCVector3(80f, 80f, 80f), textureBox); boxMeshPush.updateValues(); #endregion Cajas #region Escalera var a = 0; var textureStones = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + @"Texturas\stones.bmp"); //la altura de cualquier cubo que quiera subir una capsula debe ser menor a la mitad del radio var size = new TGCVector3(50, 4, 20); escalon = TGCBox.fromSize(size, textureStones); //Se crean 10 escalonescd d while (a < 10) { escalonRigidBody = BulletRigidBodyFactory.Instance.CreateBox(size, 0, new TGCVector3(200, a * 4 + 10, a * 20 + 100), 0, 0, 0, 0.1f, true); escalonesRigidBodies.Add(escalonRigidBody); dynamicsWorld.AddRigidBody(escalonRigidBody); a++; } #endregion Escalera #region Plataforma textureStones = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + @"Texturas\cobblestone_quad.jpg"); rigidBodyPlataforma = BulletRigidBodyFactory.Instance.CreateBox(new TGCVector3(50f, 15f, 50f), 0, new TGCVector3(200, 42.5f, 315), 0, 0, 0, 0.5f, true); dynamicsWorld.AddRigidBody(rigidBodyPlataforma); plataforma = TGCBox.fromSize(new TGCVector3(50f, 15f, 50f), textureStones); plataforma.updateValues(); #endregion Plataforma #region Columna columnaRigidBody = BulletRigidBodyFactory.Instance.CreateCylinder(new TGCVector3(10, 50, 10), new TGCVector3(100, 50, 100), 0); dynamicsWorld.AddRigidBody(columnaRigidBody); var columnaLoader = new TgcSceneLoader(); columnaMesh = columnaLoader.loadSceneFromFile(MediaDir + @"MeshCreator\Meshes\Cimientos\PilarEgipcio\PilarEgipcio-TgcScene.xml", MediaDir + @"MeshCreator\Meshes\Cimientos\PilarEgipcio\").Meshes[0]; columnaMesh.Position = new TGCVector3(100, 7.5f, 100); columnaMesh.UpdateMeshTransform(); #endregion Columna director = new TGCVector3(0, 0, 1); }