Penumbra like code

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Penumbra like code

Postby wrekwired » Tue May 01, 2012 2:24 pm

Anyone accomplish to create a penumbra like code?
I'm not that of a programmer guy thats why i use 3DGS which use lite-c and newton 2 wrapper. i'm able to move objects arround by using NewtonBodySetVelocity(). My problems are how do i hold the object to where i click it. Eveytime i click an object it automaticaly sets the velocity and move the object from where i click it going to objects origin making it like i'm holding it at the center. Other problems i face are when i fush the objects againts a wall it shakes to much and when i drag a smaller object to bigger once which should have greater mass it always push that onject as if mass does not matter. And also how do i rotate objects while adding velocity?

Sorry for asking allot of questions. I have gone through allot of researchest already and my programming skills is not that advance and i have waited and waited for a reply from 3DGS community but no luck from there. Thanks!
wrekwired
 
Posts: 6
Joined: Tue May 01, 2012 1:54 pm

Re: Penumbra like code

Postby JoeJ » Wed May 02, 2012 10:05 am

Ah, my favourite question to answer, again... :)

Try to avoid setting velocities directly. Let Newton calculate them.
Example: Box rests on floor, you try to move it downwards.
But because way down is blocked, it's impossible for the box to have a downwards velocity, and simulation will start jittering.

Solution: Use forces instead, so Newton can solve that problem for you.
You already know the angular / linear velocity to bring a body to its target orientation / position over time?
So you only need to convert the volecities to forces, pseudo-code from my older posts:



Angular part:

Code: Select all
vector targetAngVel = the angular velocity you want to reach the targe orientation;
vector curAngVel = BodyGetOmega()

targetAngVel -= curAngVel * 1.0; // take actual angvel in account - something between 0.0 and 1.0; recommended >0.5

vector torque = targetAngVel / timestep;
torque = matrix.Unrotate (torque); // matrix = BodyGetMatrix
torque[0] *= Ixx; // Inertia from BodyGetMassMatrix
torque[1] *= Iyy;
torque[2] *= Izz;
torque = matrix.Rotate (torque);

torque *= 0.1; // something between 0.0 and 1.0; recommended <0.5, high value could generate overspin

BodyAddTorque (torque)



The linear part is easy:

Code: Select all
force = (targetLinVel - currentLinVel) * (mass / timestep);
// you may want to subtract gravity here, to get perfect handling
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Penumbra like code

Postby wrekwired » Sat May 05, 2012 5:30 am

Thanks joe, i was away for quite awhile. I got get the codes but not the angular / linear velocity thing. I'm not that good in C++ to lite-c. I'll try to research more on to thats.
wrekwired
 
Posts: 6
Joined: Tue May 01, 2012 1:54 pm

Re: Penumbra like code

Postby JoeJ » Mon May 07, 2012 11:26 am

You may also look at this thread: http://newtondynamics.com/forum/viewtopic.php?f=9&t=7199

Maybe it may be easier to use the kinematic joint, if that's available from your wrapper.
Also there's a link to an older post with complete code for my method, including calculating velocities.
But note that my method always operates on center of mass. Handling an offset position like penumbra needs additional work.
Kinematic joint includes support for that.
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Penumbra like code

Postby wrekwired » Mon May 07, 2012 12:26 pm

I thought of using custom joints like kinematic joint since using force is giving me allot of throuble. no to mention after fixing the problem on how to apply angular force the onject it just lead mo to another problem like how i limit the camera from looking away from the object if an heavier object is selected then it leads to another problem. It was then i decided to use joints since i can solve all the objects and character problem at the same time that way. Proble is 3DGS newton wrapper don't have kinematic joints so i'm using the standars joints like ball then destroy them when not needed. I encounter the jittering problem when onject is pushed against a wall or something but found out that it was the parent joint that was jittering when pushed against the wall and making it none collidable object fix it. But still i want to try kinematic joints. maybe it will improve my code if ever.
wrekwired
 
Posts: 6
Joined: Tue May 01, 2012 1:54 pm

Re: Penumbra like code

Postby wrekwired » Tue May 08, 2012 8:09 am

i just checked 3DGS newton wrapper and it does have kinematic joints. problem is i don't know how to use them. I'm just used to creating joints like this. But have no idae about custom koints.
Code: Select all
// 1 meter = 32 quants
float QUANTTOMETER = 0.03125;
NewtonJoint* joint1;

