Panda3D
 All Classes Functions Variables Enumerations
physxHeightFieldShapeDesc.cxx
00001 // Filename: physxHeightFieldShapeDesc.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 "physxHeightFieldShapeDesc.h"
00016 #include "physxHeightField.h"
00017 
00018 ////////////////////////////////////////////////////////////////////
00019 //     Function: PhysxHeightFieldShapeDesc::set_to_default
00020 //       Access: Published
00021 //  Description: (re)sets the structure to the default.
00022 ////////////////////////////////////////////////////////////////////
00023 void PhysxHeightFieldShapeDesc::
00024 set_to_default() {
00025 
00026   _desc.setToDefault();
00027   set_name("");
00028 
00029   _desc.shapeFlags = NX_SF_FEATURE_INDICES | NX_SF_VISUALIZATION;
00030   _desc.meshFlags = NX_MESH_SMOOTH_SPHERE_COLLISIONS;
00031   _desc.materialIndexHighBits = (NxMaterialIndex)0;
00032   _desc.holeMaterial = (NxMaterialIndex)0;
00033   _desc.localPose = PhysxManager::mat4_to_nxMat34(LMatrix4f::y_to_z_up_mat());
00034 }
00035 
00036 ////////////////////////////////////////////////////////////////////
00037 //     Function: PhysxHeightFieldShapeDesc::set_hole_material
00038 //       Access: Published
00039 //  Description: Sets the the material index that designates holes
00040 //               in the height field. This number is compared
00041 //               directly to sample materials. Consequently the
00042 //               high 9 bits must be zero.
00043 //               Default value is 0.
00044 ////////////////////////////////////////////////////////////////////
00045 void PhysxHeightFieldShapeDesc::
00046 set_hole_material(unsigned short index) {
00047 
00048   _desc.holeMaterial = (NxMaterialIndex)index;
00049 }
00050 
00051 ////////////////////////////////////////////////////////////////////
00052 //     Function: PhysxHeightFieldShapeDesc::set_material_index_high_bits
00053 //       Access: Published
00054 //  Description: Sets the high 9 bits of this number are used to
00055 //               complete the material indices in the samples. The
00056 //               remaining low 7 bits must be zero.
00057 //               Default value is 0.
00058 ////////////////////////////////////////////////////////////////////
00059 void PhysxHeightFieldShapeDesc::
00060 set_material_index_high_bits(unsigned short index) {
00061 
00062   _desc.materialIndexHighBits = (NxMaterialIndex)index;
00063 }
00064 
00065 ////////////////////////////////////////////////////////////////////
00066 //     Function: PhysxHeightFieldShapeDesc::get_hole_material
00067 //       Access: Published
00068 //  Description: Returns the the material index that designates
00069 //               holes in the height field.
00070 ////////////////////////////////////////////////////////////////////
00071 unsigned short PhysxHeightFieldShapeDesc::
00072 get_hole_material() const {
00073 
00074   return (unsigned short)_desc.holeMaterial;
00075 }
00076 
00077 ////////////////////////////////////////////////////////////////////
00078 //     Function: PhysxHeightFieldShapeDesc::get_material_index_hight_bits
00079 //       Access: Published
00080 //  Description: Returns the high 9 bits of this number are used to
00081 //               complete the material indices in the samples.
00082 ////////////////////////////////////////////////////////////////////
00083 unsigned short PhysxHeightFieldShapeDesc::
00084 get_material_index_hight_bits() const {
00085 
00086   return (unsigned short)_desc.materialIndexHighBits;
00087 }
00088 
00089 ////////////////////////////////////////////////////////////////////
00090 //     Function: PhysxHeightFieldShapeDesc::set_dimensions
00091 //       Access: Published
00092 //  Description: 
00093 ////////////////////////////////////////////////////////////////////
00094 void PhysxHeightFieldShapeDesc::
00095 set_dimensions(const LVector3f &dimensions) {
00096 
00097   NxU32 _64K = 65535; // (1<<16)-1;
00098 
00099   NxU32 nbRows    = _desc.heightField->getNbRows();
00100   NxU32 nbColumns = _desc.heightField->getNbColumns();
00101 
00102   _desc.rowScale    = dimensions.get_x() / nbRows;
00103   _desc.columnScale = dimensions.get_y() / nbColumns;
00104   _desc.heightScale = dimensions.get_z() / _64K;
00105 }
00106 
00107 ////////////////////////////////////////////////////////////////////
00108 //     Function: PhysxHeightFieldShapeDesc::set_height_field
00109 //       Access: Published
00110 //  Description: 
00111 ////////////////////////////////////////////////////////////////////
00112 void PhysxHeightFieldShapeDesc::
00113 set_height_field(const PhysxHeightField &hf) {
00114 
00115    _desc.heightField = hf.ptr();
00116 }
00117 
 All Classes Functions Variables Enumerations