private void MedioBarrelRoll(TgcD3dInput input, float ElapsedTime) { if (input.keyPressed(Key.B) && ESTADO_BARREL.NADA.Equals(estadoBarrel)) { estadoBarrel = ESTADO_BARREL.MEDIO_BARRELROLL; medioBarrelRollTimer = 0; } if (ESTADO_BARREL.MEDIO_BARRELROLL.Equals(estadoBarrel)) { barrelRollAdvance += ElapsedTime * 4; matrizInicialTransformacion = TGCMatrix.RotationYawPitchRoll(0, barrelRollAdvance, 0); if (barrelRollAdvance >= FastMath.PI_HALF) { estadoBarrel = ESTADO_BARREL.ESPERA_MEDIO_BARRELROLL; } } if (ESTADO_BARREL.ESPERA_MEDIO_BARRELROLL.Equals(estadoBarrel)) { medioBarrelRollTimer += ElapsedTime; if (medioBarrelRollTimer >= tiempoPermanenciaMedioBarrelRoll) { estadoBarrel = ESTADO_BARREL.VOLVIENDO_MEDIO_BARRELROLL; } } if (ESTADO_BARREL.VOLVIENDO_MEDIO_BARRELROLL.Equals(estadoBarrel)) { barrelRollAdvance -= ElapsedTime * 4; if (barrelRollAdvance <= 0) { barrelRollAdvance = 0; estadoBarrel = ESTADO_BARREL.NADA; } matrizInicialTransformacion = TGCMatrix.RotationYawPitchRoll(0, barrelRollAdvance, 0); } }
public override void Render() { //BackgroundColor D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); BeginScene(); ClearTextures(); //Cargar variables shader mesh.Effect.SetValue("ambientColor", ColorValue.FromColor(Color.Gray)); mesh.Effect.SetValue("diffuseColor", ColorValue.FromColor(Color.LightBlue)); mesh.Effect.SetValue("specularColor", ColorValue.FromColor(Color.White)); mesh.Effect.SetValue("specularExp", 10f); mesh.Effect.SetValue("lightPosition", lightPos); mesh.Effect.SetValue("eyePosition", TGCVector3.Vector3ToFloat4Array(Camara.Position)); mesh.RotateY(-ElapsedTime / 2); mesh.Transform = TGCMatrix.Scaling(mesh.Scale) * TGCMatrix.RotationYawPitchRoll(mesh.Rotation.Y, mesh.Rotation.X, mesh.Rotation.Z) * TGCMatrix.Translation(mesh.Position); mesh.Render(); textHelp.render(); //Help if (Input.keyPressed(Key.H)) { helpForm.ShowDialog(); } PostRender(); }
public override void Init() { //El framework posee la clase TgcSceneLoader que permite cargar modelos 3D. //Estos modelos 3D están almacenados en un archivo XML llamado TgcScene.xml. //Este archivo es un formato a medida hecho para el framework. Y puede ser creado desde herramientas de //diseño como 3Ds MAX (exportando a traves de un plugin) o con el editor MeshCreator que viene con el framework. //El framework viene con varios modelos 3D incluidos en la carpeta: TgcViewer\Examples\Media\MeshCreator\Meshes. //El formato especifica una escena, representada por la clase TgcScene. Una escena puede estar compuesta por varios //modelos 3D. Cada modelo se representa con la clase TgcMesh. //En este ejemplo vamos a cargar una escena con un único modelo. var loader = new TgcSceneLoader(); //De toda la escena solo nos interesa guardarnos el primer modelo (el único que hay en este caso). mesh = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Meshes\\Vehiculos\\Hummer\\Hummer-TgcScene.xml").Meshes[0]; mesh.Position += new TGCVector3(100, 37, -200); mesh.Rotation += new TGCVector3(0, FastMath.QUARTER_PI, 0); mesh.Transform = TGCMatrix.Scaling(TGCVector3.One) * TGCMatrix.RotationYawPitchRoll(mesh.Rotation.Y, mesh.Rotation.X, mesh.Rotation.Z) * TGCMatrix.Translation(mesh.Position); //En este ejemplo no cargamos un solo modelo 3D sino una escena completa, compuesta por varios modelos. //El framework posee varias escenas ya hechas en la carpeta TgcViewer\Examples\Media\MeshCreator\Scenes. scene = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Scenes\\Iglesia\\Iglesia-TgcScene.xml"); //Hacemos que la cámara esté centrada sobre el mesh. Camera = new TgcRotationalCamera(mesh.BoundingBox.calculateBoxCenter(), mesh.BoundingBox.calculateBoxRadius() * 6, Input); }
public XwingEnemigo(TGCVector3 posicionInicial, Xwing target, float velocidadInicial, CoordenadaEsferica direccionInicial) { posicion = posicionInicial; velocidadGeneral = velocidadInicial; //Por defecto, se encuentra mirando hacia el z+ this.coordenadaEsferica = direccionInicial; nave = new TgcSceneLoader().loadSceneFromFile(VariablesGlobales.mediaDir + "XWing\\X-Wing-TgcScene.xml");//@ésta deberia ser nuestra nave, no la enemiga! nave.Meshes.ForEach(mesh => { mesh.AutoTransformEnable = false; mesh.Transform = TGCMatrix.Scaling(scale) * TGCMatrix.RotationYawPitchRoll(coordenadaEsferica.GetRotation().Y, coordenadaEsferica.GetRotation().X, coordenadaEsferica.GetRotation().Z) * TGCMatrix.Translation(posicion); //Shader if (VariablesGlobales.SHADERS) { Effect shader = VariablesGlobales.shaderManager.AskForEffect(ShaderManager.MESH_TYPE.SHADOW); if (shader != null) { nave.Meshes.ForEach(m => m.Effect = shader); } VariablesGlobales.shaderManager.AddObject(this); } }); this.target = target; //Calcula inicialmente en que direccion esta el xwing principal vectorDistancia = CommonHelper.SumarVectores(target.GetPosition(), -posicion); coordenadaAXwing = new CoordenadaEsferica(vectorDistancia.X, vectorDistancia.Y, vectorDistancia.Z); }
/// <summary> /// Se crea uncuerpo rigido a partir de un TgcMesh, pero no tiene masa por lo que va a ser estatico. /// </summary> /// <param name="mesh">TgcMesh</param> /// <returns>Cuerpo rigido de un Mesh</returns> public RigidBody CreateRigidBodyFromTgcMesh(TgcMesh mesh) { var vertexCoords = mesh.getVertexPositions(); TriangleMesh triangleMesh = new TriangleMesh(); for (int i = 0; i < vertexCoords.Length; i = i + 3) { triangleMesh.AddTriangle(vertexCoords[i].ToBulletVector3(), vertexCoords[i + 1].ToBulletVector3(), vertexCoords[i + 2].ToBulletVector3()); } var transformationMatrix = TGCMatrix.RotationYawPitchRoll(0, 0, 0).ToBsMatrix; DefaultMotionState motionState = new DefaultMotionState(transformationMatrix); var bulletShape = new BvhTriangleMeshShape(triangleMesh, false); var boxLocalInertia = bulletShape.CalculateLocalInertia(0); var bodyInfo = new RigidBodyConstructionInfo(0, motionState, bulletShape, boxLocalInertia); var rigidBody = new RigidBody(bodyInfo); rigidBody.Friction = 0.4f; rigidBody.RollingFriction = 1; rigidBody.Restitution = 1f; return(rigidBody); }
public override void Render() { PreRender(); gui_render(ElapsedTime); if (profiling) { Device device = D3DDevice.Instance.Device; Viewport ant_view = device.Viewport; Viewport view = new Viewport(); view.X = (int)(400 * gui.ex); view.Y = (int)(100 * gui.ey); view.Width = (int)(400 * gui.ex); view.Height = (int)(300 * gui.ey); view.MinZ = 0; view.MaxZ = 1; device.Viewport = view; mesh.Transform = TGCMatrix.Scaling(mesh.Scale) * TGCMatrix.RotationYawPitchRoll(mesh.Rotation.Y, mesh.Rotation.X, mesh.Rotation.Z) * TGCMatrix.Translation(mesh.Position); mesh.Render(); device.Viewport = ant_view; } PostRender(); }
public override void Render() { PreRender(); //FIX IT SOLO CON COLISION. if (selecting) { selectionBox.BoundingBox.Render(); } //Render suelo.Render(); foreach (var mesh in modelos) { mesh.Transform = TGCMatrix.Scaling(mesh.Scale) * TGCMatrix.RotationYawPitchRoll(mesh.Rotation.Y, mesh.Rotation.X, mesh.Rotation.Z) * TGCMatrix.Translation(mesh.Position); mesh.Render(); } //Renderizar BB de los modelos seleccionados foreach (var mesh in modelosSeleccionados) { mesh.BoundingBox.Render(); } PostRender(); }
public static RigidBody CreateRigidBodyFromTgcMesh(TgcMesh mesh, TGCVector3 position, float mass, float friction) { var meshAxisRadius = mesh.BoundingBox.calculateAxisRadius().ToBsVector; var boxShape = new BoxShape(meshAxisRadius); var transformationMatrix = TGCMatrix.RotationYawPitchRoll(0, 0, 0).ToBsMatrix; transformationMatrix.Origin = position.ToBsVector; DefaultMotionState motionState = new DefaultMotionState(transformationMatrix); var boxLocalInertia = boxShape.CalculateLocalInertia(mass); var bodyInfo = new RigidBodyConstructionInfo(mass, motionState, boxShape, boxLocalInertia); var rigidBody = new RigidBody(bodyInfo) { LinearFactor = TGCVector3.One.ToBsVector, Friction = friction, RollingFriction = 1f, AngularFactor = new Vector3(1f, 0.2f, 1f), SpinningFriction = 0.7f }; return(rigidBody); }
public override void Update() { PreUpdate(); this.handleInput(); this.time += ElapsedTime; this.sphere.Transform = TGCMatrix.Scaling(this.scale) * TGCMatrix.RotationYawPitchRoll(this.rotation, 0, 0) * TGCMatrix.Translation(this.center); this.updateEffectVector(); this.effect.SetValue("time", this.time); TGCVector3 centeredEffectVector = this.effectVector - this.center; this.effect.SetValue("effectVector", new[] { centeredEffectVector.X, centeredEffectVector.Y, centeredEffectVector.Z }); this.effect.SetValue("factor", (float)Math.Round(sumValue, 2)); this.effect.SetValue("matViewProj", D3DDevice.Instance.Device.Transform.View * D3DDevice.Instance.Device.Transform.Projection); this.effect.SetValue("eyePosition", new[] { this.Camara.Position.X, this.Camara.Position.Y, this.Camara.Position.Z }); PostUpdate(); }
/// <summary> /// Se llama cada vez que hay que refrescar la pantalla. /// Escribir aquí todo el código referido al renderizado. /// Borrar todo lo que no haga falta. /// </summary> public override void Render() { //Inicio el render de la escena, para ejemplos simples. Cuando tenemos postprocesado o shaders es mejor realizar las operaciones según nuestra conveniencia. PreRender(); //Dibuja un texto por pantalla DrawText.drawText("Con la tecla F se dibuja el bounding box.", 0, 20, Color.OrangeRed); DrawText.drawText("Con clic izquierdo subimos la camara [Actual]: " + TGCVector3.PrintTGCVector3(Camera.Position), 0, 30, Color.OrangeRed); //Siempre antes de renderizar el modelo necesitamos actualizar la matriz de transformacion. //Debemos recordar el orden en cual debemos multiplicar las matrices, en caso de tener modelos jerárquicos, tenemos control total. Box.Transform = TGCMatrix.Scaling(Box.Scale) * TGCMatrix.RotationYawPitchRoll(Box.Rotation.Y, Box.Rotation.X, Box.Rotation.Z) * TGCMatrix.Translation(Box.Position); //A modo ejemplo realizamos toda las multiplicaciones, pero aquí solo nos hacia falta la traslación. //Finalmente invocamos al render de la caja Box.Render(); //Cuando tenemos modelos mesh podemos utilizar un método que hace la matriz de transformación estándar. //Es útil cuando tenemos transformaciones simples, pero OJO cuando tenemos transformaciones jerárquicas o complicadas. Mesh.UpdateMeshTransform(); //Render del mesh Mesh.Render(); //Render de BoundingBox, muy útil para debug de colisiones. if (BoundingBox) { Box.BoundingBox.Render(); Mesh.BoundingBox.Render(); } //Finaliza el render y presenta en pantalla, al igual que el preRender se debe para casos puntuales es mejor utilizar a mano las operaciones de EndScene y PresentScene PostRender(); }
public static TGCMatrix rotacionEntreVectores(TGCVector3 v1, TGCVector3 v2) { float rotationY = OperationsWithVectors.anguloEntreVectores(new TGCVector3(v1.X, 0, v1.Z), new TGCVector3(v2.X, 0, v2.Z)); float rotationX = OperationsWithVectors.anguloEntreVectores(new TGCVector3(0, v1.Y, v1.Z), new TGCVector3(0, v2.Y, v2.Z)); float rotationZ = OperationsWithVectors.anguloEntreVectores(new TGCVector3(v1.X, v1.Y, 0), new TGCVector3(v2.X, v2.Y, 0)); return(TGCMatrix.RotationYawPitchRoll(rotationY, rotationX, rotationZ)); }
public TransformationMatrix ReturnSame(TransformationMatrix m) { TransformationMatrix theReturn = new TransformationMatrix(); theReturn.SetTranslation(m.GetTranslation() * TGCMatrix.Translation(new TGCVector3(0, 0, 0))); theReturn.SetScalation(m.GetScalation() * TGCMatrix.Scaling(new TGCVector3(1, 1, 1))); theReturn.SetRotation(m.GetRotation() * TGCMatrix.RotationYawPitchRoll(0, 0, 0)); return(theReturn); }
private void Moverse() { posicion = CommonHelper.MoverPosicionEnDireccionCoordenadaEsferica(posicion, coordenadaEsferica, velocidadGeneral, VariablesGlobales.elapsedTime); nave.Meshes.ForEach(mesh => { mesh.Transform = TGCMatrix.Scaling(scale) * TGCMatrix.RotationYawPitchRoll(coordenadaEsferica.GetRotation().Y, coordenadaEsferica.GetRotation().X, coordenadaEsferica.GetRotation().Z) * TGCMatrix.Translation(posicion); }); }
private void Posicionar() { TGCMatrix rotationTranslation = TGCMatrix.RotationYawPitchRoll(rotation.Y, 0, 0) * TGCMatrix.Translation(posicion); obstaculo.Transform = TGCMatrix.Scaling(scaleVector) * rotationTranslation; collisionObject = VariablesGlobales.physicsEngine.AgregarObstaculo(this, obstaculo.BoundingBox.calculateSize()); collisionObject.CollisionShape.LocalScaling = scaleVector.ToBulletVector3(); collisionObject.WorldTransform = CommonHelper.TgcToBulletMatrix(rotationTranslation); }
public TGCMatrix GenerateTransformation(TGCVector3 escala, TGCVector3 rotacion, TGCVector3 traslado) { TGCMatrix matrixEscalado = TGCMatrix.Scaling(escala); TGCMatrix matrixRotacion = TGCMatrix.RotationYawPitchRoll(rotacion.Y, rotacion.X, rotacion.Z); TGCMatrix matrixTraslacion = TGCMatrix.Translation(traslado); TGCMatrix transformacion = matrixEscalado * matrixRotacion * matrixTraslacion; return(transformacion); }
public override void setRotationFromPivot(TGCVector3 rotation, TGCVector3 pivot) { mesh.Rotation = rotation; var translation = pivot - mesh.Position; var m = TGCMatrix.Translation(-translation) * TGCMatrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z) * TGCMatrix.Translation(translation); mesh.Move(new TGCVector3(m.M41, m.M42, m.M43)); }
/// <summary> /// Cargar la rotacion absoluta del OBB. /// Pierda la rotacion anterior. /// </summary> /// <param name="rotation">Ángulo de rotación de cada eje en radianes</param> public void setRotation(TGCVector3 rotation) { var rotM = TGCMatrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z); orientation[0] = new TGCVector3(rotM.M11, rotM.M12, rotM.M13); orientation[1] = new TGCVector3(rotM.M21, rotM.M22, rotM.M23); orientation[2] = new TGCVector3(rotM.M31, rotM.M32, rotM.M33); dirtyValues = true; }
/// <summary> /// Convierte el box en un TgcMesh /// </summary> /// <param name="meshName">Nombre de la malla que se va a crear</param> public TgcMesh ToMesh(string meshName) { //Obtener matriz para transformar vertices if (AutoTransformEnable) { Transform = TGCMatrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z) * TGCMatrix.Translation(translation); } return(TgcMesh.FromTGCBox(meshName, this.Texture, this.vertices, this.Transform, this.AlphaBlendEnable)); }
public void TeletrasportarmeA(TGCVector3 posicionActual) { meshPersonaje.Position = posicionActual; meshPersonaje.updateBoundingBox(); meshPersonaje.Transform = TGCMatrix.Scaling(meshPersonaje.Scale) * TGCMatrix.RotationYawPitchRoll(meshPersonaje.Rotation.Y, meshPersonaje.Rotation.X, meshPersonaje.Rotation.Z) * TGCMatrix.Translation(meshPersonaje.Position); this.Position = meshPersonaje.Position; }
public override void Init(BulletExampleWall ctx) { base.Init(ctx); //Creamos shapes y bodies. //El piso es un plano estatico se dice que si tiene masa 0 es estatico. var floorShape = new StaticPlaneShape(TGCVector3.Up.ToBulletVector3(), 0); var floorMotionState = new DefaultMotionState(); var floorInfo = new RigidBodyConstructionInfo(0, floorMotionState, floorShape); floorBody = new RigidBody(floorInfo); dynamicsWorld.AddRigidBody(floorBody); //Se crea una caja de tamaño 20 con rotaciones y origien en 10,100,10 y 1kg de masa. var boxShape = new BoxShape(10, 10, 10); var boxTransform = TGCMatrix.RotationYawPitchRoll(MathUtil.SIMD_HALF_PI, MathUtil.SIMD_QUARTER_PI, MathUtil.SIMD_2_PI).ToBsMatrix; boxTransform.Origin = new TGCVector3(10, 100, 10).ToBulletVector3(); DefaultMotionState boxMotionState = new DefaultMotionState(boxTransform); //Es importante calcular la inercia caso contrario el objeto no rotara. var boxLocalInertia = boxShape.CalculateLocalInertia(1f); var boxInfo = new RigidBodyConstructionInfo(1f, boxMotionState, boxShape, boxLocalInertia); boxBody = new RigidBody(boxInfo); dynamicsWorld.AddRigidBody(boxBody); //Crea una bola de radio 10 origen 50 de 1 kg. var ballShape = new SphereShape(10); var ballTransform = TGCMatrix.Identity; ballTransform.Origin = new TGCVector3(0, 50, 0); var ballMotionState = new DefaultMotionState(ballTransform.ToBsMatrix); //Podriamos no calcular la inercia para que no rote, pero es correcto que rote tambien. var ballLocalInertia = ballShape.CalculateLocalInertia(1f); var ballInfo = new RigidBodyConstructionInfo(1, ballMotionState, ballShape, ballLocalInertia); ballBody = new RigidBody(ballInfo); dynamicsWorld.AddRigidBody(ballBody); //Cargamos objetos de render del framework. var floorTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, Ctx.MediaDir + @"Texturas\granito.jpg"); floorMesh = new TgcPlane(new TGCVector3(-200, 0, -200), new TGCVector3(400, 0f, 400), TgcPlane.Orientations.XZplane, floorTexture); var texture = TgcTexture.createTexture(D3DDevice.Instance.Device, Ctx.MediaDir + @"Texturas\madera.jpg"); //Es importante crear todos los mesh con centro en el 0,0,0 y que este coincida con el centro de masa definido caso contrario rotaria de otra forma diferente a la dada por el motor de fisica. boxMesh = TGCBox.fromSize(new TGCVector3(20, 20, 20), texture); //Se crea una esfera de tamaño 1 para escalarla luego (en render) sphereMesh = new TGCSphere(1, texture.Clone(), TGCVector3.Empty); //Tgc no crea el vertex buffer hasta invocar a update values. sphereMesh.updateValues(); }
/// <summary> /// Aplicar transformaciones del mesh /// </summary> protected void updateMeshTransform() { //Aplicar transformacion de malla if (AutoTransformEnable) { Transform = TGCMatrix.Identity * TGCMatrix.Scaling(scale) * TGCMatrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z) * TGCMatrix.Translation(translation); } }
private void CreateMesh(string pathToMesh) { TgcSceneLoader loader = new TgcSceneLoader(); TgcScene scene = loader.loadSceneFromFile(pathToMesh); this.mesh = scene.Meshes[0]; this.mesh.AutoTransform = false; this.rotation = TGCMatrix.RotationYawPitchRoll(0, 0, 0); this.escalade = TGCMatrix.Scaling(new TGCVector3(0.2f, 0.2f, 0.2f)); this.traslation = TGCMatrix.Translation(0, 0, 0); }
/// <summary> /// Transformar fisicamente los vertices del mesh segun su transformacion actual /// </summary> private void applyMeshTransformToVertices(TgcMesh m) { //Transformacion actual var transform = TGCMatrix.Scaling(m.Scale) * TGCMatrix.RotationYawPitchRoll(m.Rotation.Y, m.Rotation.X, m.Rotation.Z) * TGCMatrix.Translation(m.Position); switch (m.RenderType) { case TgcMesh.MeshRenderType.VERTEX_COLOR: var verts1 = (TgcSceneLoader.VertexColorVertex[])m.D3dMesh.LockVertexBuffer( typeof(TgcSceneLoader.VertexColorVertex), LockFlags.ReadOnly, m.D3dMesh.NumberVertices); for (var i = 0; i < verts1.Length; i++) { verts1[i].Position = TGCVector3.transform(verts1[i].Position, transform); } m.D3dMesh.SetVertexBufferData(verts1, LockFlags.None); m.D3dMesh.UnlockVertexBuffer(); break; case TgcMesh.MeshRenderType.DIFFUSE_MAP: var verts2 = (TgcSceneLoader.DiffuseMapVertex[])m.D3dMesh.LockVertexBuffer( typeof(TgcSceneLoader.DiffuseMapVertex), LockFlags.ReadOnly, m.D3dMesh.NumberVertices); for (var i = 0; i < verts2.Length; i++) { verts2[i].Position = TGCVector3.transform(verts2[i].Position, transform); } m.D3dMesh.SetVertexBufferData(verts2, LockFlags.None); m.D3dMesh.UnlockVertexBuffer(); break; case TgcMesh.MeshRenderType.DIFFUSE_MAP_AND_LIGHTMAP: var verts3 = (TgcSceneLoader.DiffuseMapAndLightmapVertex[])m.D3dMesh.LockVertexBuffer( typeof(TgcSceneLoader.DiffuseMapAndLightmapVertex), LockFlags.ReadOnly, m.D3dMesh.NumberVertices); for (var i = 0; i < verts3.Length; i++) { verts3[i].Position = TGCVector3.transform(verts3[i].Position, transform); } m.D3dMesh.SetVertexBufferData(verts3, LockFlags.None); m.D3dMesh.UnlockVertexBuffer(); break; } //Quitar movimientos del mesh m.Position = TGCVector3.Empty; m.Scale = TGCVector3.One; m.Rotation = TGCVector3.Empty; m.Transform = TGCMatrix.Identity; m.AutoTransformEnable = true; //Calcular nuevo bounding box m.createBoundingBox(); }
//private TGCMatrix YPRRrotation; //private TGCMatrix CircularRotation; public Enemy(string pathEnemy, TGCVector3 center) { Path = pathEnemy; mesh = new TgcSceneLoader().loadSceneFromFile(Path + "Enemy.xml").Meshes[0]; pivot = center; mesh.Rotation = new TGCVector3(0, -FastMath.PI_HALF, 0); mesh.Position = new TGCVector3(0, 0, -300); mesh.Transform = TGCMatrix.Scaling(TGCVector3.One) * TGCMatrix.RotationYawPitchRoll(mesh.Rotation.Y, mesh.Rotation.X, mesh.Rotation.Z) * TGCMatrix.Translation(mesh.Position); mesh.Transform = TGCMatrix.Translation(pivot); }
/// <summary> /// Convierte el TgcSphere en un TgcMesh /// </summary> /// <param name="meshName">Nombre de la malla que se va a crear</param> public TgcMesh toMesh(string meshName) { //Obtener matriz para transformar vertices if (AutoTransformEnable) { Transform = TGCMatrix.Scaling(radius, radius, radius) * TGCMatrix.RotationYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z) * TGCMatrix.Translation(translation); } return(TgcMesh.FromTGCSphere(meshName, Texture, indices, vertices, Transform, AlphaBlendEnable)); }
/// <summary> /// Rotar OBB en los 3 ejes. /// Es una rotacion relativa, sumando a lo que ya tenia antes de rotacion. /// </summary> /// <param name="rotation">Ángulo de rotación de cada eje en radianes</param> public void rotate(TGCVector3 rotation) { var rotM = TGCMatrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z); var currentRotM = computeRotationMatrix(); var newRotM = currentRotM * rotM; orientation[0] = new TGCVector3(newRotM.M11, newRotM.M12, newRotM.M13); orientation[1] = new TGCVector3(newRotM.M21, newRotM.M22, newRotM.M23); orientation[2] = new TGCVector3(newRotM.M31, newRotM.M32, newRotM.M33); dirtyValues = true; }
protected virtual void Straighten() { var transformationMatrix = TGCMatrix.RotationYawPitchRoll(FastMath.PI, 0, 0).ToBsMatrix; transformationMatrix.Origin = RigidBody.WorldTransform.Origin + new Vector3(0, 10, 0); RigidBody.MotionState = new DefaultMotionState(transformationMatrix); RigidBody.LinearVelocity = Vector3.Zero; RigidBody.AngularVelocity = Vector3.Zero; flippedTime = 0; canJump = onTheFloor = falling = false; }
public Ship(Subnautica gameInstance, string name, List <TgcMesh> meshes) : base(gameInstance, name, meshes) { Position = new TGCVector3(400, 60, -900); // seteo la posicion del barco scale *= 4; rotation = new TGCVector3(0, FastMath.PI_HALF, 0); TGCMatrix translation = TGCMatrix.Translation(Position); TGCMatrix scaling = TGCMatrix.Scaling(scale); TGCMatrix rot = TGCMatrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z); Transform = rot * scaling * translation; }
public Shooted(Weapon weapon, Vehicle car) : base(weapon) { this.car = car; this.velocity = 90f; this.weapon.direction = car.GetVectorAdelante(); this.weapon.matrix.SetTranslation(TGCMatrix.Translation(car.GetPosition())); this.weapon.matrix.Translate(TGCMatrix.Translation(new TGCVector3(0, 0.35f, 0))); TGCVector3 rotation = this.weapon.GetShootRotation(); this.weapon.matrix.SetRotation(TGCMatrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z)); this.MoveAwayFromTheCar(car); weapon.NormalEffect(); }
// ------- Métodos Privados ------- protected RigidBody CreateChassisRigidBodyFromShape(CollisionShape compound, TGCVector3 position, float rotation) { //since it is dynamic, we calculate its local inertia var localInertia = compound.CalculateLocalInertia(mass); var transformationMatrix = TGCMatrix.RotationYawPitchRoll(FastMath.PI + rotation, 0, 0).ToBsMatrix; transformationMatrix.Origin = position.ToBsVector; DefaultMotionState motionState = new DefaultMotionState(transformationMatrix); var bodyInfo = new RigidBodyConstructionInfo(mass, motionState, compound, localInertia); var rigidBody = new RigidBody(bodyInfo); return(rigidBody); }