xtreampb Posted June 8, 2013 Share Posted June 8, 2013 OK this is very weird, and may be a leadwerks bug. i've created a class which is basically 3 models and functions to control them. in my main loop i load an instance of my class and create another model with the same texture. the collision recognizes fine. I can hide the main model in my custom class. I get an issue when i try to position my second model to the location of the first one i just hid, it moves my ground (the model that the first collided with) to the location instead of the first one. below is my code. At the bottom is an attached exe so that you can see what is going on. rusted_iron.cpp // // Rusted_Iron.cpp // Kings // // Created by James Thomas on 6/6/13. // Copyright (c) 2013 Leadwerks Software. All rights reserved. // #include "Rusted_Iron.h" //Function that is called when object collides void Coll(Entity* entity0, Entity* entity1, float* position, float* normal, float speed) { Rusted_Iron *mBlock=reinterpret_cast<Rusted_Iron*>(&entity0); mBlock->Break(); } Rusted_Iron::Rusted_Iron() { //load all the models for the rusted_iron block this->Full=Model::Load("Models/Rusted_Iron/Rusted_Iron.mdl"); this->P1=Model::Load("Models/Rusted_Iron/Rusted_Ironpart01.mdl"); this->P2=Model::Load("Models/Rusted_Iron/Rusted_Ironpart02.mdl"); this->P3=Model::Load("Models/Rusted_Iron/Rusted_Ironpart03.mdl"); //hide the broken models //this->Full->Hide(); this->P1->Hide(); this->P2->Hide(); this->P3->Hide(); //paint all the models wit the material this->Full->SetMaterial(Material::Load("Models/Rusted_Iron/Rusted_Iron.mat")); this->P1->SetMaterial(Material::Load("Models/Rusted_Iron/Rusted_Iron.mat")); this->P2->SetMaterial(Material::Load("Models/Rusted_Iron/Rusted_Iron.mat")); this->P3->SetMaterial(Material::Load("Models/Rusted_Iron/Rusted_Iron.mat")); //load the physics shape for each model this->Full->SetShape(Shape::Load("Models/Rusted_Iron/Rusted_Iron.phy")); this->P1->SetShape(Shape::Load("Models/Rusted_Iron/Rusted_Ironpart01.phy")); this->P2->SetShape(Shape::Load("Models/Rusted_Iron/Rusted_Ironpart02.phy")); this->P3->SetShape(Shape::Load("Models/Rusted_Iron/Rusted_Ironpart03.phy")); //this->Full->SetCollisionType(Collision::Scene); this->Full->SetMass(1); this->P1->SetMass(1); this->P2->SetMass(1); this->P3->SetMass(1); //insert collision hook this->Full->AddHook(Entity::CollisionHook,(void*)Coll); //set user data type to 'this' so that we can retrieve itself upon collision //this->Full->SetUserData(this); } Rusted_Iron::~Rusted_Iron() { /*delete this->Full; delete this->P1; delete this->P2; delete this->P3;*/ } void Rusted_Iron::Break() { // this->P1->SetPosition(Full->GetPosition()); // this->P2->SetPosition(Full->GetPosition()); // this->P3->SetPosition(Full->GetPosition()); this->Full->Hide(); this->P1->SetPosition(0,0,0);//sets my ground model to origin instead of this model this->P1->Show(); //this->P2->Show(); //this->P3->Show(); } rusted_iron.h // // Rusted_Iron.h // Kings // // Created by James Thomas on 6/6/13. // Copyright (c) 2013 Leadwerks Software. All rights reserved. // #ifndef __Kings__Rusted_Iron__ #define __Kings__Rusted_Iron__ #include "Leadwerks.h" using namespace Leadwerks; class Rusted_Iron// : public Model { private: Model *Full, *P1, *P2, *P3; public: Rusted_Iron(); ~Rusted_Iron(); void Break(); }; #endif /* defined(__Kings__Rusted_Iron__) */ app.cpp #include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } Vec3 camerarotation; #if defined (PLATFORM_WINDOWS) || defined (PLATFORM_MACOS) #else #endif bool App::Start() { //Create a window window = Window::Create("Kings"); //Create a context context = Context::Create(window); //Create a world world = World::Create(); Light *tLight=DirectionalLight::Create(); tLight->SetRotation(0,45,45); //Create a camera camera = Camera::Create(); camera->Move(0,-5,-5); camera->SetRotation(0, 0, 0); //Hide the mouse cursor window->HideMouse(); Rusted_Iron *mBlock=new Rusted_Iron;//my instance of my custom class Model *ground=Model::Box();//my ground that is moving and not supposed to ground->SetShape(Shape::Load("Models/Rusted_Iron/Rusted_Iron.phy")); ground->SetScale(10.0, 0.1, 10.0); ground->SetMaterial(Material::Load("Models/Rusted_Iron/Rusted_Iron.mat")); ground->SetPosition(0,-8,0); /* std::string mapname = System::GetProperty("map","Maps/start.map"); Map::Load(mapname); */ //Move the mouse to the center of the screen window->SetMousePosition(context->GetWidth()/2,context->GetHeight()/2); return true; } bool App::Loop() { //Close the window to end the program if (window->Closed()) return false; //Keyboard movement float strafe = (window->KeyDown(Key:) - window->KeyDown(Key::A))*Time::GetSpeed() * 0.05; float move = (window->KeyDown(Key::W) - window->KeyDown(Key::S))*Time::GetSpeed() * 0.05; camera->Move(strafe,0,move); //Get the mouse movement float sx = context->GetWidth()/2; float sy = context->GetHeight()/2; Vec3 mouseposition = window->GetMousePosition(); float dx = mouseposition.x - sx; float dy = mouseposition.y - sy; //Adjust and set the camera rotation camerarotation.x += dy / 10.0; camerarotation.y += dx / 10.0; camera->SetRotation(camerarotation); //Move the mouse to the center of the screen window->SetMousePosition(sx,sy); if(window->KeyHit(Key::Escape)) return false; Time::Update(); world->Update(); world->Render(); context->Sync(false); return true; } please help. so confused i was like WTF when it first happened. Though i was seeing things. attached is an exe so you can see what it is doing right off the bat for some reason, i think that my custom object data is being over written by the collision function. memory bleed over. It seams that in my custom object when i cast entity0 to mBlock, Full stays the same then P1 becomes the ground. The P2 and P3 are both 'forgotten' Quote bool Life() { while(death=false) { if(death==true) return death; } } I have found the secret to infinite life Did I help you out? Like my post! Link to comment Share on other sites More sharing options...
tjheldna Posted June 8, 2013 Share Posted June 8, 2013 Hrmm looks like you are casting entity0 to Rusted_Iron* however Rusted_Iron* is not derived from the entity class in any way and can't see how this would work. Rusted_Iron*mBlock = reinterpret_cast<Rusted_Iron*>(&entity0); If you uncomment out (not sure if you can call 'this' till the this is fully instantiated? maybe do it in the first game loop) this->Full->SetUserData(this); change in the Collision hook.... Rusted_Iron *mBlock = reinterpret_cast<Rusted_Iron*>(&entity0->GetUserData()); if(mBlock) { mBlock->Break(); } Not sure if that is it, but it maybe is a place to start. Your demo didn't work btw... 1 Quote Link to comment Share on other sites More sharing options...
xtreampb Posted June 8, 2013 Author Share Posted June 8, 2013 ok so this works fine. now just need to fix my models. time to talk to my modeler. Quote bool Life() { while(death=false) { if(death==true) return death; } } I have found the secret to infinite life Did I help you out? Like my post! Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.