Преглед изворни кода

BtPhysTest : Container box now moves.

legacy
Benjamin ‘Touky’ Huet touky пре 12 година
родитељ
комит
ebbed2988a
4 измењених фајлова са 61 додато и 28 уклоњено
  1. +53
    -26
      test/BtPhysTest.cpp
  2. +1
    -1
      test/PhysicObject.h
  3. +1
    -1
      test/Physics/EasyPhysics.cpp
  4. +6
    -0
      test/Physics/LolPhysics.h

+ 53
- 26
test/BtPhysTest.cpp Прегледај датотеку

@@ -73,23 +73,26 @@ BtPhysTest::BtPhysTest(bool editor)
m_simulation->InitContext();
vec3 NewGravity = vec3(.0f, -10.0f, .0f);
m_simulation->SetGravity(NewGravity);
m_simulation->SetContinuousDetection(true);

float offset = 30.f;
float offset = 29.5f;
vec3 pos_offset = vec3(.0f, 30.f, .0f);
for (int i=0; i < 6; i++)
{
vec3 NewPosition = vec3(.0f);
quat NewRotation = quat(1.f);

PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation);

int idx = i/2;
vec3 NewPosition = pos_offset;
NewPosition = pos_offset;
NewPosition[idx] += offset;
offset *= -1.f;

quat NewRotation = quat(mat4(1.f));
PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation);

if (idx != 1)
{
vec3 axis = vec3(.0f);
axis[idx] = 1;
axis[2 - idx] = 1;
NewRotation = quat::rotate(90.f, axis);
}

@@ -98,14 +101,14 @@ BtPhysTest::BtPhysTest(bool editor)
m_ground_list << NewPhyobj;
}

for (int x=0; x < 5; x++)
for (int x=0; x < 6; x++)
{
for (int y=0; y < 5; y++)
for (int y=0; y < 6; y++)
{
for (int z=0; z < 4; z++)
for (int z=0; z < 5; z++)
{
PhysicsObject* new_physobj = new PhysicsObject(m_simulation, 10.f,
vec3(-20.f, 40.f, -20.f) +
vec3(-20.f, 20.f, -20.f) +
vec3(4.f * (float)x, 4.f * (float)y, 4.f * (float)z));
m_physobj_list << new_physobj;
Ticker::Ref(new_physobj);
@@ -268,40 +271,64 @@ void BtPhysTest::TickGame(float seconds)

m_simulation->TickContext(seconds);

vec3 barycenter = vec3(.0f);
vec3 GroundBarycenter = vec3(.0f);
vec3 PhysObjBarycenter = vec3(.0f);
float factor = .0f;
for (int i = 0; i < m_ground_list.Count(); i++)
{
PhysicsObject* PhysObj = m_ground_list[i];
mat4 GroundMat = PhysObj->GetTransform();

GroundBarycenter += GroundMat.v3.xyz;
factor += 1.f;
}

GroundBarycenter /= factor;

for (int i = 0; i < m_ground_list.Count(); i++)
{
PhysicsObject* PhysObj = m_ground_list[i];

mat4 GroundMat = PhysObj->GetTransform();
vec3 CenterToGround = GroundMat.v3.xyz - vec3(.0f, 50.f, .0f);
vec3 CenterToCam = m_camera->m_position - vec3(.0f, 50.f, .0f);
if (dot(CenterToCam, CenterToGround) > .0f)
vec3 CenterToGround = GroundMat.v3.xyz - GroundBarycenter;
vec3 CenterToCam = m_camera->m_position - GroundBarycenter;
vec3 CamDir = m_camera->m_position - m_camera->GetTarget();

if (dot(normalize(CenterToGround), normalize(CenterToCam)) > .0f &&
dot(normalize(CenterToGround), normalize(CamDir)) > .0f)
PhysObj->SetRender(false);
else
PhysObj->SetRender(true);

barycenter += GroundMat.v3.xyz;
factor += 1.f;
}

barycenter /= factor;

for (int i = 0; i < m_ground_list.Count(); i++)
{
PhysicsObject* PhysObj = m_ground_list[i];

mat4 GroundMat = PhysObj->GetTransform();
mat4 CenterMx = mat4::translate(barycenter);
//GroundMat = inverse(CenterMx) * GroundMat;
//GroundMat = CenterMx * GroundMat;
//mat4(quat::rotate(seconds * 10.0f, vec3(0, 1, 0))) * CenterMx;
//PhysObj->SetTransform(GroundMat.v3.xyz, quat(GroundMat));
mat4 CenterMx = mat4::translate(GroundBarycenter);
GroundMat = inverse(CenterMx) * GroundMat;
GroundMat = CenterMx *
mat4(quat::fromeuler_xyz(vec3(.0f, 20.f, 20.0f) * seconds))
* GroundMat;
PhysObj->SetTransform(GroundMat.v3.xyz, quat(GroundMat));
}

m_camera->SetTarget(barycenter);
m_camera->SetPosition(vec3(-40.0f, 60.0f, -40.0f));
PhysObjBarycenter = vec3(.0f);
for (int i = 0; i < m_physobj_list.Count(); i++)
{
PhysicsObject* PhysObj = m_physobj_list[i];
mat4 GroundMat = PhysObj->GetTransform();

PhysObjBarycenter += GroundMat.v3.xyz;
factor += 1.f;
}

PhysObjBarycenter /= factor;

m_camera->SetTarget(PhysObjBarycenter);
m_camera->SetPosition(GroundBarycenter + normalize(GroundBarycenter - PhysObjBarycenter) * 60.0f);

#if 0
///step the simulation


+ 1
- 1
test/PhysicObject.h Прегледај датотеку

@@ -24,7 +24,7 @@ public:
PhysicsObject(Simulation* new_sim, const vec3 &base_location, const quat &base_rotation)
: m_ready(false), m_should_render(true)
{
m_mesh.Compile("[sc#add afcb60 1 60 -.1]");
m_mesh.Compile("[sc#ddd afcb60 1 60 -.1]");
vec3 BoxSize = vec3(60.f, 1.f, 60.f);
m_physics.SetShapeToBox(BoxSize);
m_physics.SetMass(.0f);


+ 1
- 1
test/Physics/EasyPhysics.cpp Прегледај датотеку

@@ -111,7 +111,7 @@ void EasyPhysics::SetTransform(const lol::vec3& base_location, const lol::quat&
else
{
m_rigid_body->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location)));
m_motion_state->setWorldTransform(m_rigid_body->getWorldTransform());
m_motion_state->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location)));
}
}
else


+ 6
- 0
test/Physics/LolPhysics.h Прегледај датотеку

@@ -56,6 +56,12 @@ public:
m_dynamics_world = new btDiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, m_collision_configuration);
}

void SetContinuousDetection(bool ShouldUseCCD)
{
if (m_dynamics_world)
m_dynamics_world->getDispatchInfo().m_useContinuous = ShouldUseCCD;
}

void SetGravity(vec3 &NewGravity)
{
if (m_dynamics_world)


Loading…
Откажи
Сачувај