joint1 =  NewtonConstraintCreateBall (nworld, vectorf((hand_ent.x)*QUANTTOMETER,hand_ent.y*QUANTTOMETER,(hand_ent.z)*QUANTTOMETER), child_j, parent_j);


And how do i connect a child joint to a non newton body like a door and it's frame should not move with it.
wrekwired
 
Posts: 6
Joined: Tue May 01, 2012 1:54 pm

Re: Penumbra like code

Postby JoeJ » Tue May 08, 2012 1:32 pm

NewtonConstraintCreateBall is an example of the 'old' build in joints.
NewtonConstraintCreateUserJoint is the one and only new joint. You can make pretty anything out of it: hinge, ball-socket, corkscrew, whatever.
Using it is not so easy, but most if not all joints you will ever need are ready to use using the joint library ("dCustomJoints"-source folder).
All Joints from that lib are based on the UserJoint, also the kinematic joint.

The porblems are:
* There is no manual. (Correct me if i'm wrong) So we need to use the code itself for documentation.
* The lib is not part of Newton itself, but it seems it is covered by your wrapper.

We want to use kinematic controller, so we open it's header file from the dCustomJoints folder: CustomKinematicController.h:

class JOINTLIBRARY_API CustomKinematicController: public NewtonCustomJoint
{
public:
CustomKinematicController (const NewtonBody* body, const dVector& attachmentPointInGlobalSpace);
...

This is the constructor of the joint. So we create it using:
Code: Select all
myJoint = new CustomKinematicController (myBarrel, myPickPositionPoint_usuallyBarrelCenter);


...
void SetPickMode (int mode); // mode = 1 -> constrain orientation, 0-> constrain position only
void SetMaxLinearFriction(dFloat accel); // how "strong" are the constraints?
void SetMaxAngularFriction(dFloat alpha);
...

Setup our joint:
Code: Select all
myJoint->SetMaxLinearFriction(some scene dependent value);
myJoint->SetMaxAngularFriction(some scene dependent value);
myJoint->SetPickMode (1);


and further we see:
...

void SetTargetRotation (const dQuaternion& rotation); // Set the target stuff...
void SetTargetPosit (const dVector& posit);
void SetTargetMatrix (const dMatrix& matrix);
...
so at runtime we want to update our hand position (target):
Code: Select all
matrix me = BodyGetMatrix (player);
me.posit += handOffsetVector;
myJoint->SetTargetMatrix (me);



wrekwired wrote:And how do i connect a child joint to a non newton body like a door and it's frame should not move with it.

Example:
joint = NewtonConstraintCreateBall ( const NewtonWorld* newtonWorld, const dFloat* pivotPoint, const NewtonBody* childBody, const NewtonBody* parentBody)
Set child body to the door, but parent body to null.
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Penumbra like code

Postby wrekwired » Wed May 09, 2012 1:45 am

Thanks allot Joej. You're really a big help for my work. Just check the libraries and it cameup with this APIs.

Code: Select all
// Kinematic control joint
JOINTLIBRARY_API NewtonUserJoint *CreateCustomKinematicController (const NewtonBody* targetBody, dFloat* attachmentPointInGlobalSpace);
JOINTLIBRARY_API void CustomKinematicControllerSetPickMode (const NewtonUserJoint *pick, int mode);
JOINTLIBRARY_API void CustomKinematicControllerSetMaxLinearFriction(const NewtonUserJoint *pick, dFloat accel);
JOINTLIBRARY_API void CustomKinematicControllerSetMaxAngularFriction(const NewtonUserJoint *pick, dFloat alpha);
JOINTLIBRARY_API void CustomKinematicControllerSetTargetPosit (const NewtonUserJoint *pick, dFloat* posit);
JOINTLIBRARY_API void CustomKinematicControllerSetTargetRotation (const NewtonUserJoint *pick, dFloat* rotation);
JOINTLIBRARY_API void CustomKinematicControllerSetTargetMatrix (const NewtonUserJoint *pick, dFloat* matrix);
JOINTLIBRARY_API void CustomKinematicControllerGetTargetMatrix (const NewtonUserJoint *pick, dFloat* matrix);


which will make it easier with allot more APIs including player controller function.. :D
wrekwired
 
Posts: 6
Joined: Tue May 01, 2012 1:54 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron