Panda3D
 All Classes Functions Variables Enumerations
physxHeightFieldDesc.cxx
00001 // Filename: physxHeightFieldDesc.cxx
00002 // Created by:  enn0x (15Oct09)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "physxHeightFieldDesc.h"
00016 
00017 ////////////////////////////////////////////////////////////////////
00018 //     Function: PhysxHeightFieldDesc::set_convex_edge_threshold
00019 //       Access: Published
00020 //  Description: 
00021 ////////////////////////////////////////////////////////////////////
00022 void PhysxHeightFieldDesc::
00023 set_convex_edge_threshold(float threshold) {
00024 
00025   _desc.convexEdgeThreshold = threshold;
00026 }
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //     Function: PhysxHeightFieldDesc::set_thickness
00030 //       Access: Published
00031 //  Description: 
00032 ////////////////////////////////////////////////////////////////////
00033 void PhysxHeightFieldDesc::
00034 set_thickness(float thickness) {
00035 
00036   _desc.thickness = thickness;
00037 }
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //     Function: PhysxHeightFieldDesc::set_image
00041 //       Access: Published
00042 //  Description: 
00043 ////////////////////////////////////////////////////////////////////
00044 void PhysxHeightFieldDesc::
00045 set_image(const PNMImage &image, unsigned short materialIndex) {
00046 
00047   NxU32 _32K = 32767; // (1<<15)-1;
00048   NxU32 _64K = 65535; // (1<<16)-1;
00049 
00050   NxU32 nbRows = image.get_x_size();
00051   NxU32 nbColumns = image.get_y_size();
00052 
00053   set_size(nbRows, nbColumns);
00054 
00055   NxU8 *currentByte = (NxU8 *)(_desc.samples);
00056 
00057   for (NxU32 row=0; row < nbRows; row++) {
00058     for (NxU32 column=0; column < nbColumns; column++) {
00059 
00060       NxHeightFieldSample* currentSample = (NxHeightFieldSample *)currentByte;
00061 
00062       NxReal fvalue = image.get_bright(row, column);
00063       NxI16 ivalue = (NxI16)((fvalue - 0.5f) * _32K);
00064 
00065       currentSample->height         = (NxI16)ivalue;
00066       currentSample->tessFlag       = (NxU8)0;
00067       currentSample->materialIndex0 = (NxU8)materialIndex;
00068       currentSample->materialIndex1 = (NxU8)materialIndex;
00069 
00070       currentByte += _desc.sampleStride;
00071     }
00072   }
00073 }
00074 
00075 ////////////////////////////////////////////////////////////////////
00076 //     Function: PhysxHeightFieldDesc::set_material_index
00077 //       Access: Published
00078 //  Description: 
00079 ////////////////////////////////////////////////////////////////////
00080 void PhysxHeightFieldDesc::
00081 set_material_index(unsigned int row, unsigned int column, unsigned short materialIndex0, unsigned short materialIndex1) {
00082 
00083   nassertv(_desc.samples);
00084   nassertv(row < _desc.nbRows);
00085   nassertv(column < _desc.nbColumns);
00086 
00087   NxU32 idx = row * _desc.nbColumns + column;
00088   NxU8 *byte = (NxU8 *)_desc.samples + _desc.sampleStride * idx;
00089   NxHeightFieldSample* sample = (NxHeightFieldSample *)byte;
00090 
00091   //NxHeightFieldSample* sample = ((NxHeightFieldSample *)_desc.samples) + idx;
00092 
00093   sample->materialIndex0 = (NxU8)materialIndex0;
00094   sample->materialIndex1 = (NxU8)materialIndex1;
00095 }
00096 
00097 ////////////////////////////////////////////////////////////////////
00098 //     Function: PhysxHeightFieldDesc::set_height
00099 //       Access: Published
00100 //  Description: 
00101 ////////////////////////////////////////////////////////////////////
00102 void PhysxHeightFieldDesc::
00103 set_height(unsigned int row, unsigned int column, short height) {
00104 
00105   nassertv(_desc.samples);
00106   nassertv(row < _desc.nbRows);
00107   nassertv(column < _desc.nbColumns);
00108 
00109   NxU32 idx = row * _desc.nbColumns + column;
00110   NxU8 *byte = (NxU8 *)_desc.samples + _desc.sampleStride * idx;
00111   NxHeightFieldSample* sample = (NxHeightFieldSample *)byte;
00112 
00113   sample->height = (NxI16)height;
00114 }
00115 
00116 ////////////////////////////////////////////////////////////////////
00117 //     Function: PhysxHeightFieldDesc::set_tess_flag
00118 //       Access: Published
00119 //  Description: 
00120 ////////////////////////////////////////////////////////////////////
00121 void PhysxHeightFieldDesc::
00122 set_tess_flag(unsigned int row, unsigned int column, unsigned short value) {
00123 
00124   nassertv(_desc.samples);
00125   nassertv(row < _desc.nbRows);
00126   nassertv(column < _desc.nbColumns);
00127 
00128   NxU32 idx = row * _desc.nbColumns + column;
00129   NxU8 *byte = (NxU8 *)_desc.samples + _desc.sampleStride * idx;
00130   NxHeightFieldSample* sample = (NxHeightFieldSample *)byte;
00131 
00132   nassertv(value < 2);
00133   sample->tessFlag = (NxU8)value;
00134 }
00135 
 All Classes Functions Variables Enumerations