Exemplo n.º 1
0
//////////////////////////////////////////////////////////////////////////
// Position the body precisely
//////////////////////////////////////////////////////////////////////////
void DropDownBox(NewtonBody *body)
{
	float matrix[16];
	NewtonBodyGetMatrix(body, matrix);
	Matrix4 m = Matrix4(matrix);

	Vector3 pos = m.GetPosition();
	pos.y += 1.0f;
	m.SetPosition(pos);
	Vector3 p = pos;
	p.y -= 20;

	// cast collision shape within +20 -20 y range
	NewtonWorld *world = NewtonBodyGetWorld(body);
	NewtonCollision *collision = NewtonBodyGetCollision(body);

	float param;
	NewtonWorldConvexCastReturnInfo info[16];
	m.FlattenToArray(matrix);
	NewtonWorldConvexCast(world, matrix, &p[0], collision, &param, body, DropDownConvexCastCallback, info, 16, 0);

	m = Matrix4(matrix);
	pos = m.GetPosition();
	m.SetPosition(pos + Vector3(0, (p.y - pos.y) * param, 0) );

	m.FlattenToArray(matrix);
	NewtonBodySetMatrix(body, matrix);
}
Exemplo n.º 2
0
NewtonBody* CPhysics::CreateBox(NewtonWorld *world, CObject3D *object, float x, float y, float z, float mass, Vector3 offset)
{
	Matrix4 offsetMat;
	offsetMat.SetPosition(offset);
	float m[16];
	offsetMat.FlattenToArray(m);

	NewtonCollision *collision = NewtonCreateBox(world, x, y, z, 0, m);
	return CreateRigidBody(world, object, collision, mass);	
}