O.D.E. in Darkplaces?
O.D.E. in Darkplaces?
Hello!
Anyone knows how to implement the O.D.E. (Open Dynamics Engine) Physics, in Darkplaces to make whells or barrels. Thnakx
Thorn
Anyone knows how to implement the O.D.E. (Open Dynamics Engine) Physics, in Darkplaces to make whells or barrels. Thnakx
Thorn
Place the DLL in the the directory where darkplaces.exe resides. Enable ode with +physics_ode 1 from the command-line, or from the console with physics_ode 1thorn3001 wrote:I found a. DLL, but I´m blank
The DLL will have to have been compiled with double precision math (--enable-double-precision). I have no idea if this is the default from the builds you can find precompiled.
I am not sure what you mean by "whells and barrels"... but
You can enable ode on items by modifying something such as PlaceItem() or similar.
Code: Select all
void PlaceItem()
{
self.velocity = '0 0 0';
self.origin_z = self.origin_z + 6;
//ODE
// these are or can be set up in the map file
// by adding the keys movetype, solid, mass
self.movetype = MOVETYPE_PHYSICS;
self.solid = SOLID_PHYSICS_BOX;
self.mass = 0.25;
// this enables ODE on the object
physics_enable(self, 1);
}
You could modify T_RadiusDamage by adding something like
Code: Select all
physics_addforce(entity, '10000 10000 10000',origin);
// enable or disable physics on object
void(entity e, vector force, vector force_pos) physics_addforce
// apply a force from certain origin, length of force vector is power of force
You can find these and more in dpdefs.qc in the newest darkplaces SVN.
This may or may not be correct. I really haven't messed with it much.
-
- Posts: 1395
- Joined: Tue Feb 24, 2009 4:39 pm
- Location: Italy
Where is it possible to find additional informations about this very interesting feature? For example how to:
1) add ropes or similar
2) make enemies get hurt by physics objects
3) create ragdolls(I know this is near impossible!)
4) add physics to every map item
Just an information: every object created in ode (vehicles, springs, etc.) are usable in DP?
Thanks!!
1) add ropes or similar
2) make enemies get hurt by physics objects
3) create ragdolls(I know this is near impossible!)
4) add physics to every map item
Just an information: every object created in ode (vehicles, springs, etc.) are usable in DP?
Thanks!!
dpdefs.qctoneddu2000 wrote:Where is it possible to find additional informations about this very interesting feature?
or you could look through the darkplaces source. I'm not aware of any additional documentation anywhere. Reading through the ODE documentation couldn't possibly hurt though.
Do something like find the objects (velocity / mass) * some damage for a touch on classname player if the velocity is > something? This seems like it would be pretty trivial to do...toneddu2000 wrote:Where is it possible to find additional
2) make enemies get hurt by physics objects
I think Alien Arena (not quake1) did this with ODE. So I believe it could be possible with the right QC, but I don't think anyone has bothered to attempt this thus far.toneddu2000 wrote:Where is it possible to find additional
3) create ragdolls(I know this is near impossible!)
The code I posted already does this in the most generic fashion possible...toneddu2000 wrote:Where is it possible to find additional
4) add physics to every map item
What do you mean by "usable"?toneddu2000 wrote:Where is it possible to find additional
Just an information: every object created in ode (vehicles, springs, etc.) are usable in DP?
--
I think it should be noted this is VERY buggy. For instance, the objects that are physics enabled bug depending on their angles it seems. You can hack in a really ugly "fix" to reset the physics by
adding something like
Code: Select all
//global
.vector oldangles;
// in spawn function
self.oldangles = self.angles;
self.think = FixAngles;
self.nextthink = time + somearbitrarynumber;
//think function
void FixAngles
{
if (self.movetype == MOVETYPE_PHYSICS)
{
if (self.angles != self.oldangles && self.velocity != '0 0 0')
{
// remove physics
physics_enable(self, 0);
// restore original angles
self.angles = self.oldangles;
// restore physics (because the origin may change for
// some reason or another and we want it to drop to the
// floor again)
physics_enable(self, 1);
}
}
}
Using
self.solid = SOLID_BSD;
for trimesh collisions rather than SOLID_PHYSICS_* seems to give better results (no need to restore the original angles I believe) at the cost of FPS. This is not a minor cost, however. It is a HUGE cost.
This is the relevant information from dpdefs.qc
This is all the "documentation" that exists that I am aware of...
Code: Select all
//DP_PHYSICS
//idea: LordHavoc
//darkplaces implementation: LordHavoc, divVerent
//constant definitions:
float MOVETYPE_PHYSICS = 32;
float SOLID_PHYSICS_BOX = 32;
float SOLID_PHYSICS_SPHERE = 33;
float SOLID_PHYSICS_CAPSULE = 34;
float JOINTTYPE_POINT = 1; // point; uses origin (anchor)
float JOINTTYPE_HINGE = 2; // hinge; uses origin (anchor) and angles (axis)
float JOINTTYPE_SLIDER = 3; // slider; uses angles (axis)
float JOINTTYPE_UNIVERSAL = 4; // universal; uses origin (anchor) and angles (forward is axis1, up is axis2)
float JOINTTYPE_HINGE2 = 5; // hinge2; uses origin (anchor), angles (axis1), velocity (axis2)
//field definitions:
.float mass;
.float bouncefactor;
.float bouncestop;
.float jointtype; // see JOINTTYPE_ definitions above
// common joint properties:
// .entity aiment, enemy; // connected objects
// .vector movedir;
// for a spring:
// movedir_x = spring constant (force multiplier, must be > 0)
// movedir_y = spring dampening constant to prevent oscillation (must be > 0)
// movedir_z = spring stop position (+/-)
// for a motor:
// movedir_x = desired motor velocity
// movedir_y = -1 * max motor force to use
// movedir_z = stop position (+/-), set to 0 for no stop
// note that ODE does not support both in one anyway
//description:
//various physics properties can be defined in an entity and are executed via
//ODE
//builtin definitions:
void(entity e, float physics_enabled) physics_enable = #540; // enable or disable physics on object
void(entity e, vector force, vector force_pos) physics_addforce = #541; // apply a force from certain origin, length of force vector is power of force
void(entity e, vector torque) physics_addtorque = #542; // add relative torque
//description: provides Open Dynamics Engine support, requires extenal dll to be present or engine compiled with statical link option
//be sure to checkextension for it to know if library i loaded and ready, also to enable physics set "physice_ode" cvar to 1
//note: this extension is highly experimental and may be unstable
//note: use SOLID_BSP on entities to get a trimesh collision models on them
-
- Posts: 1395
- Joined: Tue Feb 24, 2009 4:39 pm
- Location: Italy
Thanks apolluwn for your clarification! I took a look at alien arena 2011 source at the ragdoll.c file and I'll try to insert it into darkplaces in the next week.
According to the example you post, I had success on the first part
now items fall down to the ground, cool!
but if i open weapons.qc and, for example inside void() T_MissileTouch = {} for rocket launcher
if I put after T_RadiusDamage (self, self.owner, 120, other);
this
compiler returns me an error saying: ""physics_addforce already declared in dpextensions.qc"
According to the example you post, I had success on the first part
Code: Select all
void PlaceItem()
{
self.velocity = '0 0 0';
self.origin_z = self.origin_z + 6;
//ODE
// these are or can be set up in the map file
// by adding the keys movetype, solid, mass
self.movetype = MOVETYPE_PHYSICS;
self.solid = SOLID_PHYSICS_BOX;
self.mass = 0.25;
// this enables ODE on the object
physics_enable(self, 1);
}
but if i open weapons.qc and, for example inside void() T_MissileTouch = {} for rocket launcher
if I put after T_RadiusDamage (self, self.owner, 120, other);
this
Code: Select all
physics_addforce(entity, '10000 10000 10000',origin);
i know this has nothing to do with code. but i found this with nexuiz.
http://www.youtube.com/watch?v=ZrNR3vnD9P4
http://www.youtube.com/watch?v=ZrNR3vnD9P4
-
- Posts: 1395
- Joined: Tue Feb 24, 2009 4:39 pm
- Location: Italy
Well... You won't be able to drop in ragdoll.c and get it working if that's what you are saying... I didn't mean to give you that impression. I just remembered that AA had implemented ODE and also ragdoll on IQM models so I imagine that Darkplaces could feasibly accomplish this with enough effort.toneddu2000 wrote:Thanks apolluwn for your clarification! I took a look at alien arena 2011 source at the ragdoll.c file and I'll try to insert it into darkplaces in the next week.
According to the example you post, I had success on the first part
You should place this in T_RadiusDamage instead of the rocket touch. I assume you are using the stock 1.06 progs?toneddu2000 wrote: but if i open weapons.qc and, for example inside void() T_MissileTouch = {} for rocket launcher
if I put after T_RadiusDamage (self, self.owner, 120, other);
thiscompiler returns me an error saying: ""physics_addforce already declared in dpextensions.qc"Code: Select all
physics_addforce(entity, '10000 10000 10000',origin);
The problem is you aren't changing the "entity" or "origin". Both "entity" and "origin" don't actually exist and the compiler
doesn't know what to do it since it's expecting an entity, a vector of the force strength, and a vector for the position of the force.
It would be something like this:
Code: Select all
void(entity inflictor, entity attacker, float damage, entity ignore) T_RadiusDamage =
{
local float points;
local entity head;
local vector org;
head = findradius(inflictor.origin, damage+40);
while (head)
{
if (head != ignore)
{
physics_addforce(head, '1000 1000 1000', inflictor.origin); // entity to apply force to, force size vector 'x y z', origin of force
if (head.takedamage)
{
org = head.origin + (head.mins + head.maxs)*0.5;
points = 0.5*vlen (inflictor.origin - org);
if (points < 0)
points = 0;
points = damage - points;
if (head == attacker)
points = points * 0.5;
if (points > 0)
{
if (CanDamage (head, inflictor))
{ // shambler takes half damage from all explosions
if (head.classname == "monster_shambler")
T_Damage (head, inflictor, attacker, points*0.5);
else
T_Damage (head, inflictor, attacker, points);
}
}
}
}
head = head.chain;
}
};
Error wrote:why not just use Gyro for things like hitting entities away from an explosion?
Gyro is VERY good for what it is and is definitely VERY simple to set up since you can basically drop it in and use the pre-made "macros". I don't believe it relies on any other extensions either which is great for compatibility with whatever engine people wish to use.Nahuel wrote:gyro is very simple and stable!
It isn't without problems, however. It really isn't very stable... It has problems if the velocity is too high or it is changed too quickly (well, this is what it -seems- to be), transitions from air to water/water to air can result in random crashes (particularly if there are several objects moving at a semi-high velocity with a similar origin, the object impacts near enough a waterline, etc ), and the collision between objects can look pretty bad even if you adjust the bounding box size.
That being said, I don't believe any of these are really deal breakers by any means since most of these little hiccups can be worked around or fixed if you put the time in.
There is also the problem of items falling into the void, but this happens even with ODE under the right circumstances (object close to a wall and a large vector used for the force). This doesn't seem to be a problem when using SOLID_BSP, but, unfortunately, it's too costly to be used on anything but a few objects.
Using ODE simply for the object collisions is worthwhile I suppose despite the problems with tracelines after an objects angles have changed. It really does make it look more natural...
I haven't really looked through the ODE stuff in darkplaces enough to know for sure, but I think that once you physics_enable the object it will use ODE for most(all?) of the physics anyways. If this is correct then you should be able to use gyro with ODE regardless? I don't know if this is really the case, but it appears to take things like .gravity/.velocity/etc into consideration and run it through ODE if enabled... at least it appears that way from a cursory glance of world.c
It's probably bashing things in every way possible, but a quick test to physics_enable an object then use gyro to create a force does appear to result in it using ODE for collisions and gyro's nicely done forces/etc seem to work well with it, but this may just be asking for trouble...
Last edited by apolluwn on Wed Jul 13, 2011 2:25 am, edited 1 time in total.