Panda3D
Loading...
Searching...
No Matches
bulletSphereShape.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 bulletSphereShape.cxx
10 * @author enn0x
11 * @date 2010-01-23
12 */
13
14#include "bulletSphereShape.h"
15
16#include "bulletWorld.h"
17
18TypeHandle BulletSphereShape::_type_handle;
19
20/**
21 *
22 */
23BulletSphereShape::
24BulletSphereShape(PN_stdfloat radius) : _radius(radius) {
25
26 _shape = new btSphereShape(radius);
27 _shape->setUserPointer(this);
28}
29
30/**
31 *
32 */
33BulletSphereShape::
34BulletSphereShape(const BulletSphereShape &copy) {
35 LightMutexHolder holder(BulletWorld::get_global_lock());
36
37 _radius = copy._radius;
38
39 _shape = new btSphereShape(_radius);
40 _shape->setUserPointer(this);
41}
42
43
44/**
45 *
46 */
47btCollisionShape *BulletSphereShape::
48ptr() const {
49
50 return _shape;
51}
52
53/**
54 *
55 */
56BulletSphereShape *BulletSphereShape::
57make_from_solid(const CollisionSphere *solid) {
58
59 return new BulletSphereShape(solid->get_radius());
60}
61
62/**
63 * Tells the BamReader how to create objects of type BulletShape.
64 */
67 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
68}
69
70/**
71 * Writes the contents of this object to the datagram for shipping out to a
72 * Bam file.
73 */
75write_datagram(BamWriter *manager, Datagram &dg) {
76 BulletShape::write_datagram(manager, dg);
77
78 dg.add_stdfloat(get_margin());
79 dg.add_stdfloat(_radius);
80}
81
82/**
83 * This function is called by the BamReader's factory when a new object of
84 * type BulletShape is encountered in the Bam file. It should create the
85 * BulletShape and extract its information from the file.
86 */
87TypedWritable *BulletSphereShape::
88make_from_bam(const FactoryParams &params) {
91 BamReader *manager;
92
93 parse_params(params, scan, manager);
94 param->fillin(scan, manager);
95
96 return param;
97}
98
99/**
100 * This internal function is called by make_from_bam to read in all of the
101 * relevant data from the BamFile for the new BulletShape.
102 */
103void BulletSphereShape::
104fillin(DatagramIterator &scan, BamReader *manager) {
105 BulletShape::fillin(scan, manager);
106 nassertv(_shape == nullptr);
107
108 PN_stdfloat margin = scan.get_stdfloat();
109 _radius = scan.get_stdfloat();
110
111 _shape = new btSphereShape(_radius);
112 _shape->setUserPointer(this);
113 _shape->setMargin(margin);
114}
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 spherical collision volume or object.
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.