Panda3D
Loading...
Searching...
No Matches
bulletConeShape.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 bulletConeShape.cxx
10 * @author enn0x
11 * @date 2010-01-24
12 */
13
14#include "bulletConeShape.h"
15
16#include "config_bullet.h"
17
18#include "bulletWorld.h"
19
20TypeHandle BulletConeShape::_type_handle;
21
22/**
23 *
24 */
25BulletConeShape::
26BulletConeShape(PN_stdfloat radius, PN_stdfloat height, BulletUpAxis up) :
27 _radius(radius),
28 _height(height),
29 _up(up) {
30
31 switch (up) {
32 case X_up:
33 _shape = new btConeShapeX((btScalar)radius, (btScalar)height);
34 break;
35 case Y_up:
36 _shape = new btConeShape((btScalar)radius, (btScalar)height);
37 break;
38 case Z_up:
39 _shape = new btConeShapeZ((btScalar)radius, (btScalar)height);
40 break;
41 default:
42 bullet_cat.error() << "invalid up-axis:" << up << std::endl;
43 break;
44 }
45
46 nassertv(_shape);
47 _shape->setUserPointer(this);
48}
49
50/**
51 *
52 */
53BulletConeShape::
54BulletConeShape(const BulletConeShape &copy) {
55 LightMutexHolder holder(BulletWorld::get_global_lock());
56
57 _up = copy._up;
58 _radius = copy._radius;
59 _height = copy._height;
60
61 switch (_up) {
62 case X_up:
63 _shape = new btConeShapeX((btScalar)_radius, (btScalar)_height);
64 break;
65 case Y_up:
66 _shape = new btConeShape((btScalar)_radius, (btScalar)_height);
67 break;
68 case Z_up:
69 _shape = new btConeShapeZ((btScalar)_radius, (btScalar)_height);
70 break;
71 default:
72 bullet_cat.error() << "invalid up-axis:" << _up << std::endl;
73 break;
74 }
75
76 nassertv(_shape);
77 _shape->setUserPointer(this);
78}
79
80/**
81 *
82 */
83btCollisionShape *BulletConeShape::
84ptr() const {
85
86 return _shape;
87}
88
89/**
90 * Tells the BamReader how to create objects of type BulletShape.
91 */
94 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
95}
96
97/**
98 * Writes the contents of this object to the datagram for shipping out to a
99 * Bam file.
100 */
102write_datagram(BamWriter *manager, Datagram &dg) {
103 BulletShape::write_datagram(manager, dg);
104 dg.add_stdfloat(get_margin());
105
106 // parameters to serialize: radius, height, upIndex
107 dg.add_stdfloat(_radius);
108 dg.add_stdfloat(_height);
109 dg.add_int8((int8_t)_up);
110}
111
112/**
113 * This function is called by the BamReader's factory when a new object of
114 * type BulletShape is encountered in the Bam file. It should create the
115 * BulletShape and extract its information from the file.
116 */
117TypedWritable *BulletConeShape::
118make_from_bam(const FactoryParams &params) {
119 // create a default BulletConeShape
120 BulletConeShape *param = new BulletConeShape;
121 DatagramIterator scan;
122 BamReader *manager;
123
124 parse_params(params, scan, manager);
125 param->fillin(scan, manager);
126
127 return param;
128}
129
130/**
131 * This internal function is called by make_from_bam to read in all of the
132 * relevant data from the BamFile for the new BulletShape.
133 */
134void BulletConeShape::
135fillin(DatagramIterator &scan, BamReader *manager) {
136 BulletShape::fillin(scan, manager);
137 nassertv(_shape == nullptr);
138
139 PN_stdfloat margin = scan.get_stdfloat();
140
141 // parameters to serialize: radius, height, up
142 _radius = scan.get_stdfloat();
143 _height = scan.get_stdfloat();
144 _up = (BulletUpAxis) scan.get_int8();
145
146 switch (_up) {
147 case 0:
148 _shape = new btConeShapeX((btScalar)_radius, (btScalar)_height);
149 break;
150 case 1:
151 _shape = new btConeShape((btScalar)_radius, (btScalar)_height);
152 break;
153 case 2:
154 _shape = new btConeShapeZ((btScalar)_radius, (btScalar)_height);
155 break;
156 default:
157 bullet_cat.error() << "invalid up-axis:" << _up << std::endl;
158 break;
159 }
160
161 nassertv(_shape);
162 _shape->setUserPointer(this);
163 _shape->setMargin(margin);
164}
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
static void register_with_read_factory()
Tells the BamReader how to create objects of type BulletShape.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
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...
int8_t get_int8()
Extracts a signed 8-bit integer.
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
void add_int8(int8_t value)
Adds a signed 8-bit integer to the datagram.
Definition datagram.I:42
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.