[NEWTON] Lite-C - How to destroy dynamic objects.

Posted By: msl_manni

[NEWTON] Lite-C - How to destroy dynamic objects. - 09/13/07 15:50

Hi,
I am having problems regarding removing dynamic objects in Newton.
Please help.
Bye,
MSL.
Posted By: msl_manni

Re: [NEWTON] Lite-C - How to destroy dynamic objects. - 09/14/07 06:05

Code:
 
void d_func()
{
my.skill10 = 100;
while(my.skill10 > 0)
{
my.skill10 -= 1;
wait(1);
}
NewtonDestroyBody(nworld, my.skill99);
ent_remove(me);
}

void fireentity()
{
you = ent_create("ball.mdl", &v, d_func);
NewtonBody *body = newton_addentity(you, 10, currentcollisiontype, onforceandtorque); // register entity as physics entity
}



I try to remove the dynamic object from the Newton world after 100 waits, but it gives me crash error and the object is still there.
Posted By: ventilator

Re: [NEWTON] Lite-C - How to destroy dynamic objec - 09/14/07 06:50

i didn't test this earlier but now i noticed it too.

the problem is in newton_addentity():

printf("%d", body);
entity->skill99 = (long)body; // save body pointer with entity
printf("%d", entity->skill99);

lite-c does some strange automatic var conversion. you have to remove the (long).
Posted By: msl_manni

Re: [NEWTON] Lite-C - How to destroy dynamic objec - 09/14/07 07:01

Changed

entity->skill99 = (long)body; // save body pointer with entity
to
entity->skill99 = body; // save body pointer with entity
but it still crashes with the above code and the object is still there.
Posted By: ventilator

Re: [NEWTON] Lite-C - How to destroy dynamic objec - 09/14/07 07:04

please try:

NewtonDestroyBody(nworld, (NewtonBody*)my->skill99);
ent_remove(my);
Posted By: msl_manni

Re: [NEWTON] Lite-C - How to destroy dynamic objec - 09/14/07 07:17

Error E1513
crash in d_func

It still crashes with the above error message when it tries to destroy the newton body.
Posted By: ventilator

Re: [NEWTON] Lite-C - How to destroy dynamic objec - 09/14/07 07:27

hm... this works for me (after i have removed the (long)):
Code:

void test_remove()
{
wait(-3);
NewtonDestroyBody(nworld, (NewtonBody*)my->skill99);
ent_remove(my);
}

void fireentity()
{
var power = 0;
while(mouse_left) // power depends on how long you hold the mouse button
{
power = clamp(power + time_step, 0, 25);
draw_line(vector(10, 40, 0), 0, 100);
draw_line(vector(10, 40, 0), vector(255,255,255), 100);
draw_line(vector(10 + power * 5, 40, 0), vector(255,255,255), 100);
wait(1);
}

VECTOR v;
vec_set(&v, vector(100, 0, 0));
vec_rotate(&v, &camera->pan);
vec_add(&v, &camera->x);

switch(currentcollisiontype)
{
case NEWTON_SPHERE:
you = ent_create("ball.mdl", &v, test_remove);
break;
case NEWTON_BOX:
you = ent_create("crate.mdl", &v, NULL);
break;
[...]

i use the newest free lite-c version.

btw. you can download a cleaned up version of my newton example here.
Posted By: msl_manni

Re: [NEWTON] Lite-C - How to destroy dynamic objec - 09/14/07 08:02

Quote:


you can download a cleaned up version of my newton example





Thanks, your cleaned up version works perfectly. Just dont know why the previous version is giving errors .
Well thanks for the support.

A couple of things more if have them.

1. Player or enemy that can be controlled via newton so that they are always standing upright, only pan and gravity is affected of the newton body.

2. Ragdoll example.

Thanks again for your support.
Posted By: ventilator

Re: [NEWTON] Lite-C - How to destroy dynamic objec - 09/14/07 08:13

for a player you have to use the up-vector joint. i will do examples for things like that but i don't know yet when i will have enough time.

for ragdolls i would wait for the next newton version. it will have a very cool physics driven character animation system. this won't only be useful for ragdolls but it also will automatically adapt the feet when walking up a slope or stair or rebalance the character when it gets pushed and so on.
Posted By: msl_manni

Re: [NEWTON] Lite-C - How to destroy dynamic objec - 09/14/07 08:29

I will try to see the c-examples of Newton for up-vector examples, dont know if I will be able to translate it to LiteC. Please at-least do the up-vector example, for the ragdoll we can wait for the new addition.

One thing else is how do we know about collision response for an object when it is colliding. Say I fire a bullet and when it collides with anything then I would like it to be removed immediately and respond to colliding object also.
Posted By: ventilator

Re: [NEWTON] Lite-C - How to destroy dynamic objec - 09/14/07 08:36

Quote:

One thing else is how do we know about collision response for an object when it is colliding. Say I fire a bullet and when it collides with anything then I would like it to be removed immediately and respond to colliding object also.


for that you can use the material collision callbacks. the newton material system is very powerful and important! this is also something i (or somebody else ) have to cover with some examples. maybe i will find some time in the next 2 or 3 weeks.
Posted By: msl_manni

Re: [NEWTON] Lite-C - How to destroy dynamic objec - 09/14/07 08:56

O.K. Will try to understand how to get collission response in Lite-C, or else you are there .
© 2024 lite-C Forums