Jump to content

Collision::SetResponse does not seem to be working


Recommended Posts

I've been doing some collision/physics testing today and noticed that SetResponse() does not seem to be working. Setting up two new Collision Types and their response results in no detection (at least based on my tests).

 

Here's a small c++ test app. Please excuse the sloppy code--my brainstorming code is less-than-organized; and snippets don't retain formatting, so it gets even uglier.... Using WASD will move the green box around in space (although it's the other blocks that move, thus keeping your block centered on screen).

 

As it stands, you will get no reaction when the two objects meet. BUT, if you change these lines then things respond as you'd expect:

 

//MEblock->SetCollisionType(Collision::Prop);		 //<--USING THIS WORKS
MEblock->SetCollisionType(50);			 //<--THIS DOES NOT USING THE ABOVE DEFINITION

 

and

 

//TESTblock->SetCollisionType(Collision::Prop);		 //<--USING THIS WORKS
TESTblock->SetCollisionType(51);		 //<--THIS DOES NOT USING THE ABOVE DEFINITION

 

 

 

Here's the complete .cpp:

 

#include "App.h"
using namespace Leadwerks;

App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {}
App::~App() { delete world; delete window; }Pivot *cameraDummy, *moveDummy;

Light *omnilight;
Model *MEblock, *TESTblock, *THEMblock;
Shape* Cshape;
Vec3 MYmomentum = 0.0, THEIRmomentum = 0.0, MYrotationGLOBAL = 0.0, MYrotationLOCAL = 0.0, THEIRrotation = 0.0, MYvelANGULAR = 0.0;int PREVtime = Time::GetCurrent();
float timeMULTI = 0.0;
Vec3 currOMG = 0.0;

bool App::Start()
{
window = Window::Create("test", 0, 0, 1024, 768, Window::Titlebar + Window::Center);
context = Context::Create(window);
world = World::Create();
world->SetGravity(0, -9.8, 0);cameraDummy = Pivot::Create();

camera = Camera::Create();
camera->SetRange(0.1, 200);
camera->SetPosition(0.0, 2.0, -5.0);
camera->SetParent(cameraDummy);

omnilight = PointLight::Create();
omnilight->SetPosition(0.0, 10.0, -10.0);
omnilight->SetRange(20);
omnilight->SetShadowMapSize(1024);moveDummy = Pivot::Create();

PhysicsDriver::GetCurrent()->SetCollisionResponse(50, 51, Collision::Collide); //<-- TRYING BOTH METHODS HERE TO SET A RESPONSE -- NEITHER SEEMS TO WORK
//Collision::SetResponse(50, 51, 1);MEblock = Model::Box();

MEblock->SetScale(1, 1, 1);
MEblock->SetMass(3000);
//MEblock->SetCollisionType(Collision::Prop);		 //<--USING THIS WORKS
MEblock->SetCollisionType(50);			 //<--THIS DOES NOT USING THE ABOVE DEFINITIONMEblock->SetColor(0.0, 1.0, 0.0);
Cshape = Shape::Box(0, 0, 0, 0, 0, 0, 1, 1, 1);
MEblock->SetShape(Cshape);
Cshape->Release();
MEblock->SetPosition(0.0, 0.0, 0.0);
MEblock->SetGravityMode(0);

TESTblock = Model::Box();
TESTblock->SetScale(0.5, 0.5, 0.5);
TESTblock->SetMass(0);//TESTblock->SetCollisionType(Collision::Prop);		 //<--USING THIS WORKS
TESTblock->SetCollisionType(51);		 //<--THIS DOES NOT USING THE ABOVE DEFINITION
TESTblock->SetColor(0.0, 1.0, 0.0);
Cshape = Shape::Box(0, 0, 0, 0, 0, 0, 0.5, 0.5, 0.5);
TESTblock->SetShape(Cshape);
Cshape->Release();
TESTblock->SetPosition(0.0, 0.8, 0.0);
TESTblock->SetGravityMode(0);
TESTblock->SetParent(MEblock, false);

THEMblock = Model::Box();
THEMblock->SetScale(1, 1, 1);
THEMblock->SetMass(3000);
//THEMblock->SetMass(0);
THEMblock->SetCollisionType(Collision::Prop);
THEMblock->SetColor(0.0, 1.0, 1.0);
Cshape = Shape::Box(0, 0, 0, 0, 0, 0, 1, 1, 1);
THEMblock->SetShape(Cshape);
Cshape->Release();
THEMblock->SetPosition(2.0, 2.0, 2.0);
THEMblock->SetGravityMode(0);
THEMblock->SetScale(1.5, 1.5, 1.5);
//THEMblock->SetParent(ROOTpiv);return true;
}

bool App::Loop()
{
Vec3 offset = 0.0;
Vec3 Roffset = 0.0;
Vec3 NEWrotation = 0.0;Vec3 OLDrot = THEMblock->GetRotation(true);
Vec3 OLDpos = THEMblock->GetPosition(true);
int newTime = Time::GetCurrent();
int cycleTime = newTime - PREVtime;
if (cycleTime >= 1)
{
timeMULTI = cycleTime / 1000.0;
PREVtime = newTime;
if (window->KeyDown(Key::Escape) || window->Closed()) return false; NEWrotation = MEblock->GetRotation(true);	 //Get my last rotation
Roffset = MEblock->GetRotation(false) - MYrotationLOCAL; //Difference between last rotation and current (PROBALBY NOT NEEDED)
offset = MEblock->GetPosition(true);		 //End of last cycle we were set to 0,0,0 -- if we moved then we were bumped, which will affect our momentum
MEblock->PhysicsSetPosition(0.0, 0.0, 0.0, 1.0);	 //Move back to 0,0,0
MYmomentum += (offset * 1);		 //Adjust my momentum by offset
//** Translation ** (WORKING WELL)
moveDummy->SetPosition(0.0, 0.0, 0.0, true);	 //MoveDummy to 0,0,0
moveDummy->SetRotation(NEWrotation, true);	 //MoveDummy rotation to current rotation
if (window->KeyDown(Key::A)) moveDummy->Move(-0.01, 0, 0); //vvv get movements vvv
else if (window->KeyDown(Key:)) moveDummy->Move(0.01, 0, 0); if (window->KeyDown(Key::W)) moveDummy->Move(0.0, 0.0, 0.01);
else if (window->KeyDown(Key::S)) moveDummy->Move(0.0, 0.0, -0.01);
if (window->KeyDown(Key::E)) moveDummy->Move(0.0, 0.01, 0.0);
else if (window->KeyDown(Key::C)) moveDummy->Move(0.0, -0.01, 0.0); //^^^ get movements ^^^ MYmomentum += moveDummy->GetPosition(true);	 //Add new movement to momentum
THEMblock->SetVelocity(MYmomentum * -1);	 //use offset to move other objects
//** Rotation **
moveDummy->SetPosition(0.0, 0.0, 0.0, true);
moveDummy->SetRotation(NEWrotation, true); if (window->KeyDown(Key::G)) MYvelANGULAR.y += -0.001;
else if (window->KeyDown(Key::J)) MYvelANGULAR.y += 0.001;
if (window->KeyDown(Key::Y)) MYvelANGULAR.x += 0.001;
else if (window->KeyDown(Key::H)) MYvelANGULAR.x += -0.001;
if (window->KeyDown(Key::T)) MYvelANGULAR.z += -0.001;
else if (window->KeyDown(Key::U)) MYvelANGULAR.z += 0.001;
moveDummy->Turn(MYvelANGULAR, false);
MYrotationGLOBAL = moveDummy->GetRotation(true);	 //Record new orientation for use next cycle
Quat NewQuat = moveDummy->GetQuaternion(true);
cameraDummy->SetRotation(MYrotationGLOBAL, true);	 //Set Camera orientation with new rotation
MEblock->PhysicsSetRotation(NewQuat, 1.0); MYrotationLOCAL = moveDummy->GetRotation(false);	 //Probably not needed

}
//Continue
Time::Update();
world->Update();
world->Render();context->SetColor(255, 0, 0);
context->SetBlendMode(Blend::Alpha);
context->DrawText("UPS: " + String(Time::UPS()), 2, 2);
context->DrawText("My A VEL X: " + String(MYvelANGULAR.x), 2, 15);
context->DrawText("My A VEL Y: " + String(MYvelANGULAR.y), 2, 30);
context->DrawText("My A VEL Z: " + String(MYvelANGULAR.z), 2, 45);
context->DrawText("My RoffSet X: " + String(Roffset.x), 2, 75);
context->DrawText("My RoffSet Y: " + String(Roffset.y), 2, 90);
context->DrawText("My RoffSet Z: " + String(Roffset.z), 2, 105);context->DrawText("My Rotation X: " + String(MYrotationGLOBAL.x), 2, 135);
context->DrawText("My Rotation Y: " + String(MYrotationGLOBAL.y), 2, 150);
context->DrawText("My Rotation Z: " + String(MYrotationGLOBAL.z), 2, 165);
context->SetBlendMode(Blend::Solid);
context->SetColor(0, 0, 0);
context->Sync(false);
return true;
}

 

Thanks for giving this a look. If there's something wrong with my setup then please feel free to slap me upside the head smile.png I thought maybe I had to register the collision types before created the response, but I couldn't find anything seemed appropriate. Based on a couple other threads though, I was under the impression I didn't need to do that. Hence, this appears to be a bug...

 

Note, I also tried using PhysicsDriver::GetCurrent()->SetCollisionResponse() with the same results...

--"There is no spoon"

Link to comment
Share on other sites

This code doesn't run.

 

------

 

I modified it so the MEBLock is getting created, but the WASD keys don't do anything.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Ah--was some copy/paste weirdness. Let's try this again:

 

#include "App.h"
using namespace Leadwerks;

App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {}
App::~App() { delete world; delete window; }
Pivot *cameraDummy, *moveDummy;
Light *omnilight;
Model *MEblock, *TESTblock, *THEMblock;
Shape* Cshape;
Vec3 MYmomentum = 0.0, THEIRmomentum = 0.0, MYrotationGLOBAL = 0.0, MYrotationLOCAL = 0.0, THEIRrotation = 0.0, MYvelANGULAR = 0.0;
int PREVtime = Time::GetCurrent();
float timeMULTI = 0.0;
Vec3 currOMG = 0.0;
bool App::Start()
{
window = Window::Create("test", 0, 0, 1024, 768, Window::Titlebar + Window::Center);
context = Context::Create(window);
world = World::Create();
world->SetGravity(0, -9.8, 0);
cameraDummy = Pivot::Create();
camera = Camera::Create();
camera->SetRange(0.1, 200);
camera->SetPosition(0.0, 2.0, -5.0);
camera->SetParent(cameraDummy);
omnilight = PointLight::Create();
omnilight->SetPosition(0.0, 10.0, -10.0);
omnilight->SetRange(20);
omnilight->SetShadowMapSize(1024);
moveDummy = Pivot::Create();
PhysicsDriver::GetCurrent()->SetCollisionResponse(50, 51, Collision::Collide); //<-- TRYING BOTH METHODS HERE TO SET A RESPONSE -- NEITHER SEEMS TO WORK
//Collision::SetResponse(50, 51, 1);
MEblock = Model::Box();
MEblock->SetScale(1, 1, 1);
MEblock->SetMass(3000);
//MEblock->SetCollisionType(Collision::Prop);		 //<--USING THIS WORKS
MEblock->SetCollisionType(50);			 //<--THIS DOES NOT USING THE ABOVE DEFINITION
MEblock->SetColor(0.0, 1.0, 0.0);
Cshape = Shape::Box(0, 0, 0, 0, 0, 0, 1, 1, 1);
MEblock->SetShape(Cshape);
Cshape->Release();
MEblock->SetPosition(0.0, 0.0, 0.0);
MEblock->SetGravityMode(0);
TESTblock = Model::Box();
TESTblock->SetScale(0.5, 0.5, 0.5);
TESTblock->SetMass(0);
//TESTblock->SetCollisionType(Collision::Prop);		 //<--USING THIS WORKS
TESTblock->SetCollisionType(51);		    //<--THIS DOES NOT USING THE ABOVE DEFINITION
TESTblock->SetColor(0.0, 1.0, 0.0);
Cshape = Shape::Box(0, 0, 0, 0, 0, 0, 0.5, 0.5, 0.5);
TESTblock->SetShape(Cshape);
Cshape->Release();
TESTblock->SetPosition(0.0, 0.8, 0.0);
TESTblock->SetGravityMode(0);
TESTblock->SetParent(MEblock, false);
THEMblock = Model::Box();
THEMblock->SetScale(1, 1, 1);
THEMblock->SetMass(3000);
//THEMblock->SetMass(0);
THEMblock->SetCollisionType(Collision::Prop);
THEMblock->SetColor(0.0, 1.0, 1.0);
Cshape = Shape::Box(0, 0, 0, 0, 0, 0, 1, 1, 1);
THEMblock->SetShape(Cshape);
Cshape->Release();
THEMblock->SetPosition(2.0, 2.0, 2.0);
THEMblock->SetGravityMode(0);
THEMblock->SetScale(1.5, 1.5, 1.5);
//THEMblock->SetParent(ROOTpiv);
return true;
}
bool App::Loop()
{
Vec3 offset = 0.0;
Vec3 Roffset = 0.0;
Vec3 NEWrotation = 0.0;
Vec3 OLDrot = THEMblock->GetRotation(true);
Vec3 OLDpos = THEMblock->GetPosition(true);
int newTime = Time::GetCurrent();
int cycleTime = newTime - PREVtime;
if (cycleTime >= 1)
{
 timeMULTI = cycleTime / 1000.0;
 PREVtime = newTime;
 if (window->KeyDown(Key::Escape) || window->Closed()) return false;
 NEWrotation = MEblock->GetRotation(true);	    //Get my last rotation
 Roffset = MEblock->GetRotation(false) - MYrotationLOCAL;    //Difference between last rotation and current (PROBALBY NOT NEEDED)
 offset = MEblock->GetPosition(true);		 //End of last cycle we were set to 0,0,0 -- if we moved then we were bumped, which will affect our momentum
 MEblock->PhysicsSetPosition(0.0, 0.0, 0.0, 1.0);	  //Move back to 0,0,0
 MYmomentum += (offset * 1);		    //Adjust my momentum by offset

 //** Translation ** (WORKING WELL)
 moveDummy->SetPosition(0.0, 0.0, 0.0, true);	   //MoveDummy to 0,0,0
 moveDummy->SetRotation(NEWrotation, true);	    //MoveDummy rotation to current rotation
 if (window->KeyDown(Key::A)) moveDummy->Move(-0.01, 0, 0);    //vvv get movements vvv
 else if (window->KeyDown(Key:)) moveDummy->Move(0.01, 0, 0);
 if (window->KeyDown(Key::W)) moveDummy->Move(0.0, 0.0, 0.01);
 else if (window->KeyDown(Key::S)) moveDummy->Move(0.0, 0.0, -0.01);
 if (window->KeyDown(Key::E)) moveDummy->Move(0.0, 0.01, 0.0);
 else if (window->KeyDown(Key::C)) moveDummy->Move(0.0, -0.01, 0.0);  //^^^ get movements ^^^
 MYmomentum += moveDummy->GetPosition(true);	    //Add new movement to momentum
 THEMblock->SetVelocity(MYmomentum * -1);	    //use offset to move other objects
 //** Rotation **
 moveDummy->SetPosition(0.0, 0.0, 0.0, true); 
 moveDummy->SetRotation(NEWrotation, true);
 if (window->KeyDown(Key::G))  MYvelANGULAR.y += -0.001;
 else if (window->KeyDown(Key::J))  MYvelANGULAR.y += 0.001;
 if (window->KeyDown(Key::Y))  MYvelANGULAR.x += 0.001;
 else if (window->KeyDown(Key::H))  MYvelANGULAR.x += -0.001;
 if (window->KeyDown(Key::T))  MYvelANGULAR.z += -0.001;
 else if (window->KeyDown(Key::U))  MYvelANGULAR.z += 0.001;
 moveDummy->Turn(MYvelANGULAR, false);
 MYrotationGLOBAL = moveDummy->GetRotation(true);	  //Record new orientation for use next cycle
 Quat NewQuat = moveDummy->GetQuaternion(true);
 cameraDummy->SetRotation(MYrotationGLOBAL, true);	  //Set Camera orientation with new rotation
 MEblock->PhysicsSetRotation(NewQuat, 1.0);
 MYrotationLOCAL = moveDummy->GetRotation(false);	  //Probably not needed

}
//Continue
Time::Update();
world->Update();
world->Render();
context->SetColor(255, 0, 0);
context->SetBlendMode(Blend::Alpha);
context->DrawText("UPS: " + String(Time::UPS()), 2, 2);
context->DrawText("My A VEL X: " + String(MYvelANGULAR.x), 2, 15);
context->DrawText("My A VEL Y: " + String(MYvelANGULAR.y), 2, 30);
context->DrawText("My A VEL Z: " + String(MYvelANGULAR.z), 2, 45);
context->DrawText("My RoffSet X: " + String(Roffset.x), 2, 75);
context->DrawText("My RoffSet Y: " + String(Roffset.y), 2, 90);
context->DrawText("My RoffSet Z: " + String(Roffset.z), 2, 105);
context->DrawText("My Rotation X: " + String(MYrotationGLOBAL.x), 2, 135);
context->DrawText("My Rotation Y: " + String(MYrotationGLOBAL.y), 2, 150);
context->DrawText("My Rotation Z: " + String(MYrotationGLOBAL.z), 2, 165);
context->SetBlendMode(Blend::Solid);
context->SetColor(0, 0, 0);
context->Sync(false);
return true;
}

--"There is no spoon"

Link to comment
Share on other sites

I tested the above code by copying it back and it works fine now in both release and debug. again, sorry about the bugs created by the copy/paste....

 

WASD will make the blue block move left/right/forward/back. The E and C keys will move it up and down. At least it does here, anyway :) No collisions will occur until you change the two relevant lines (thus ignoring the attempted SetResponse )

--"There is no spoon"

Link to comment
Share on other sites

Just looking at the code quickly (without compiling) and comparing a few things to my code you have done the responses correctly and I haven't noticed any bugs for this as of yet. Maybe the parenting is messing things up with two different collision types?

 

camera->SetDebugPhysicsMode(true); may help you debug a little further.

trindieprod.png?dl=0spacer.png?dl=0steam-icon.png?dl=0twitter-icon.png?dl=0spacer.png?dl=0
Link to comment
Share on other sites

Here is an example of a custom mover class I created and all the collision responses that go along with it.

 

//Define collision types

PhysicsDriver::GetCurrent()->SetCollisionResponse(kCollisionMover, Collision::Scene, 0);

PhysicsDriver::GetCurrent()->SetCollisionResponse(kCollisionMover, Collision::Prop, 0);

PhysicsDriver::GetCurrent()->SetCollisionResponse(kCollisionMover, Collision::Trigger, 0);

PhysicsDriver::GetCurrent()->SetCollisionResponse(kCollisionMover, Collision::Character, 1);

PhysicsDriver::GetCurrent()->SetCollisionResponse(kCollisionMover, kCollisionProjectile, 1);

PhysicsDriver::GetCurrent()->SetCollisionResponse(kCollisionMover, kCollisionCorpse, 0);

PhysicsDriver::GetCurrent()->SetCollisionResponse(kCollisionMover, kCollisionBorder, 0);

PhysicsDriver::GetCurrent()->SetCollisionResponse(kCollisionMover, kCollisionMover, 0);

trindieprod.png?dl=0spacer.png?dl=0steam-icon.png?dl=0twitter-icon.png?dl=0spacer.png?dl=0
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...