public void seguirA(Vector3 posJugador, float elapsedTime, float velocidad) { Vector3 direccion = posJugador - mesh.Position; direccion.Normalize(); direccion.Y = 0; mesh.rotateY((float)Math.Atan2(direccion.X, direccion.Z) - mesh.Rotation.Y - Geometry.DegreeToRadian(180f)); bounding.rotateY((float)Math.Atan2(direccion.X, direccion.Z) - mesh.Rotation.Y - Geometry.DegreeToRadian(180f)); direccion *= velocidad * elapsedTime; mesh.move(direccion); bounding.move(direccion); }
/// <summary> /// Mover ejes del gizmo /// </summary> private void moveGizmo(Vector3 movement) { gizmoCenter += movement; boxX.move(movement); boxY.move(movement); boxZ.move(movement); }
/// <summary> /// Actualizar posición de la malla en base a movimientos del mouse /// </summary> public void updateMove() { TgcD3dInput input = GuiController.Instance.D3dInput; Vector3 currentMove = new Vector3(0, 0, 0); //Desplazamiento segun el mouse en X if (selectedAxis == Axis.X) { currentMove.X += (input.XposRelative - initMouseP.X) * MOVE_FACTOR; } //Desplazamiento segun el mouse en Y else if (selectedAxis == Axis.Y) { currentMove.Y -= (input.YposRelative - initMouseP.Y) * MOVE_FACTOR; } //Desplazamiento segun el mouse en X else if (selectedAxis == Axis.Z) { currentMove.Z -= (input.YposRelative - initMouseP.Y) * MOVE_FACTOR; } //Mover mesh meshObj.mesh.move(currentMove); //Mover ejes boxX.move(currentMove); boxY.move(currentMove); boxZ.move(currentMove); }
/// <summary> /// Mover ejes del gizmo /// </summary> public void moveGizmo(Vector3 movement) { gizmoCenter += movement; boxX.move(movement); boxY.move(movement); boxZ.move(movement); boxXZ.move(movement); boxXY.move(movement); boxYZ.move(movement); }
public override void Render() { PreRender(); //Obtenemos acceso al objeto que maneja input de mouse y teclado del framework var input = TgcD3dInput.Instance; //Declaramos un vector de movimiento inicializado todo en cero. //El movimiento sobre el suelo es sobre el plano XZ. //El movimiento en altura es sobre el eje Y. //Sobre XZ nos movemos con las flechas del teclado o con las letas WASD. //Sobre el eje Y nos movemos con Space y Ctrl. var movement = new Vector3(0, 0, 0); //Movernos de izquierda a derecha, sobre el eje X. if (input.keyDown(Key.Left) || input.keyDown(Key.A)) { movement.X = 1; } else if (input.keyDown(Key.Right) || input.keyDown(Key.D)) { movement.X = -1; } //Movernos arriba y abajo, sobre el eje Y. if (input.keyDown(Key.Space)) { movement.Y = 1; } else if (input.keyDown(Key.LeftControl) || input.keyDown(Key.RightControl)) { movement.Y = -1; } //Movernos adelante y atras, sobre el eje Z. if (input.keyDown(Key.Up) || input.keyDown(Key.W)) { movement.Z = -1; } else if (input.keyDown(Key.Down) || input.keyDown(Key.S)) { movement.Z = 1; } //Multiplicar movimiento por velocidad y elapsedTime movement *= MOVEMENT_SPEED * ElapsedTime; //Aplicar movimiento box.move(movement); box.render(); PostRender(); }
public EnemigoAnimacion(Vector3 cercania, Vector3 dimensionesCaja) { string pathSonido = alumnoMediaFolder + "CucarachaJugosita\\Media\\Juego felipe sonido ambiente terror.wav"; sonidoPreSusto = new TgcStaticSound(); sonidoPreSusto.loadSound(pathSonido); this.cercania = cercania; animada = false; activarAnimacion = false; //Paths para archivo XML de la malla pathMesh = alumnoMediaFolder + "CucarachaJugosita\\Media\\SkeletalAnimations\\Robot\\Robot-TgcSkeletalMesh.xml"; //Path para carpeta de texturas de la malla mediaPath = alumnoMediaFolder + "CucarachaJugosita\\Media\\SkeletalAnimations\\Robot\\"; //Lista de animaciones disponibles animationList = new string[] { "Parado", "Caminando", "Correr", "PasoDerecho", "PasoIzquierdo", "Empujar", "Patear", "Pegar", "Arrojar", }; //Crear rutas con cada animacion animationsPath = new string[animationList.Length]; for (int i = 0; i < animationList.Length; i++) { animationsPath[i] = mediaPath + animationList[i] + "-TgcSkeletalAnim.xml"; } //Cargar mesh y animaciones TgcSkeletalLoader loader2 = new TgcSkeletalLoader(); mesh = loader2.loadMeshAndAnimationsFromFile(pathMesh, mediaPath, animationsPath); //mesh.Position = new Vector3(105, 5.06f, 660); mesh.Scale = new Vector3(0.5f, 0.5f, 0.5f); //Crear esqueleto a modo Debug mesh.buildSkletonMesh(); //Elegir animacion Caminando // mesh.BoundingBox.move(new Vector3(15,0,-170)); //mesh.BoundingBox.scaleTranslate(mesh.BoundingBox.Position, new Vector3(4f,0.8f,4f)); // este sera el rango de vision bounding = new TgcBox(); bounding = TgcBox.fromSize(mesh.Position, new Vector3(100f, 100f, 300f)); bounding.move(new Vector3(15, 0, -170)); box = new TgcBox(); box.Position = cercania; box.Size = dimensionesCaja; }
public PartesARenderizar(List <TgcMesh> mapa, Camara camarita) { escena = mapa; camara = camarita; listaCaja1 = new ArrayList(); listaCaja2 = new ArrayList(); listaCaja3 = new ArrayList(); listaCaja4 = new ArrayList(); listaCaja5 = new ArrayList(); listaCaja6 = new ArrayList(); listaCaja7 = new ArrayList(); listaCaja8 = new ArrayList(); listaCaja9 = new ArrayList(); listaCaja10 = new ArrayList(); listaCaja11 = new ArrayList(); listaCaja12 = new ArrayList(); listaCaja13 = new ArrayList(); listaCaja14 = new ArrayList(); caja1 = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(750, 750, 600), Color.Blue); caja1.move(new Vector3(375, 370, 300)); caja2 = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(500, 750, 600), Color.Blue); caja2.Position = new Vector3(750 + 250, 370, 300); caja3 = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(750, 750, 650), Color.Blue); caja3.Position = new Vector3(375, 370, 600 + 325); caja4 = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(1300, 750, 650), Color.Blue); caja4.Position = new Vector3(750 + 650, 370, 600 + 325); caja5 = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(700, 750, 600), Color.Blue); caja5.Position = new Vector3(1350 + 350, 370, 300); caja6 = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(700, 750, 500), Color.Blue); caja6.Position = new Vector3(2050 + 350, 370, 250); caja7 = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(800, 750, 500), Color.Blue); caja7.Position = new Vector3(2750 + 400, 370, 250); caja8 = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(550, 750, 600), Color.Blue); caja8.Position = new Vector3(545, 370, 1250 + 300); caja9 = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(1230, 750, 900), Color.Blue); caja9.Position = new Vector3(820 + 615, 370, 1250 + 450); caja10 = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(850, 750, 650), Color.Blue); caja10.Position = new Vector3(2050 + 425, 370, 900 + 325); caja11 = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(1300, 750, 850), Color.Blue); caja11.Position = new Vector3(2050 + 650, 370, 1550 + 425); caja12 = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(800, 750, 1050), Color.Blue); caja12.Position = new Vector3(2900 + 400, 370, 500 + 525); caja13 = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(1200, 750, 1400), Color.Blue); caja13.Position = new Vector3(3700 + 600, 370, 500 + 700); caja14 = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(850, 750, 400), Color.Blue); caja14.Position = new Vector3(2050 + 425, 370, 500 + 200); this.init(); }
public Enemigo() { //Paths para archivo XML de la malla pathMesh = alumnoMediaFolder + "CucarachaJugosita\\Media\\SkeletalAnimations\\Robot\\Robot-TgcSkeletalMesh.xml"; //Path para carpeta de texturas de la malla mediaPath = alumnoMediaFolder + "CucarachaJugosita\\Media\\SkeletalAnimations\\Robot\\"; //Lista de animaciones disponibles animationList = new string[] { "Parado", "Caminando", "Correr", "PasoDerecho", "PasoIzquierdo", "Empujar", "Patear", "Pegar", "Arrojar", }; //Crear rutas con cada animacion animationsPath = new string[animationList.Length]; for (int i = 0; i < animationList.Length; i++) { animationsPath[i] = mediaPath + animationList[i] + "-TgcSkeletalAnim.xml"; } //Cargar mesh y animaciones TgcSkeletalLoader loader2 = new TgcSkeletalLoader(); mesh = loader2.loadMeshAndAnimationsFromFile(pathMesh, mediaPath, animationsPath); //mesh.Position = new Vector3(105, 5.06f, 660); mesh.Scale = new Vector3(0.5f, 0.5f, 0.5f); //Crear esqueleto a modo Debug mesh.buildSkletonMesh(); //Elegir animacion Caminando // mesh.BoundingBox.move(new Vector3(15,0,-170)); //mesh.BoundingBox.scaleTranslate(mesh.BoundingBox.Position, new Vector3(4f,0.8f,4f)); // este sera el rango de vision bounding = new TgcBox(); bounding = TgcBox.fromSize(mesh.Position, new Vector3(100f, 100f, 300f)); bounding.move(new Vector3(15, 0, -170)); sonidoCaminar = new Tgc3dSound(GuiController.Instance.AlumnoEjemplosDir + "CucarachaJugosita\\Media\\pasos_16.wav", mesh.Position); sonidoCaminar.MinDistance = 30f; sonidoPerseguir = new Tgc3dSound(GuiController.Instance.AlumnoEjemplosDir + "CucarachaJugosita\\Media\\monstruoMuyEnojado.wav", mesh.Position); sonidoPerseguir.MinDistance = 300f; }
public override void Update() { PreUpdate(); //En cada cuadro de render rotamos la caja con cierta velocidad (en radianes) //Siempre tenemos que multiplicar las velocidades por el elapsedTime. //De esta forma la velocidad de rotacion es independiente de la potencia del CPU. //Sino en computadoras con CPU más rápido la caja giraría mas rápido que en computadoras mas lentas. box3.rotateY(ROTATION_SPEED * ElapsedTime); //Aplicamos una traslación en Y. Hacemos que la caja se mueva en forma intermitente en el intervalo [0, 3] de Y. //Cuando llega a uno de los límites del intervalo invertimos la dirección del movimiento. //Tambien tenemos que multiplicar la velocidad por el elapsedTime box3.move(0, MOVEMENT_SPEED * currentMoveDir * ElapsedTime, 0); if (FastMath.Abs(box3.Position.Y) > 3f) { currentMoveDir *= -1; } }
private void moveTo(Vector3 movimiento) { sphere.move(movimiento); box.move(movimiento); }
public Enemigo2() { //Path para carpeta de texturas de la malla mediaPath = alumnoMediaFolder + "CucarachaJugosita\\Media\\SkeletalAnimations\\BasicHuman\\"; //Cargar dinamicamente todos los Mesh animados que haya en el directorio DirectoryInfo dir = new DirectoryInfo(mediaPath); FileInfo[] meshFiles = dir.GetFiles("*-TgcSkeletalMesh.xml", SearchOption.TopDirectoryOnly); string[] meshList = new string[meshFiles.Length]; for (int i = 0; i < meshFiles.Length; i++) { string name = meshFiles[i].Name.Replace("-TgcSkeletalMesh.xml", ""); meshList[i] = name; } //Cargar dinamicamente todas las animaciones que haya en el directorio "Animations" DirectoryInfo dirAnim = new DirectoryInfo(mediaPath + "Animations\\"); FileInfo[] animFiles = dirAnim.GetFiles("*-TgcSkeletalAnim.xml", SearchOption.TopDirectoryOnly); animationList = new string[animFiles.Length]; animationsPath = new string[animFiles.Length]; for (int i = 0; i < animFiles.Length; i++) { string name = animFiles[i].Name.Replace("-TgcSkeletalAnim.xml", ""); animationList[i] = name; animationsPath[i] = animFiles[i].FullName; } //Cargar mesh inicial animationList = new string[animFiles.Length]; animationsPath = new string[animFiles.Length]; for (int i = 0; i < animFiles.Length; i++) { string name = animFiles[i].Name.Replace("-TgcSkeletalAnim.xml", ""); animationList[i] = name; animationsPath[i] = animFiles[i].FullName; } animationList = new string[] { "StandBy", "Walk", "Run", "Jump", "LowKick", "Push", "Patear", "Pegar", "Arrojar", "AASD", }; selectedAnim = animationList[0]; TgcSkeletalLoader loader = new TgcSkeletalLoader(); mesh = loader.loadMeshAndAnimationsFromFile(mediaPath + "Quake2Scout-TgcSkeletalMesh.xml", mediaPath, animationsPath); mesh.Scale = new Vector3(1.3f, 1.3f, 1.3f); //Crear esqueleto a modo Debug mesh.buildSkletonMesh(); //Elegir animacion inicial mesh.playAnimation(selectedAnim, true); bounding = new TgcBox(); bounding = TgcBox.fromSize(mesh.Position, new Vector3(100f, 100f, 300f)); bounding.move(new Vector3(15, 0, -170)); }
public override void move(Vector3 move) { mesh.move(move); }
public override void Render() { PreRender(); var velocidadCaminar = 50f * ElapsedTime; //Calcular proxima posicion de personaje segun Input var d3dInput = TgcD3dInput.Instance; var moving = false; var movement = new Vector3(0, 0, 0); //Adelante if (d3dInput.keyDown(Key.W)) { movement.Z = velocidadCaminar; moving = true; } //Atras if (d3dInput.keyDown(Key.S)) { movement.Z = -velocidadCaminar; moving = true; } //Derecha if (d3dInput.keyDown(Key.D)) { movement.X = velocidadCaminar; moving = true; } //Izquierda if (d3dInput.keyDown(Key.A)) { movement.X = -velocidadCaminar; moving = true; } //Salto if (d3dInput.keyDown(Key.Space)) { movement.Y = velocidadCaminar; moving = true; } //Agachar if (d3dInput.keyDown(Key.LeftControl)) { movement.Y = -velocidadCaminar; moving = true; } //Si hubo desplazamiento if (moving) { //Aplicar movimiento box.move(movement); } //Hacer que la camara siga al personaje en su nueva posicion camaraInterna.Target = box.Position; //Detectar colision con triangulo if (TgcCollisionUtils.testTriangleAABB(triangle[0].Position, triangle[1].Position, triangle[2].Position, box.BoundingBox)) { box.BoundingBox.render(); triagleAABB.render(); } //Detectar colision con el otro AABB if (TgcCollisionUtils.testAABBAABB(box.BoundingBox, box2.BoundingBox)) { box.BoundingBox.render(); box2.BoundingBox.render(); } //Detectar colision con la esfera if (TgcCollisionUtils.testSphereAABB(sphere, box.BoundingBox)) { box.BoundingBox.render(); sphere.setRenderColor(Color.Red); } else { sphere.setRenderColor(Color.Yellow); } //Detectar colision con la obb if (TgcCollisionUtils.testObbAABB(obb, box.BoundingBox)) { box.BoundingBox.render(); obb.setRenderColor(Color.Red); } else { obb.setRenderColor(Color.Yellow); } //Dibujar box.render(); box2.render(); sphere.render(); 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(); }