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
14#include "bulletMinkowskiSumShape.h"
15
16#include "bulletWorld.h"
17
18 TypeHandle 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 */
67 void 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 */
78 void 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 */
109 void BulletMinkowskiSumShape::
110 register_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 */
118 void BulletMinkowskiSumShape::
119 write_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 */
134 int BulletMinkowskiSumShape::
135 complete_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 */
163 bool BulletMinkowskiSumShape::
164 require_fully_complete() const {
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 */
174 TypedWritable *BulletMinkowskiSumShape::
175make_from_bam(const FactoryParams &params) {
176 // create a default BulletMinkowskiSumShape
177 BulletMinkowskiSumShape *param = new 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 */
191 void 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}
parse_params
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
bulletMinkowskiSumShape.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bulletWorld.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
BamReader::read_pointer
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition bamReader.cxx:610
BamReader::get_factory
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition bamReader.I:177
BamWriter::write_pointer
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
Definition bamWriter.cxx:317
BulletMinkowskiSumShape
Definition bulletMinkowskiSumShape.h:28
BulletMinkowskiSumShape::require_fully_complete
virtual bool require_fully_complete() const
Some objects require all of their nested pointers to have been completed before the objects themselve...
Definition bulletMinkowskiSumShape.cxx:164
BulletMinkowskiSumShape::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition bulletMinkowskiSumShape.cxx:119
BulletMinkowskiSumShape::register_with_read_factory
static void register_with_read_factory()
Tells the BamReader how to create objects of type BulletShape.
Definition bulletMinkowskiSumShape.cxx:110
BulletMinkowskiSumShape::complete_pointers
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
Definition bulletMinkowskiSumShape.cxx:135
BulletShape
Definition bulletShape.h:27
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition datagramIterator.h:30
DatagramIterator::get_stdfloat
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
Definition datagramIterator.I:242
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
Datagram::add_stdfloat
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
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition factoryParams.h:36
Factory::register_factory
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
TransformState
Indicates a coordinate-system transform on vertices.
Definition transformState.h:54
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition typedWritable.h:35
TypedWritable::fillin
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...
Definition typedWritable.cxx:103
TypedWritable::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition typedWritable.cxx:54
TypedWritable::complete_pointers
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().
Definition typedWritable.cxx:81