Deleting Custom Player Controller

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Deleting Custom Player Controller

Postby derdragon » Tue Nov 17, 2009 11:52 am

I'm having some trouble destroying my custom player controller joint. From what I read here on the forums, I believe I'm just supposed to delete the instance I created with new:
Code: Select all
if(jointtype=="hover") {
    set(VAR_TYPEINT,JT_HOVER);
    dMatrix globalFrame (GetIdentityMatrix());
    globalFrame.m_front = dVector (0.0f, 1.0f, 0.0f, 0.0f);        // up direction in global Space
    globalFrame.m_up    = dVector (1.0f, 0.0f, 0.0f, 0.0f);        // front direction in global Space
    globalFrame.m_right = globalFrame.m_front * globalFrame.m_up;  // strafing direction in global Space
    CoreHoverJoint* hjoint = new CoreHoverJoint(globalFrame, body_child, get_float(VAR_HOVER), get_float(VAR_HOVERRADIUS)/NEWTON_SCALE);
    hjoint->D = this;
    setpointer(VAR_NEWTONJOINT,(int)hjoint);
}


Later on when the joint is being deleted, I get "BEGINNING DELETION..." but never make it to "DONE DELETING...", I get a crash with NewtonForEachJointDo(), I'm not sure where that would be getting called.

Code: Select all
if(get_int(VAR_TYPEINT)==JT_HOVER) {
    std::cout << "BEGINNING DELETION OF HOVER JOINT" << std::endl;
    CoreHoverJoint* J = (CoreHoverJoint*)get_pointer(VAR_NEWTONJOINT);
    delete J;
    std::cout << "DONE DELETING HOVER JOINT" << std::endl;
}


This is pretty much the entirety of my "Hover Joint" code.

Code: Select all
class CoreHoverJoint: public CustomPlayerController
{
   public:
        Datum* D;
        CoreHoverJoint(const dMatrix& globalFrame, NewtonBody* player, dFloat stairStepFactor, dFloat cushion) :CustomPlayerController (globalFrame, player, stairStepFactor, cushion) {
            SetMaxSlope(30.0f * 3.1416f / 180.0f);
        }
        ~CoreHoverJoint() {
        }
        virtual void SubmitConstraints (dFloat timestep, int threadId) {
            float yaw = D->get_float(VAR_YAW);
            Ogre::Vector2 V = D->get_vec2(VAR_VELOCITY);
            SetVelocity (V.x, V.y, yaw);
            CustomPlayerController::SubmitConstraints (timestep, threadId);
        }
};

derdragon
 
Posts: 13
Joined: Fri Aug 03, 2007 12:56 pm

Re: Deleting Custom Player Controller

Postby Julio Jerez » Tue Nov 17, 2009 12:11 pm

It may be a bug, can you put a test demo?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Deleting Custom Player Controller

Postby derdragon » Tue Nov 17, 2009 1:09 pm

Unfortunately because of the way I set my project up, it'd be really difficult for me to put this into a little test demo. If what I've got there is ok, I will just continue testing on my own then and will post here if I come up with a solution or work around. Thanks for the quick reply.
derdragon
 
Posts: 13
Joined: Fri Aug 03, 2007 12:56 pm

Re: Deleting Custom Player Controller

Postby Julio Jerez » Tue Nov 17, 2009 1:18 pm

you can try pasting the code in any of the SDK demos.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Deleting Custom Player Controller

Postby derdragon » Tue Nov 17, 2009 1:21 pm

Well, that didn't take long...
Code: Select all
CustomPlayerController::~CustomPlayerController()
{
    std::cout << "DELETING CUSTOM PLAYER CONTROLLER" << std::endl;
   /*NewtonReleaseCollision(m_world, m_bodySensorShape);
   NewtonReleaseCollision(m_world, m_stairSensorShape);
   NewtonReleaseCollision(m_world, m_bodyFloorSensorShape);*/
    std::cout << "DONE DELETING CUSTOM PLAYER CONTROLLER" << std::endl;

}


Added some debug lines to CustomPlayerController.cpp and saw that I got to "DELETING.." but not "DONE DELETING..." so a problem existed between them. With those lines commented out, I have no problems.

EDIT: Upon further testing, m_stairSensorShape was null, so I just added if(m_stairSensorShape) before that line.
derdragon
 
Posts: 13
Joined: Fri Aug 03, 2007 12:56 pm

Re: Deleting Custom Player Controller

Postby Julio Jerez » Tue Nov 17, 2009 2:27 pm

derdragon wrote:Added some debug lines to CustomPlayerController.cpp and saw that I got to "DELETING.." but not "DONE DELETING..." so a problem existed between them. With those lines commented out, I have no problems.
EDIT: Upon further testing, m_stairSensorShape was null, so I just added if(m_stairSensorShape) before that line.


I am confused do you mean that if you add a check to see if the test shpe is there it will work.
Also how is is the the shape is NULL?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Deleting Custom Player Controller

Postby derdragon » Wed Nov 18, 2009 3:57 pm

When I did std::cout << m_stairSensorShape << std::endl; I got a 0, which I'm assuming means that the point to the shape is null. I'm still getting some weird behavior with the controller, but I don't know if it's just the way I'm using it. I added if(m_stairSensorShape) before NewtonReleaseCollision(m_world, m_stairSensorShape); so it wouldn't try to release the collision if the collision didn't actually exist.

While I'm on the topic... With this character controller, would my characters actually affect and be affected by objects they're standing on? Example, if I had a see-saw with two character controllers, one at either side, if I dropped one in at a high velocity, should I expect the other object to be launched appropriately? Another example, if I had a spinning disc and walked onto it with a player controller, would it be carried around as the disc moves?
derdragon
 
Posts: 13
Joined: Fri Aug 03, 2007 12:56 pm

Re: Deleting Custom Player Controller

Postby Julio Jerez » Wed Nov 18, 2009 4:09 pm

well they are normal bodies, it should work. The will be an ineteresting test to see.

ther is a Player controller demo in the wiki tutorials, 203
maybe you can try stuff in that framework
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Deleting Custom Player Controller

Postby derdragon » Thu Nov 19, 2009 3:11 pm

From what I can tell, no force is really exerted on the object that the character controller rests on. This would make sense, since the shape is just being cast to it and not actually colliding with it. I was just thinking this over and have an idea, but I'm not sure how practical it is to implement. If I were to create a "joint" between the character controller, and whatever object it's standing on, basically just a ball joint between the two objects, rather than just forcing the position of the character controller with SetMatrix. It'd be nice to be able to do this from within the Character Controller code, but I think I'd need something like NewtonJointSetBody1() where I could assign what body I'm affecting from within that section of code, and I don't know if this is feasible.
derdragon
 
Posts: 13
Joined: Fri Aug 03, 2007 12:56 pm

Re: Deleting Custom Player Controller

Postby Julio Jerez » Thu Nov 19, 2009 3:35 pm

yes you could be right, it is long time since I did not check on that.
but I think that the contact still pushed the body down,

The truth is that I am no sure what would happen. I guess the best is to try, and it is does not work then see if it can be fixed.
mayb adding a down impulse or forces or somethong like that.

Basically you want a user contact, you cosul do tah by cration a joint and keepin teh handle in teh player joint,
the in the call back of teh player joint you detrmine if teh user contact is activated.
you do tha by setting a boller or somethong.

the in the user contact summit contrainrt call back you read the value you set int the player joint if it is true you emit the rows to puch teh su;ortion body, if false you return zero an dteh joiun will do nothing
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron