Panda3D
Loading...
Searching...
No Matches
odeUtil.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file odeUtil.cxx
10 * @author joswilso
11 * @date 2006-12-27
12 */
13
14#include "odeUtil.h"
15
16dReal OdeUtil::OC_infinity = dInfinity;
17
18/**
19 * Returns the joint that connects the given bodies.
20 */
22get_connecting_joint(const OdeBody &body1, const OdeBody &body2) {
23 return OdeJoint(dConnectingJoint(body1.get_id(),body2.get_id()));
24}
25
26/**
27 * Returns a collection of joints connecting the specified bodies.
28 */
30get_connecting_joint_list(const OdeBody &body1, const OdeBody &body2) {
31 const int max_possible_joints = std::min(body1.get_num_joints(), body1.get_num_joints());
32
33 dJointID *joint_list = (dJointID *)PANDA_MALLOC_ARRAY(max_possible_joints * sizeof(dJointID));
34 int num_joints = dConnectingJointList(body1.get_id(), body2.get_id(),
35 joint_list);
36 OdeJointCollection joints;
37 for (int i = 0; i < num_joints; i++) {
38 joints.add_joint(OdeJoint(joint_list[i]));
39 }
40
41 PANDA_FREE_ARRAY(joint_list);
42 return joints;
43}
44
45/**
46 * Returns 1 if the given bodies are connected by a joint, returns 0
47 * otherwise.
48 */
50are_connected(const OdeBody &body1, const OdeBody &body2) {
51 return dAreConnected(body1.get_id(),body2.get_id());
52}
53
54/**
55 * Returns 1 if the given bodies are connected by a joint that does not match
56 * the given joint_type, returns 0 otherwise. This is useful for deciding
57 * whether to add contact joints between two bodies: if they are already
58 * connected by non-contact joints then it may not be appropriate to add
59 * contacts, however it is okay to add more contact between bodies that
60 * already have contacts.
61 */
64 const OdeBody &body2,
65 const int joint_type) {
66 return dAreConnectedExcluding(body1.get_id(),
67 body2.get_id(),
68 joint_type);
69}
70
71/**
72 * Given two geometry objects that potentially touch (geom1 and geom2),
73 * generate contact information for them. Returns an OdeCollisionEntry.
74 */
75PT(OdeCollisionEntry) OdeUtil::
76collide(const OdeGeom &geom1, const OdeGeom &geom2, const short int max_contacts) {
77 dContactGeom *contact_list = (dContactGeom *)PANDA_MALLOC_ARRAY(max_contacts * sizeof(dContactGeom));
78 int num_contacts = dCollide(geom1.get_id(), geom2.get_id(), max_contacts, contact_list, sizeof(dContactGeom));
79 PT(OdeCollisionEntry) entry = new OdeCollisionEntry();
80 entry->_geom1 = geom1.get_id();
81 entry->_geom2 = geom2.get_id();
82 entry->_body1 = dGeomGetBody(geom1.get_id());
83 entry->_body2 = dGeomGetBody(geom2.get_id());
84 entry->_num_contacts = num_contacts;
85 entry->_contact_geoms = new OdeContactGeom[num_contacts];
86 for (int i = 0; i < num_contacts; i++) {
87 entry->_contact_geoms[i] = contact_list[i];
88 }
89
90 PANDA_FREE_ARRAY(contact_list);
91 return entry;
92}
93
94OdeGeom OdeUtil::
95space_to_geom(const OdeSpace &space) {
96 return OdeGeom((dGeomID)space.get_id());
97}
dBodyID get_id() const
Returns the underlying dBodyID.
Definition odeBody.I:28
A class used to hold information about a collision that has occurred.
dGeomID get_id() const
Returns the underlying dGeomID.
Definition odeGeom.I:28
dSpaceID get_id() const
Returns the underlying dSpaceID.
Definition odeSpace.I:28
static OdeJointCollection get_connecting_joint_list(const OdeBody &body1, const OdeBody &body2)
Returns a collection of joints connecting the specified bodies.
Definition odeUtil.cxx:30
static int are_connected(const OdeBody &body1, const OdeBody &body2)
Returns 1 if the given bodies are connected by a joint, returns 0 otherwise.
Definition odeUtil.cxx:50
static OdeJoint get_connecting_joint(const OdeBody &body1, const OdeBody &body2)
Returns the joint that connects the given bodies.
Definition odeUtil.cxx:22
static int are_connected_excluding(const OdeBody &body1, const OdeBody &body2, const int joint_type)
Returns 1 if the given bodies are connected by a joint that does not match the given joint_type,...
Definition odeUtil.cxx:63
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.