1D Inertia Tensor (problem with boxes)

1D Inertia Tensor (problem with boxes)

Hi, I have problem with the inertia tensor for boxes. I would like to ignore all rotations around Y and X.This is how I do it:

void PhysicsGod::CreateBox(Actor* actor, const D3DXVECTOR3& radii, const PhysicalProperties& properties)
{
	ActorBodyLink* body_link = new ActorBodyLink;
	actor->AddBodyLink(body_link);

	hkpMassProperties mass_properties;
	hkpInertiaTensorComputer::computeBoxVolumeMassProperties(ConvertToVector3(radii), 1.0f, mass_properties);
	mass_properties.scaleToDensity(properties.density);

	hkpRigidBodyCinfo rigid_body_c_info;
	{
		rigid_body_c_info.m_mass = mass_properties.m_mass;
		rigid_body_c_info.m_centerOfMass  = mass_properties.m_centerOfMass;
		rigid_body_c_info.m_inertiaTensor = mass_properties.m_inertiaTensor;
		rigid_body_c_info.m_shape = new hkpBoxShape(ConvertToVector3(radii), 0);
		rigid_body_c_info.m_position = ConvertToVector3(properties.position);
		rigid_body_c_info.m_linearVelocity = ConvertToVector3(properties.linear_velocity);
		rigid_body_c_info.m_angularVelocity = ConvertToVector3(properties.angular_velocity);
		rigid_body_c_info.m_motionType = ConvertToMotionType(properties.motion_type);
		rigid_body_c_info.m_qualityType = ConvertToCollideQuality(properties.collide_quality);
		rigid_body_c_info.m_friction = properties.friction;
		rigid_body_c_info.m_restitution = properties.restitution;
	}

	body_link->rigid_body = new hkpRigidBody(rigid_body_c_info);
	body_link->rigid_body->setUserData(reinterpret_cast(body_link));


	// Adjust inertia tensor matrix to remove non-Z axis rotation
	hkMatrix3 invInertiaMatrix;
	body_link->rigid_body->getInertiaInvLocal(invInertiaMatrix);
	invInertiaMatrix(0,0) = 0.0f;
	invInertiaMatrix(1,1) = 0.0f;
	body_link->rigid_body->setInertiaInvLocal(invInertiaMatrix);


	g_physics->my_world->markForWrite();
	{
		g_physics->my_world->addEntity(body_link->rigid_body);
		body_link->rigid_body->addContactListener(my_collision_callback);
		body_link->rigid_body->addEntityListener(my_removed_callback);
		body_link->rigid_body->setContactPointCallbackDelay(0);
	}
	g_physics->my_world->unmarkForWrite();
}

The strange thing is that I'm doing the same thing to my ragdolls rootbody (the pelvisbox) and it works perfect.So do you guys have any idea why the simple box refuse to accept my new inertia tensor?This is three pictures showing how the inertia tensor looks like in the Visual Debugger:http://www.drvn.se/inertia_tensor_problem.jpgAlso if I call getInertiaInvLocal again right after I modified it. The matrix is all zeroed out.

2 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

LOL, as always when I post something I figure out the answer myself just a few secound after I submitted.Maybe things get clear when I have to specify the problem in text :)
ThehkpMotion needs to beMOTION_BOX_INERTIA insted ofMOTION_DYNAMIC.

Faça login para deixar um comentário.