torquevec/torquemag are off

This commit is contained in:
austin 2022-03-29 23:03:20 -04:00
parent d85610ab17
commit 0bf0418fa7

View File

@ -32,7 +32,7 @@ public class CollidableTree {
Quaternionf angularVelocity = new Quaternionf(0,0,0,0);
Vector4d cumulativeTorque = new Vector4d(0,0,0,0);
static final float DELTA_T = 0.01f;
public CollidableTree(Entity e, Collidable collidable, CollisionObject body){
parent = e;
@ -84,7 +84,10 @@ public class CollidableTree {
Vector3d forceDir = new Vector3d(impulse.getDirection().mul(-1.0f)).normalize();
Vector3d torqueVec = new Vector3d(collisionPoint).cross(forceDir).normalize();
// double torqueMag = Math.abs(impulse.force);
double torqueMag = impulse.getCollisionPoint().length() * impulse.getDirection().length() * impulse.getForce();
double torqueMag = Math.sqrt(impulse.getCollisionPoint().length()) * impulse.getForce();
if(!impulse.getType().equals(Collidable.TYPE_TERRAIN)){
torqueMag = torqueMag * 10;
}
// if(impulse.type.matches(Collidable.TYPE_ITEM) && ItemUtils.isItem(parent)){
// // System.out.println(rotation);
// if(impulse.collisionPoint.x < 0){
@ -95,15 +98,15 @@ public class CollidableTree {
// // angularVelocity.add(new Vector3d(impulse.getCollisionPoint()).cross(impulse.getDirection()),1.0);
// cumulativeTorque.add(new Vector3d(impulse.getCollisionPoint()).cross(impulse.getDirection()));
// }
// if(impulse.type.matches(Collidable.TYPE_ITEM)){
// System.out.println("Impulse: " + torqueVec + " " + torqueMag);
// }
if(CreatureUtils.isCreature(parent) && forceDir.y < 0.5){
System.out.println(collisionPoint + " x " + forceDir + " => " + torqueVec + " " + torqueMag);
if(impulse.type.matches(Collidable.TYPE_ITEM)){
System.out.println("Impulse: " + torqueVec + " " + torqueMag);
}
Quaternionf impulseRotation = new Quaternionf().rotationAxis((float)torqueMag,new Vector3f((float)torqueVec.x,(float)torqueVec.y,(float)torqueVec.z));
// if(CreatureUtils.isCreature(parent) && forceDir.y < 0.5){
// System.out.println(collisionPoint + " x " + forceDir + " => " + torqueVec + " " + torqueMag);
// }
Quaternionf impulseRotation = new Quaternionf().rotationAxis((float)torqueMag * DELTA_T,new Vector3f((float)torqueVec.x,(float)torqueVec.y,(float)torqueVec.z));
if(angularVelocity.lengthSquared() > 0.001){
angularVelocity.slerp(impulseRotation, (float)(torqueMag / Math.abs(angularVelocity.w)));
angularVelocity.mul(impulseRotation);
} else {
angularVelocity.set(impulseRotation);
}
@ -117,8 +120,9 @@ public class CollidableTree {
// }
//friction
if(angularVelocity.lengthSquared() > 0.001){
angularVelocity.scale((float)(Math.sqrt(angularVelocity.lengthSquared()) * 0.9));
System.out.println(angularVelocity);
angularVelocity.slerp(new Quaternionf(0,0,0,1), 0.01f);
// angularVelocity.scale((float)(Math.sqrt(angularVelocity.lengthSquared()) * 0.9));
// System.out.println(angularVelocity);
}
// if(cumulativeTorque.w > 0.001){
// Vector4f holder = inverseInertiaTensor.transform(new Vector4f((float)cumulativeTorque.x,(float)cumulativeTorque.y,(float)cumulativeTorque.z,(float)cumulativeTorque.w));