private void ApuntarAlTarget(Vector3 PosicionTarget) { //1- bajo el contador que se fija cuando fue la ultima vez que apunte. // 2 - si todavia no puedo doblar, return! if (tiempoEspera > 0f) { return; } tiempoEspera = FixedWaitingTime; //3- Vuelvo la constante a valor inicial para que //espere para volver a apuntar la proxima vez. //4 checkeo la cantidad de grados a girar y quedar apuntando hacia el target var posicionMesh = Mesh.Position; //float ab = Vector3.Dot(posicionMesh, PosicionTarget); //float a = posicionMesh.Length(); //float b = PosicionTarget.Length(); //double anguloDouble = Math.Acos(Convert.ToDouble(a)); //anguloFinal = Convert.ToSingle(anguloDouble); //ahora pongo al mesh mirando hacia el target. //matrixRotacion = Matrix.RotationY(anguloFinal); //obb.rotate(new Vector3(0, anguloFinal, 0)); // float ang = FastMath.Acos((a * b) / ab); float X1 = Mesh.Position.X; float Z1 = Mesh.Position.Z; float X2 = meshTarget.Position.X; float Z2 = meshTarget.Position.Z; float ang = FastMath.Atan2((Z2 - Z1), (X2 - X1)); matrixRotacion = Matrix.RotationY((FastMath.PI * 3 / 2) - ang); obb.setRotation(new Vector3(0, (FastMath.PI * 3 / 2) - ang, 0)); anguloFinal = ang; angOrientacionMesh = ang; //Doblar(ang); }
public void Render(float tiempo) { OBB.setRotation(TGCVector3.Multiply(vRotacionOBB, tiempo)); OBB.Render(); }