20 TypeHandle BulletHeightfieldShape::_type_handle;
27 BulletHeightfieldShape::
28 BulletHeightfieldShape(
const PNMImage &image, PN_stdfloat max_height, BulletUpAxis up) :
29 _max_height(max_height), _up(up) {
34 _data =
new btScalar[_num_rows * _num_cols];
36 for (
int row=0; row < _num_rows; row++) {
37 for (
int column=0; column < _num_cols; column++) {
39 _data[_num_rows * column + row] =
41 max_height * image.
get_bright(row, _num_cols - column - 1);
45 _shape =
new btHeightfieldTerrainShape(_num_rows,
51 _shape->setUserPointer(
this);
57 btCollisionShape *BulletHeightfieldShape::
66 void BulletHeightfieldShape::
67 set_use_diamond_subdivision(
bool flag) {
70 return _shape->setUseDiamondSubdivision(flag);
79 BulletHeightfieldShape::
80 BulletHeightfieldShape(
Texture *tex, PN_stdfloat max_height, BulletUpAxis up) :
81 _max_height(max_height), _up(up) {
85 _data =
new btScalar[_num_rows * _num_cols];
87 btScalar step_x = 1.0 / (btScalar)tex->
get_x_size();
88 btScalar step_y = 1.0 / (btScalar)tex->
get_y_size();
93 for (
int row=0; row < _num_rows; row++) {
94 for (
int column=0; column < _num_cols; column++) {
95 if (!peeker->lookup_bilinear(sample, row * step_x, column * step_y)) {
96 bullet_cat.error() <<
"Could not sample texture." << std::endl;
99 _data[_num_rows * column + row] = max_height * sample.get_x();
103 _shape =
new btHeightfieldTerrainShape(_num_rows,
109 _shape->setUserPointer(
this);
115 BulletHeightfieldShape::
119 _num_rows = copy._num_rows;
120 _num_cols = copy._num_cols;
121 _max_height = copy._max_height;
124 size_t size = (size_t)_num_rows * (
size_t)_num_cols;
125 _data =
new btScalar[size];
126 memcpy(_data, copy._data, size *
sizeof(btScalar));
128 _shape =
new btHeightfieldTerrainShape(_num_rows,
134 _shape->setUserPointer(
this);
160 size_t size = (size_t)_num_rows * (
size_t)_num_cols;
161 for (
size_t i = 0; i < size; ++i) {
179 param->fillin(scan, manager);
188 void BulletHeightfieldShape::
191 nassertv(_shape ==
nullptr);
196 _up = (BulletUpAxis) scan.
get_int8();
201 size_t size = (size_t)_num_rows * (
size_t)_num_cols;
203 _data =
new float[size];
205 for (
size_t i = 0; i < size; ++i) {
209 _shape =
new btHeightfieldTerrainShape(_num_rows,
215 _shape->setUserPointer(
this);
216 _shape->setMargin(margin);
get_y_size
Returns the height of the texture image in texels.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Base class for objects that can be written to and read from Bam files.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
int32_t get_int32()
Extracts a signed 32-bit integer.
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.
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
void add_int8(int8_t value)
Adds a signed 8-bit integer to the datagram.
static void register_with_read_factory()
Tells the BamReader how to create objects of type BulletShape.
Similar to MutexHolder, but for a light mutex.
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.
An instance of this object is returned by Texture::peek().
void add_int32(int32_t value)
Adds a signed 32-bit integer to the datagram.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A class to retrieve the individual data elements previously stored in a Datagram.
int8_t get_int8()
Extracts a signed 8-bit integer.
TypeHandle is the identifier used to differentiate C++ class types.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
float get_bright(int x, int y) const
Returns the linear brightness of the given xel, as a linearized float in the range 0....
get_x_size
Returns the width of the texture image in texels.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.