Panda3D
Loading...
Searching...
No Matches
bulletMinkowskiSumShape.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 bulletMinkowskiSumShape.cxx
10 * @author enn0x
11 * @date 2013-08-15
12 */
13
15
16#include "bulletWorld.h"
17
18TypeHandle BulletMinkowskiSumShape::_type_handle;
19
20/**
21 *
22 */
23BulletMinkowskiSumShape::
24BulletMinkowskiSumShape(const BulletShape *shape_a, const BulletShape *shape_b) :
25 _shape_a(shape_a),
26 _shape_b(shape_b) {
27
28 nassertv(shape_a->is_convex());
29 nassertv(shape_b->is_convex());
30
31 const btConvexShape *ptr_a = (const btConvexShape *)shape_a->ptr();
32 const btConvexShape *ptr_b = (const btConvexShape *)shape_b->ptr();
33
34 _shape = new btMinkowskiSumShape(ptr_a, ptr_b);
35 _shape->setUserPointer(this);
36}
37
38/**
39 *
40 */
41BulletMinkowskiSumShape::
42BulletMinkowskiSumShape(const BulletMinkowskiSumShape &copy) {
43 LightMutexHolder holder(BulletWorld::get_global_lock());
44
45 _shape_a = copy._shape_a;
46 _shape_b = copy._shape_b;
47
48 const btConvexShape *ptr_a = (const btConvexShape *)_shape_a->ptr();
49 const btConvexShape *ptr_b = (const btConvexShape *)_shape_b->ptr();
50
51 _shape = new btMinkowskiSumShape(ptr_a, ptr_b);
52 _shape->setUserPointer(this);
53}
54
55/**
56 *
57 */
58btCollisionShape *BulletMinkowskiSumShape::
59ptr() const {
60
61 return _shape;
62}
63
64/**
65 *
66 */
67void BulletMinkowskiSumShape::
68set_transform_a(const TransformState *ts) {
69 LightMutexHolder holder(BulletWorld::get_global_lock());
70
71 nassertv(ts);
72 _shape->setTransformA(TransformState_to_btTrans(ts));
73}
74
75/**
76 *
77 */
78void BulletMinkowskiSumShape::
79set_transform_b(const TransformState *ts) {
80 LightMutexHolder holder(BulletWorld::get_global_lock());
81
82 nassertv(ts);
83 _shape->setTransformB(TransformState_to_btTrans(ts));
84}
85
86/**
87 *
88 */
89CPT(TransformState) BulletMinkowskiSumShape::
90get_transform_a() const {
91 LightMutexHolder holder(BulletWorld::get_global_lock());
92
93 return btTrans_to_TransformState(_shape->getTransformA());
94}
95
96/**
97 *
98 */
99CPT(TransformState) BulletMinkowskiSumShape::
100get_transform_b() const {
101 LightMutexHolder holder(BulletWorld::get_global_lock());
102
103 return btTrans_to_TransformState(_shape->GetTransformB());
104}
105
106/**
107 * Tells the BamReader how to create objects of type BulletShape.
108 */
109void BulletMinkowskiSumShape::
110register_with_read_factory() {
111 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
112}
113
114/**
115 * Writes the contents of this object to the datagram for shipping out to a
116 * Bam file.
117 */
119write_datagram(BamWriter *manager, Datagram &dg) {
120 BulletShape::write_datagram(manager, dg);
121 dg.add_stdfloat(get_margin());
122
123 // parameters to serialize: _shape_a, _shape_b, _transform_a, _transform_b
124 manager->write_pointer(dg, _shape_a);
125 manager->write_pointer(dg, _shape_b);
126 manager->write_pointer(dg, get_transform_a());
127 manager->write_pointer(dg, get_transform_b());
128}
129
130/**
131 * Receives an array of pointers, one for each time manager->read_pointer()
132 * was called in fillin(). Returns the number of pointers processed.
133 */
135complete_pointers(TypedWritable **p_list, BamReader *manager) {
136 int pi = BulletShape::complete_pointers(p_list, manager);
137
138 _shape_a = DCAST(BulletShape, p_list[pi++]);
139 _shape_b = DCAST(BulletShape, p_list[pi++]);
140
141 const TransformState *transform_a = DCAST(TransformState, p_list[pi++]);
142 const TransformState *transform_b = DCAST(TransformState, p_list[pi++]);
143
144 const btConvexShape *ptr_a = (const btConvexShape *)_shape_a->ptr();
145 const btConvexShape *ptr_b = (const btConvexShape *)_shape_b->ptr();
146
147 _shape = new btMinkowskiSumShape(ptr_a, ptr_b);
148 _shape->setUserPointer(this);
149 _shape->setMargin(_margin);
150
151 set_transform_a(transform_a);
152 set_transform_b(transform_b);
153
154 return pi;
155}
156
157/**
158 * Some objects require all of their nested pointers to have been completed
159 * before the objects themselves can be completed. If this is the case,
160 * override this method to return true, and be careful with circular
161 * references (which would make the object unreadable from a bam file).
162 */
165 // We require the shape pointers to be complete before we add them.
166 return true;
167}
168
169/**
170 * This function is called by the BamReader's factory when a new object of
171 * type BulletShape is encountered in the Bam file. It should create the
172 * BulletShape and extract its information from the file.
173 */
174TypedWritable *BulletMinkowskiSumShape::
175make_from_bam(const FactoryParams &params) {
176 // create a default BulletMinkowskiSumShape
178 DatagramIterator scan;
179 BamReader *manager;
180
181 parse_params(params, scan, manager);
182 param->fillin(scan, manager);
183
184 return param;
185}
186
187/**
188 * This internal function is called by make_from_bam to read in all of the
189 * relevant data from the BamFile for the new BulletShape.
190 */
191void BulletMinkowskiSumShape::
192fillin(DatagramIterator &scan, BamReader *manager) {
193 BulletShape::fillin(scan, manager);
194 nassertv(_shape == nullptr);
195
196 _margin = scan.get_stdfloat();
197
198 // parameters to serialize: _shape_a, _shape_b, _transform_a, _transform_b
199 manager->read_pointer(scan);
200 manager->read_pointer(scan);
201 manager->read_pointer(scan);
202 manager->read_pointer(scan);
203}
void parse_params(const FactoryParams &params, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
Definition bamReader.I:275
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition bamReader.I:177
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
virtual bool require_fully_complete() const
Some objects require all of their nested pointers to have been completed before the objects themselve...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
A class to retrieve the individual data elements previously stored in a Datagram.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
Definition datagram.I:133
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Definition factory.I:73
Similar to MutexHolder, but for a light mutex.
Indicates a coordinate-system transform on vertices.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().