Panda3D
Loading...
Searching...
No Matches
physxHeightFieldDesc.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 physxHeightFieldDesc.cxx
10 * @author enn0x
11 * @date 2009-10-15
12 */
13
15
16/**
17 *
18 */
19void PhysxHeightFieldDesc::
20set_convex_edge_threshold(float threshold) {
21
22 _desc.convexEdgeThreshold = threshold;
23}
24
25/**
26 *
27 */
28void PhysxHeightFieldDesc::
29set_thickness(float thickness) {
30
31 _desc.thickness = thickness;
32}
33
34/**
35 *
36 */
37void PhysxHeightFieldDesc::
38set_image(const PNMImage &image, unsigned short materialIndex) {
39
40 NxU32 _32K = 32767; // (1<<15)-1;
41 NxU32 _64K = 65535; // (1<<16)-1;
42
43 NxU32 nbRows = image.get_x_size();
44 NxU32 nbColumns = image.get_y_size();
45
46 set_size(nbRows, nbColumns);
47
48 NxU8 *currentByte = (NxU8 *)(_desc.samples);
49
50 for (NxU32 row=0; row < nbRows; row++) {
51 for (NxU32 column=0; column < nbColumns; column++) {
52
53 NxHeightFieldSample* currentSample = (NxHeightFieldSample *)currentByte;
54
55 NxReal fvalue = image.get_bright(row, column);
56 NxI16 ivalue = (NxI16)((fvalue - 0.5f) * _32K);
57
58 currentSample->height = (NxI16)ivalue;
59 currentSample->tessFlag = (NxU8)0;
60 currentSample->materialIndex0 = (NxU8)materialIndex;
61 currentSample->materialIndex1 = (NxU8)materialIndex;
62
63 currentByte += _desc.sampleStride;
64 }
65 }
66}
67
68/**
69 *
70 */
71void PhysxHeightFieldDesc::
72set_material_index(unsigned int row, unsigned int column, unsigned short materialIndex0, unsigned short materialIndex1) {
73
74 nassertv(_desc.samples);
75 nassertv(row < _desc.nbRows);
76 nassertv(column < _desc.nbColumns);
77
78 NxU32 idx = row * _desc.nbColumns + column;
79 NxU8 *byte = (NxU8 *)_desc.samples + _desc.sampleStride * idx;
80 NxHeightFieldSample* sample = (NxHeightFieldSample *)byte;
81
82 // NxHeightFieldSample* sample = ((NxHeightFieldSample *)_desc.samples) +
83 // idx;
84
85 sample->materialIndex0 = (NxU8)materialIndex0;
86 sample->materialIndex1 = (NxU8)materialIndex1;
87}
88
89/**
90 *
91 */
92void PhysxHeightFieldDesc::
93set_height(unsigned int row, unsigned int column, short height) {
94
95 nassertv(_desc.samples);
96 nassertv(row < _desc.nbRows);
97 nassertv(column < _desc.nbColumns);
98
99 NxU32 idx = row * _desc.nbColumns + column;
100 NxU8 *byte = (NxU8 *)_desc.samples + _desc.sampleStride * idx;
101 NxHeightFieldSample* sample = (NxHeightFieldSample *)byte;
102
103 sample->height = (NxI16)height;
104}
105
106/**
107 *
108 */
109void PhysxHeightFieldDesc::
110set_tess_flag(unsigned int row, unsigned int column, unsigned short value) {
111
112 nassertv(_desc.samples);
113 nassertv(row < _desc.nbRows);
114 nassertv(column < _desc.nbColumns);
115
116 NxU32 idx = row * _desc.nbColumns + column;
117 NxU8 *byte = (NxU8 *)_desc.samples + _desc.sampleStride * idx;
118 NxHeightFieldSample* sample = (NxHeightFieldSample *)byte;
119
120 nassertv(value < 2);
121 sample->tessFlag = (NxU8)value;
122}
int get_x_size() const
Returns the number of pixels in the X direction.
int get_y_size() const
Returns the number of pixels in the Y direction.
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
Definition pnmImage.h:58
float get_bright(int x, int y) const
Returns the linear brightness of the given xel, as a linearized float in the range 0....
Definition pnmImage.I:869
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.