x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
btHeightfieldTerrainShape.cpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\DarkPuzzle\libs\bullet_sdk\src\BulletCollision\CollisionShapes\btHeightfieldTerrainShape.cpp
旋转
特效
属性
历史版本
/* Bullet Continuous Collision Detection and Physics Library Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "btHeightfieldTerrainShape.h" #include "LinearMath/btTransformUtil.h" btHeightfieldTerrainShape::btHeightfieldTerrainShape(int heightStickWidth, int heightStickLength,void* heightfieldData,btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges) : m_heightStickWidth(heightStickWidth), m_heightStickLength(heightStickLength), m_width((btScalar)heightStickWidth-1), m_length((btScalar)heightStickLength-1), m_maxHeight(maxHeight), m_heightfieldDataUnknown(heightfieldData), m_useFloatData(useFloatData), m_flipQuadEdges(flipQuadEdges), m_useDiamondSubdivision(false), m_upAxis(upAxis), m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)) { btScalar quantizationMargin = 1.f; //enlarge the AABB to avoid division by zero when initializing the quantization values btVector3 clampValue(quantizationMargin,quantizationMargin,quantizationMargin); btVector3 halfExtents(0,0,0); switch (m_upAxis) { case 0: { halfExtents.setValue( btScalar(m_maxHeight), btScalar(m_width), //?? don't know if this should change btScalar(m_length)); break; } case 1: { halfExtents.setValue( btScalar(m_width), btScalar(m_maxHeight), btScalar(m_length)); break; }; case 2: { halfExtents.setValue( btScalar(m_width), btScalar(m_length), btScalar(m_maxHeight) ); break; } default: { //need to get valid m_upAxis btAssert(0); } } halfExtents*= btScalar(0.5); m_localAabbMin = -halfExtents - clampValue; m_localAabbMax = halfExtents + clampValue; btVector3 aabbSize = m_localAabbMax - m_localAabbMin; } btHeightfieldTerrainShape::~btHeightfieldTerrainShape() { } void btHeightfieldTerrainShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const { /* aabbMin.setValue(-1e30f,-1e30f,-1e30f); aabbMax.setValue(1e30f,1e30f,1e30f); */ btVector3 halfExtents = (m_localAabbMax-m_localAabbMin)* m_localScaling * btScalar(0.5); btMatrix3x3 abs_b = t.getBasis().absolute(); btPoint3 center = t.getOrigin(); btVector3 extent = btVector3(abs_b[0].dot(halfExtents), abs_b[1].dot(halfExtents), abs_b[2].dot(halfExtents)); extent += btVector3(getMargin(),getMargin(),getMargin()); aabbMin = center - extent; aabbMax = center + extent; } btScalar btHeightfieldTerrainShape::getHeightFieldValue(int x,int y) const { btScalar val = 0.f; if (m_useFloatData) { val = m_heightfieldDataFloat[(y*m_heightStickWidth)+x]; } else { //assume unsigned short int unsigned char heightFieldValue = m_heightfieldDataUnsignedChar[(y*m_heightStickWidth)+x]; val = heightFieldValue* (m_maxHeight/btScalar(65535)); } return val; } void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const { btAssert(x>=0); btAssert(y>=0); btAssert(x
startX) startX = quantizedAabbMin[1]; if (quantizedAabbMax[1]
startJ) startJ = quantizedAabbMin[2]; if (quantizedAabbMax[2]
startX) startX = quantizedAabbMin[0]; if (quantizedAabbMax[0]
startJ) startJ = quantizedAabbMin[2]; if (quantizedAabbMax[2]
startX) startX = quantizedAabbMin[0]; if (quantizedAabbMax[0]
startJ) startJ = quantizedAabbMin[1]; if (quantizedAabbMax[1]
processTriangle(vertices,x,j); //second triangle getVertex(x,j,vertices[0]); getVertex(x+1,j+1,vertices[1]); getVertex(x,j+1,vertices[2]); callback->processTriangle(vertices,x,j); } else { //first triangle getVertex(x,j,vertices[0]); getVertex(x,j+1,vertices[1]); getVertex(x+1,j,vertices[2]); callback->processTriangle(vertices,x,j); //second triangle getVertex(x+1,j,vertices[0]); getVertex(x,j+1,vertices[1]); getVertex(x+1,j+1,vertices[2]); callback->processTriangle(vertices,x,j); } } } } void btHeightfieldTerrainShape::calculateLocalInertia(btScalar ,btVector3& inertia) const { //moving concave objects not supported inertia.setValue(btScalar(0.),btScalar(0.),btScalar(0.)); } void btHeightfieldTerrainShape::setLocalScaling(const btVector3& scaling) { m_localScaling = scaling; } const btVector3& btHeightfieldTerrainShape::getLocalScaling() const { return m_localScaling; }
btHeightfieldTerrainShape.cpp
网页地址
文件地址
上一页
28/58
下一页
下载
( 8 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.