本文整理汇总了C++中hkArray::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ hkArray::reserve方法的具体用法?C++ hkArray::reserve怎么用?C++ hkArray::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hkArray
的用法示例。
在下文中一共展示了hkArray::reserve方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadEntireFileIntoBuffer
void loadEntireFileIntoBuffer(const char* filepath, hkArray<char>& outBuf)
{
// Load the entire file
// Open a stream to read the file
hkIstream infile( filepath );
HK_ASSERT( 0x215d080c, infile.isOk() );
if( infile.getStreamReader()->seekTellSupported() )
{
infile.getStreamReader()->seek(0, hkStreamReader::STREAM_END);
outBuf.reserve( infile.getStreamReader()->tell() );
infile.getStreamReader()->seek(0, hkStreamReader::STREAM_SET);
}
// read entire file into local buffer
int nread = 1;
while( nread )
{
const int CSIZE = 8192;
char* b = outBuf.expandBy( CSIZE ); // outBuf.reserve( outBuf.getSize() + CSIZE ); b = outBuf.begin() + outBuf.getSize();
nread = infile.read( b, CSIZE );
outBuf.setSize( outBuf.getSize() + nread - CSIZE );
}
}
示例2: buildBrickWall
void BrickWallBuilder::buildBrickWall(const BrickwallBuilderDescriptor& bwDescriptor, hkArray<hkpRigidBody*>& bricksOut, hkArray<hkpConstraintInstance*>& constraintsOut )
{
hkVector4 halfExtents( bwDescriptor.m_brickShape->getHalfExtents() );
// move start point depending on wall size
hkVector4 posX( hkVector4::getZero() );
posX(0) = -bwDescriptor.m_width * halfExtents(0);
posX(0) += halfExtents(0);
posX(1) = -halfExtents(1);
// reserve space for all bricks and constraints
bricksOut.reserve(bwDescriptor.m_height * bwDescriptor.m_width * 2);
constraintsOut.reserve( (2 * bwDescriptor.m_height - 1) * (2 * bwDescriptor.m_width - 1) + bwDescriptor.m_width - 1);
hkReal thresholdDelta = (bwDescriptor.m_strength > bwDescriptor.m_lowerThreshold)? (bwDescriptor.m_strength - bwDescriptor.m_lowerThreshold) /(bwDescriptor.m_height*2-1) : 0.0f;
// set brick properties, used for all the bricks
hkpRigidBodyCinfo boxInfo;
computeBrickInfo(bwDescriptor.m_brickShape, bwDescriptor.m_brickMass, boxInfo);
// QUI
int colOffset=bwDescriptor.m_height;
for(int x=0;x<bwDescriptor.m_width;x++) // along the ground, left to right
{
hkVector4 pos(posX);
// breaking threshold for this row
hkReal rowThreshold = bwDescriptor.m_strength;
for(int y=0; y<bwDescriptor.m_height; y++) // bottom to top
{
pos(1) += (halfExtents(1) + bwDescriptor.m_brickShape->getRadius()) * 2.0f;
// build rigid body for brick
int brickIndOne;
{
brickIndOne=bricksOut.getSize();
boxInfo.m_position.setRotatedDir( bwDescriptor.m_transform.getRotation() /*bwDescriptor.m_orientation*/,pos);
boxInfo.m_position.add4( bwDescriptor.m_transform.getTranslation() /*bwDescriptor.m_position*/);
boxInfo.m_rotation.set( bwDescriptor.m_transform.getRotation() ); //bwDescriptor.m_orientation;
bricksOut.pushBack(new hkpRigidBody(boxInfo));
}
// At each step 2 constraints are built:
hkBool constraintsAdded[] = {false, false};
// 1 - A constraint to the ground OR a constraint to the brick below the one just built
if( y == 0 ) {
// attach the first row to the ground (if requested)
if(bwDescriptor.m_attachToGround)
constraintsOut.pushBack(buildBreakableConstraintInstance(bricksOut[brickIndOne], bwDescriptor.m_theGround, rowThreshold*1000));
} else {
// create a breakable constraint from the brick and the one below
constraintsOut.pushBack(buildBreakableConstraintInstance(bricksOut[brickIndOne], bricksOut[brickIndOne - 1], rowThreshold));
constraintsAdded[0]=true;
}
// 2 - a constraint to the brick to the left
if( x > 0 ) // check if there is a previous column
{
// create a constraint from the new brick and the corresponding brick from the previous column
// the first row is made of unbreakable constraints
if(y==0 && bwDescriptor.m_attachToGround)
constraintsOut.pushBack(buildConstraintInstance(bricksOut[brickIndOne], bricksOut[brickIndOne - colOffset]));
else
constraintsOut.pushBack(buildBreakableConstraintInstance(bricksOut[brickIndOne], bricksOut[brickIndOne - colOffset], rowThreshold));
constraintsAdded[1]=true;
}
if(bwDescriptor.m_setCollisionFilter)
{
// Set filter info
bool b = constraintsAdded[0];
bool l = constraintsAdded[1];
hkUint32 filterInfo = BrickFilter::calcFilterInfo(y, x, bwDescriptor.m_wallID, l, b);
bricksOut[brickIndOne]->setCollisionFilterInfo(filterInfo);
}
rowThreshold -= thresholdDelta;
} // end of for(..y..)
// advance to next col
posX(0) += bwDescriptor.m_gapWidth + halfExtents(0)*2.0f;
} // end of for(..x..)
}