Panda3D
Loading...
Searching...
No Matches
bulletPlaneShape.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 bulletPlaneShape.cxx
10 * @author enn0x
11 * @date 2010-01-23
12 */
13
14#include "bulletPlaneShape.h"
15
16#include "bulletWorld.h"
17
18TypeHandle BulletPlaneShape::_type_handle;
19
20/**
21 * Creates a plane shape from a plane definition.
22 */
23BulletPlaneShape::
24BulletPlaneShape(LPlane plane) {
25
26 btVector3 btNormal = LVecBase3_to_btVector3(plane.get_normal());
27
28 _shape = new btStaticPlaneShape(btNormal, plane.get_w());
29 _shape->setUserPointer(this);
30}
31
32/**
33 *
34 */
35BulletPlaneShape::
36BulletPlaneShape(const LVector3 &normal, PN_stdfloat constant) {
37
38 btVector3 btNormal = LVecBase3_to_btVector3(normal);
39
40 _shape = new btStaticPlaneShape(btNormal, constant);
41 _shape->setUserPointer(this);
42}
43
44/**
45 *
46 */
47BulletPlaneShape::
48BulletPlaneShape(const BulletPlaneShape &copy) {
49 LightMutexHolder holder(BulletWorld::get_global_lock());
50
51 btVector3 btNormal = copy._shape->getPlaneNormal();
52 PN_stdfloat constant = (PN_stdfloat)_shape->getPlaneConstant();
53
54 _shape = new btStaticPlaneShape(btNormal, constant);
55 _shape->setUserPointer(this);
56}
57
58/**
59 *
60 */
61btCollisionShape *BulletPlaneShape::
62ptr() const {
63
64 return _shape;
65}
66
67/**
68 *
69 */
70LPlane BulletPlaneShape::
71get_plane() const {
72 LightMutexHolder holder(BulletWorld::get_global_lock());
73
74 btVector3 normal = _shape->getPlaneNormal();
75 return LPlane(normal[0], normal[1], normal[2], (PN_stdfloat)_shape->getPlaneConstant());
76}
77
78/**
79 *
80 */
81PN_stdfloat BulletPlaneShape::
82get_plane_constant() const {
83 LightMutexHolder holder(BulletWorld::get_global_lock());
84
85 return (PN_stdfloat)_shape->getPlaneConstant();
86}
87
88/**
89 *
90 */
91LVector3 BulletPlaneShape::
92get_plane_normal() const {
93 LightMutexHolder holder(BulletWorld::get_global_lock());
94
95 return btVector3_to_LVector3(_shape->getPlaneNormal());
96}
97
98/**
99 *
100 */
101BulletPlaneShape *BulletPlaneShape::
102make_from_solid(const CollisionPlane *solid) {
103
104 LVector3 normal = solid->get_normal();
105 PN_stdfloat constant = solid->dist_to_plane(LPoint3(0, 0, 0));
106
107 return new BulletPlaneShape(normal, constant);
108}
109
110/**
111 * Tells the BamReader how to create objects of type BulletShape.
112 */
115 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
116}
117
118/**
119 * Writes the contents of this object to the datagram for shipping out to a
120 * Bam file.
121 */
123write_datagram(BamWriter *manager, Datagram &dg) {
124 BulletShape::write_datagram(manager, dg);
125
126 dg.add_stdfloat(get_margin());
127 get_plane_normal().write_datagram(dg);
128 dg.add_stdfloat(get_plane_constant());
129}
130
131/**
132 * This function is called by the BamReader's factory when a new object of
133 * type BulletShape is encountered in the Bam file. It should create the
134 * BulletShape and extract its information from the file.
135 */
136TypedWritable *BulletPlaneShape::
137make_from_bam(const FactoryParams &params) {
139 DatagramIterator scan;
140 BamReader *manager;
141
142 parse_params(params, scan, manager);
143 param->fillin(scan, manager);
144
145 return param;
146}
147
148/**
149 * This internal function is called by make_from_bam to read in all of the
150 * relevant data from the BamFile for the new BulletShape.
151 */
152void BulletPlaneShape::
153fillin(DatagramIterator &scan, BamReader *manager) {
154 BulletShape::fillin(scan, manager);
155 nassertv(_shape == nullptr);
156
157 PN_stdfloat margin = scan.get_stdfloat();
158
159 LVector3 normal;
160 normal.read_datagram(scan);
161
162 PN_stdfloat constant = scan.get_stdfloat();
163
164 _shape = new btStaticPlaneShape(LVecBase3_to_btVector3(normal), constant);
165 _shape->setUserPointer(this);
166 _shape->setMargin(margin);
167}
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
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
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
static void register_with_read_factory()
Tells the BamReader how to create objects of type BulletShape.
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.
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.