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
20 TypeHandle 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 */
92 void BulletConeShape::
93 register_with_read_factory() {
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 */
101 void BulletConeShape::
102 write_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 */
117 TypedWritable *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 */
134 void 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}
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
bulletConeShape.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::get_factory
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition bamReader.I:177
BulletConeShape
Definition bulletConeShape.h:26
BulletConeShape::register_with_read_factory
static void register_with_read_factory()
Tells the BamReader how to create objects of type BulletShape.
Definition bulletConeShape.cxx:93
BulletConeShape::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 bulletConeShape.cxx:102
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
DatagramIterator::get_int8
int8_t get_int8()
Extracts a signed 8-bit integer.
Definition datagramIterator.I:56
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
Datagram::add_int8
void add_int8(int8_t value)
Adds a signed 8-bit integer to the datagram.
Definition datagram.I:42
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
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
config_bullet.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.