本文整理汇总了C++中ogre::HardwareIndexBufferSharedPtr::getSizeInBytes方法的典型用法代码示例。如果您正苦于以下问题:C++ HardwareIndexBufferSharedPtr::getSizeInBytes方法的具体用法?C++ HardwareIndexBufferSharedPtr::getSizeInBytes怎么用?C++ HardwareIndexBufferSharedPtr::getSizeInBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::HardwareIndexBufferSharedPtr
的用法示例。
在下文中一共展示了HardwareIndexBufferSharedPtr::getSizeInBytes方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createFakeEntity
void ESKOgre::createFakeEntity(Ogre::SceneManager *mSceneMgr) {
Ogre::MeshPtr msh = Ogre::MeshManager::getSingleton().createManual(name + "_skeleton", XENOVIEWER_RESOURCE_GROUP);
msh->setSkeletonName(name);
Ogre::SubMesh* sub = msh->createSubMesh();
const size_t nVertices = 3;
const size_t nVertCount = 3;
const size_t vbufCount = nVertCount*nVertices;
float *vertices = (float *)malloc(sizeof(float)*vbufCount);
for (size_t i = 0; i < nVertices; i++) {
vertices[i*nVertCount] = 0.0;
vertices[i*nVertCount + 1] = 0.0;
vertices[i*nVertCount + 2] = 0.0;
}
const size_t ibufCount = 3;
unsigned short *faces = (unsigned short *)malloc(sizeof(unsigned short) * ibufCount);
for (size_t i = 0; i < ibufCount; i++) {
faces[i] = i;
}
msh->sharedVertexData = new Ogre::VertexData();
msh->sharedVertexData->vertexCount = nVertices;
Ogre::VertexDeclaration* decl = msh->sharedVertexData->vertexDeclaration;
size_t offset = 0;
decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
Ogre::HardwareVertexBufferSharedPtr vbuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(offset, msh->sharedVertexData->vertexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true);
Ogre::VertexBufferBinding* bind = msh->sharedVertexData->vertexBufferBinding;
bind->setBinding(0, vbuf);
Ogre::HardwareIndexBufferSharedPtr ibuf = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT, ibufCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true);
sub->useSharedVertices = true;
sub->indexData->indexBuffer = ibuf;
sub->indexData->indexCount = ibufCount;
sub->indexData->indexStart = 0;
msh->_setBounds(Ogre::AxisAlignedBox(-100, -100, -100, 100, 100, 100));
msh->_setBoundingSphereRadius(100);
msh->load();
free(faces);
free(vertices);
skeleton_entity = mSceneMgr->createEntity(name + "_skeleton");
skeleton_node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
skeleton_node->attachObject(skeleton_entity);
skeleton_node->setVisible(false);
}
示例2:
Ogre::SubMesh *EMDOgre::createOgreSubmesh(EMDTriangles *triangles, Ogre::MeshPtr mesh) {
Ogre::SubMesh *sub = mesh->createSubMesh();
const size_t ibufCount = triangles->faces.size();
unsigned short *faces = (unsigned short *)malloc(sizeof(unsigned short) * ibufCount);
for (size_t i = 0; i<ibufCount; i++) {
faces[i] = triangles->faces[i];
}
Ogre::HardwareIndexBufferSharedPtr ibuf = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT, ibufCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true);
sub->useSharedVertices = true;
sub->indexData->indexBuffer = ibuf;
sub->indexData->indexCount = ibufCount;
sub->indexData->indexStart = 0;
free(faces);
return sub;
}
示例3: createTerrain
//.........这里部分代码省略.........
name, "General").get();
// Create one submesh.
Ogre::SubMesh* subMesh = mMeshes[tileIndex]->createSubMesh();
// Create vertex data structure for vertices shared between submeshes.
mMeshes[tileIndex]->sharedVertexData = new Ogre::VertexData();
mMeshes[tileIndex]->sharedVertexData->vertexCount = vertexPerTile;
// Create declaration (memory format) of vertex data.
Ogre::VertexDeclaration* decl =
mMeshes[tileIndex]->sharedVertexData->vertexDeclaration;
size_t offset = 0;
// 1st buffer
decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
decl->addElement(0, offset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);
decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_DIFFUSE);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
// Allocate vertex buffer of the requested number of vertices (vertexPerTile)
// and bytes per vertex (offset).
Ogre::HardwareVertexBufferSharedPtr vbuf =
Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
offset, vertexPerTile, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
// Upload the vertex data to the card
vbuf->writeData(0, vbuf->getSizeInBytes(), &(vertices.front()), true);
// Set vertex buffer binding so buffer 0 is bound to our vertex buffer.
Ogre::VertexBufferBinding* bind =
mMeshes[tileIndex]->sharedVertexData->vertexBufferBinding;
bind->setBinding(0, vbuf);
// Allocate index buffer of the requested number of vertices .
Ogre::HardwareIndexBufferSharedPtr ibuf = Ogre::HardwareBufferManager::getSingleton().
createIndexBuffer(
Ogre::HardwareIndexBuffer::IT_16BIT,
trianglesPerTile * 3,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
// Upload the index data to the card.
ibuf->writeData(0, ibuf->getSizeInBytes(), &(indices[0].front()), true);
/// Set parameters of the submesh
subMesh->useSharedVertices = true;
subMesh->indexData->indexBuffer = ibuf;
subMesh->indexData->indexCount = indices[0].size();
subMesh->indexData->indexStart = 0;
subMesh->setMaterialName("terrain");
float xMin = vertices[0];
float yMin = vertices[1];
float zMin = vertices[2];
float xMax = vertices[0];
float yMax = vertices[1];
float zMax = vertices[2];
for (unsigned int i = 0; i < vertexPerTile * 11; i += 11)
{
if (vertices[i ] < xMin) xMin = vertices[i ]; else
if (vertices[i ] > xMax) xMax = vertices[i ];
if (vertices[i + 1] < yMin) yMin = vertices[i + 1]; else
if (vertices[i + 1] > yMax) yMax = vertices[i + 1];
if (vertices[i + 2] < zMin) zMin = vertices[i + 2]; else
if (vertices[i + 2] > zMax) zMax = vertices[i + 2];
}
// Set bounding information (for culling).
mMeshes[tileIndex]->_setBounds(Ogre::AxisAlignedBox(xMin, yMin, zMin, xMax, yMax, zMax));
mMeshes[tileIndex]->_setBoundingSphereRadius(1.0f);
// Notify Mesh object that it has been loaded.
mMeshes[tileIndex]->load();
// Create entity.
mEntities[tileIndex] = createEntity(name, name);
mEntities[tileIndex]->setCastShadows(false);
mEntities[tileIndex]->setUserAny(Ogre::Any(this));
// Create scene node.
mSceneNodes[tileIndex] = createSceneNode();
mSceneNodes[tileIndex]->attachObject(mEntities[tileIndex]);
// Advance to next tile.
tileIndex++;
}
}
}
示例4: createSubMesh
//.........这里部分代码省略.........
if(!bounds.isValid())
{
float v[3] = { 0.0f, 0.0f, 0.0f };
bounds.add(&v[0], 1);
}
mesh->_setBounds(Ogre::AxisAlignedBox(bounds.minX()-0.5f, bounds.minY()-0.5f, bounds.minZ()-0.5f,
bounds.maxX()+0.5f, bounds.maxY()+0.5f, bounds.maxZ()+0.5f));
mesh->_setBoundingSphereRadius(bounds.getRadius());
// This function is just one long stream of Ogre-barf, but it works
// great.
Ogre::HardwareBufferManager *hwBufMgr = Ogre::HardwareBufferManager::getSingletonPtr();
Ogre::HardwareVertexBufferSharedPtr vbuf;
Ogre::HardwareIndexBufferSharedPtr ibuf;
Ogre::VertexBufferBinding *bind;
Ogre::VertexDeclaration *decl;
int nextBuf = 0;
Ogre::SubMesh *sub = mesh->createSubMesh();
// Add vertices
sub->useSharedVertices = false;
sub->vertexData = new Ogre::VertexData();
sub->vertexData->vertexStart = 0;
sub->vertexData->vertexCount = srcVerts.size();
decl = sub->vertexData->vertexDeclaration;
bind = sub->vertexData->vertexBufferBinding;
if(srcVerts.size())
{
vbuf = hwBufMgr->createVertexBuffer(Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3),
srcVerts.size(), vertUsage, vertShadowBuffer);
vbuf->writeData(0, vbuf->getSizeInBytes(), &srcVerts[0][0], true);
decl->addElement(nextBuf, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
bind->setBinding(nextBuf++, vbuf);
}
// Vertex normals
if(srcNorms.size())
{
vbuf = hwBufMgr->createVertexBuffer(Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3),
srcNorms.size(), vertUsage, vertShadowBuffer);
vbuf->writeData(0, vbuf->getSizeInBytes(), &srcNorms[0][0], true);
decl->addElement(nextBuf, 0, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
bind->setBinding(nextBuf++, vbuf);
}
// Vertex colors
const std::vector<Ogre::Vector4> &colors = data->colors;
if(colors.size())
{
Ogre::RenderSystem *rs = Ogre::Root::getSingleton().getRenderSystem();
std::vector<Ogre::RGBA> colorsRGB(colors.size());
for(size_t i = 0;i < colorsRGB.size();i++)
{
Ogre::ColourValue clr(colors[i][0], colors[i][1], colors[i][2], colors[i][3]);
rs->convertColourValue(clr, &colorsRGB[i]);
}
vbuf = hwBufMgr->createVertexBuffer(Ogre::VertexElement::getTypeSize(Ogre::VET_COLOUR),
colorsRGB.size(), Ogre::HardwareBuffer::HBU_STATIC);
vbuf->writeData(0, vbuf->getSizeInBytes(), &colorsRGB[0], true);
decl->addElement(nextBuf, 0, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE);
bind->setBinding(nextBuf++, vbuf);
示例5: dist
//.........这里部分代码省略.........
for (uint32_t vert_index = 0; vert_index < n.num_verticies; ++vert_index) {
const l2p::Vector &pos = m->points[m->vertexes[n.vert_pool + vert_index].vertex];
const Ogre::Vector3 dist(ogre_cast(pos) - base);
const Ogre::Vector2 tcoord((dist | uvec) / float(usize), (dist | vvec) / float(vsize));
bounds += pos;
vertex_data.push_back(pos.X);
vertex_data.push_back(pos.Y);
vertex_data.push_back(pos.Z);
vertex_data.push_back(Normal.X);
vertex_data.push_back(Normal.Y);
vertex_data.push_back(Normal.Z);
vertex_data.push_back(tcoord.x);
vertex_data.push_back(tcoord.y);
}
if (s.flags & l2p::PF_TwoSided) {
for (uint32_t vert_index = 0; vert_index < n.num_verticies; ++vert_index) {
const l2p::Vector &pos = m->points[m->vertexes[n.vert_pool + vert_index].vertex];
const Ogre::Vector3 dist(ogre_cast(pos) - base);
const Ogre::Vector2 tcoord((dist | uvec) / float(usize), (dist | vvec) / float(vsize));
vertex_data.push_back(pos.X);
vertex_data.push_back(pos.Y);
vertex_data.push_back(pos.Z);
vertex_data.push_back(Normal.X);
vertex_data.push_back(Normal.Y);
vertex_data.push_back(-Normal.Z);
vertex_data.push_back(tcoord.x);
vertex_data.push_back(tcoord.y);
}
}
}
// Index buffer.
for (int verti = 2; verti < n.num_verticies; ++verti) {
index_buf.push_back(vert_start);
index_buf.push_back(vert_start + verti - 1);
index_buf.push_back(vert_start + verti);
}
if (s.flags & l2p::PF_TwoSided) {
for (int verti = 2; verti < n.num_verticies; ++verti) {
index_buf.push_back(vert_start);
index_buf.push_back(vert_start + verti);
index_buf.push_back(vert_start + verti - 1);
}
}
}
if (vertex_data.size() == 0 || index_buf.size() == 0)
return nullptr;
Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().createManual(Ogre::String(name) + Ogre::String(m->name), "General");
Ogre::VertexData *data = new Ogre::VertexData();
mesh->sharedVertexData = data;
data->vertexCount = vertex_data.size() / 8;
Ogre::VertexDeclaration *decl = data->vertexDeclaration;
uint32_t offset = 0;
decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
decl->addElement(0, offset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);
Ogre::HardwareVertexBufferSharedPtr vbuf =
Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
offset,
data->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
vbuf->writeData(0, vbuf->getSizeInBytes(), &vertex_data.front(), true);
data->vertexBufferBinding->setBinding(0, vbuf);
// Setup index buffer.
Ogre::HardwareIndexBufferSharedPtr ibuf =
Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
Ogre::HardwareIndexBuffer::IT_32BIT,
index_buf.size(),
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
ibuf->writeData(0, ibuf->getSizeInBytes(), &index_buf.front(), true);
Ogre::SubMesh *subMesh = mesh->createSubMesh();
subMesh->useSharedVertices = true;
subMesh->indexData->indexBuffer = ibuf;
subMesh->indexData->indexCount = index_buf.size();
subMesh->indexData->indexStart = 0;
mesh->_setBounds(Ogre::AxisAlignedBox(bounds.min.X, bounds.min.Y, bounds.min.Z, bounds.max.X, bounds.max.Y, bounds.max.Z));
mesh->_setBoundingSphereRadius((std::max(bounds.max.X - bounds.min.X, std::max(bounds.max.Y - bounds.min.Y, bounds.max.Z - bounds.min.Z))) / 2.0);
mesh->load();
Ogre::Entity *ent = mSceneMgr->createEntity(Ogre::String(name) + Ogre::String(m->name) + "E", Ogre::String(name) + Ogre::String(m->name));
ent->setUserAny(Ogre::Any(static_cast<l2p::UObject*>(m.get())));
ent->setMaterialName("StaticMesh/Default");
Ogre::SceneNode *node = mUnrealCordNode->createChildSceneNode();
node->attachObject(ent);
return node;
}
示例6: TOSTRING
//.........这里部分代码省略.........
size_t offset = 0;
mesh->sharedVertexData->vertexDeclaration->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
mesh->sharedVertexData->vertexDeclaration->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_TEXTURE_COORDINATES);
// Create and bind vertex buffer
mesh->sharedVertexData->vertexCount = 14;
Ogre::HardwareVertexBufferSharedPtr vertexBuffer =
Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
mesh->sharedVertexData->vertexDeclaration->getVertexSize(0),
mesh->sharedVertexData->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
mesh->sharedVertexData->vertexBufferBinding->setBinding(0, vertexBuffer);
// Vertex data
static const float vertexData[] = {
// Position Texture coordinates // Index
0.0, 2.0, -1.0, 1.0, 1.0, // 0
0.0, 1.0, -1.0, -1.0, 1.0, // 1
1.0, 2.0, -1.0, 1.0, -1.0, // 2
1.0, 1.0, -1.0, -1.0, -1.0, // 3
2.0, 2.0, 1.0, 1.0, -1.0, // 4
2.0, 1.0, 1.0, -1.0, -1.0, // 5
3.0, 2.0, 1.0, 1.0, 1.0, // 6
3.0, 1.0, 1.0, -1.0, 1.0, // 7
4.0, 2.0, -1.0, 1.0, 1.0, // 8
4.0, 1.0, -1.0, -1.0, 1.0, // 9
1.0, 3.0, -1.0, 1.0, 1.0, // 10
2.0, 3.0, 1.0, 1.0, 1.0, // 11
1.0, 0.0, -1.0, -1.0, 1.0, // 12
2.0, 0.0, 1.0, -1.0, 1.0, // 13
};
// Fill vertex buffer
float* pData = static_cast<float*>(vertexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));
for (size_t vertex = 0, i = 0; vertex < mesh->sharedVertexData->vertexCount; vertex++)
{
// Position
*pData++ = position.x + scale * vertexData[i++];
*pData++ = position.y + scale * vertexData[i++];
*pData++ = 0.0;
// Texture coordinates
*pData++ = vertexData[i++];
*pData++ = vertexData[i++];
*pData++ = vertexData[i++];
}
vertexBuffer->unlock();
// Create index buffer
sub->indexData->indexCount = 36;
Ogre::HardwareIndexBufferSharedPtr indexBuffer =
Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
Ogre::HardwareIndexBuffer::IT_16BIT,
sub->indexData->indexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
sub->indexData->indexBuffer = indexBuffer;
// Index data
static const Ogre::uint16 indexData[] = {
// Indices // Face
0, 1, 2, // 0
2, 1, 3, // 1
2, 3, 4, // 2
4, 3, 5, // 3
4, 5, 6, // 4
6, 5, 7, // 5
6, 7, 8, // 6
8, 7, 9, // 7
10, 2, 11, // 8
11, 2, 4, // 9
3, 12, 5, // 10
5, 12, 13, // 11
};
// Fill index buffer
indexBuffer->writeData(0, indexBuffer->getSizeInBytes(), indexData, true);
mesh->_setBounds(Ogre::AxisAlignedBox::BOX_INFINITE);
mesh->_setBoundingSphereRadius(10);
mesh->load();
Ogre::Entity* e = gEnv->sceneManager->createEntity(mesh->getName());
e->setCastShadows(false);
e->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY - 1);
e->setVisible(true);
e->setMaterialName("tracks/EnvMapDebug");
Ogre::SceneNode* mDebugSceneNode = new Ogre::SceneNode(gEnv->sceneManager);
mDebugSceneNode->attachObject(e);
mDebugSceneNode->setPosition(Ogre::Vector3(0, 0, -5));
mDebugSceneNode->setFixedYawAxis(true, Ogre::Vector3::UNIT_Y);
mDebugSceneNode->setVisible(true);
mDebugSceneNode->_update(true, true);
mDebugSceneNode->_updateBounds();
overlay->add3D(mDebugSceneNode);
overlay->show();
}
}
}
示例7: getVertexSize
/*求对象rend和射线ray的全部交点到射线原点的距离
*/
vector<Ogre::Real> BaseManager::Intersect(const Ogre::Ray& ray,Ogre::Renderable *rend){
Ogre::RenderOperation op;
Ogre::VertexElementType vtype;
size_t offset,pkgsize,source,indexNums,vertexNums;
vector<Ogre::Real> result;
rend->getRenderOperation( op );
if( !op.indexData ||
op.operationType==Ogre::RenderOperation::OT_LINE_LIST ||
op.operationType==Ogre::RenderOperation::OT_LINE_STRIP ||
op.operationType==Ogre::RenderOperation::OT_POINT_LIST )
return result;
Ogre::VertexDeclaration* pvd = op.vertexData->vertexDeclaration;
source = -1;
for( size_t i = 0;i < pvd->getElementCount();++i ){
if( pvd->getElement(i)->getSemantic()==Ogre::VES_POSITION ){
source = pvd->getElement(i)->getSource();
offset = pvd->getElement(i)->getOffset();
vtype = pvd->getElement(i)->getType();
break;
}
}
if( source == - 1 || vtype != Ogre::VET_FLOAT3 ) //别的格式目前没有考虑
return result;
/*source对应与一个缓存区
getVertexSize(source)求缓存区中一个紧密数据包的大小
例如:一个数据包里面包括POSITION,COLOR,NORMAL,TEXCROOD然后在这个缓冲
区中循环。而getVertexSize求出这个包的字节大小
例如POSITION(FLOAT3) TEXCROOD(FLOAT2) 这样前面的是12字节后面的是8字节
getVertexSize返回20
*/
pkgsize = pvd->getVertexSize(source);
Ogre::HardwareVertexBufferSharedPtr hvb = op.vertexData->vertexBufferBinding->getBuffer(source);
Ogre::HardwareIndexBufferSharedPtr ivb = op.indexData->indexBuffer;
Ogre::HardwareIndexBuffer::IndexType indexType = op.indexData->indexBuffer->getType();
/*先将顶点数据复制一份,然后变换到世界坐标系
*/
vertexNums = hvb->getNumVertices();
indexNums = ivb->getNumIndexes();
boost::scoped_array<float> vp( new float[3*vertexNums] );
boost::scoped_array<unsigned int> ip( new unsigned int[indexNums] );
{
Ogre::Vector3 p3;
Ogre::Matrix4 mat;
rend->getWorldTransforms( &mat );
float* preal = (float*)hvb->lock( Ogre::HardwareBuffer::HBL_READ_ONLY );
float* ptarget = vp.get();
//这里考虑到对齐,我假设offset和pkgsize都可以被sizeof(float)整除
preal += offset/sizeof(float);
size_t strip = pkgsize/sizeof(float);
for( size_t i = 0; i < vertexNums;++i ){
p3.x = *preal;
p3.y = *(preal+1);
p3.z = *(preal+2);
p3 = mat * p3;
*ptarget++ = p3.x;
*ptarget++ = p3.y;
*ptarget++ = p3.z;
preal += strip;
}
hvb->unlock();
}
//拷贝出顶点数据
{
unsigned int* pindex32 = ip.get();
if( indexType==Ogre::HardwareIndexBuffer::IT_16BIT ){
unsigned short* pi16 = (unsigned short*)ivb->lock( Ogre::HardwareBuffer::HBL_READ_ONLY );
copy( pi16,pi16+indexNums,pindex32 );
}else
memcpy( pindex32,ivb->lock( Ogre::HardwareBuffer::HBL_READ_ONLY ),ivb->getSizeInBytes() );
ivb->unlock();
}
/*数据都准备好了,vp保存了变换好的顶点,ip保存了顶点索引
下面根据情况求交点
*/
switch( op.operationType ){
case Ogre::RenderOperation::OT_TRIANGLE_LIST:
{ /* 0,1,2 组成一个三角 3,4,5 下一个...
*/
Ogre::Vector3 a[3],n;
int index,k = 0;
float* preal = vp.get();
unsigned int* pindex = ip.get();
for( size_t i = 0;i<indexNums;++i ){
if( pindex[i] < vertexNums ){
index = pindex[i]*3; //对应与格式VET_FLOAT3
a[k].x = preal[index];
a[k].y = preal[index+1];
a[k].z = preal[index+2];
//.........这里部分代码省略.........
示例8: createLine
void WaterObjectView::createLine()
{
size_t verticesCount = ((mWaterObject->getPointCount() - 1) * mSegments + 1) * 2;
size_t verticesSize = verticesCount * 5;
size_t indicesSize = ((mWaterObject->getPointCount() - 1) * mSegments) * 6;
verticesCount = mWaterObject->getPointCount() * 2;
verticesSize = verticesCount * 5;
indicesSize = (mWaterObject->getPointCount() - 1) * 6;
Ogre::Real* vertices = new Ogre::Real[verticesSize];
Ogre::uint16* indices = new Ogre::uint16[indicesSize];
unsigned int i, index = 0;
// Prepare vertices.
for (i = 0; i < mWaterObject->getPointCount(); ++i)
{
const Point3D& point3D = mWaterObject->getPoint(i);
vertices[index++] = point3D.x - mWaterObject->getWidth() * 0.5f;
vertices[index++] = point3D.y;
vertices[index++] = point3D.z + 1.0f;
vertices[index++] = point3D.x - mWaterObject->getWidth() * 0.5f;;
vertices[index++] = point3D.z;
vertices[index++] = point3D.x + mWaterObject->getWidth() * 0.5f;
vertices[index++] = point3D.y;
vertices[index++] = point3D.z + 1.0f;
vertices[index++] = point3D.x + mWaterObject->getWidth() * 0.5f;
vertices[index++] = point3D.z;
}
index = 0;
// Prepare indices.
for (i = 0; i < verticesCount - 2; i += 2)
{
indices[index++] = (Ogre::uint16)i;
indices[index++] = (Ogre::uint16)i + 2;
indices[index++] = (Ogre::uint16)i + 1;
indices[index++] = (Ogre::uint16)i + 2;
indices[index++] = (Ogre::uint16)i + 3;
indices[index++] = (Ogre::uint16)i + 1;
}
// Create mesh.
mMesh = Ogre::MeshManager::getSingleton().createManual(
Ogre::StringConverter::toString(mID), "General").get();
// Create one submesh.
Ogre::SubMesh* sub = mMesh->createSubMesh();
// Create vertex data structure for 8 vertices shared between submeshes.
mMesh->sharedVertexData = new Ogre::VertexData();
mMesh->sharedVertexData->vertexCount = verticesCount;
// Create declaration (memory format) of vertex data.
Ogre::VertexDeclaration* decl = mMesh->sharedVertexData->vertexDeclaration;
size_t offset = 0;
// 1st buffer
decl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
decl->addElement(0, offset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);
/// Allocate vertex buffer of the requested number of vertices (vertexCount)
/// and bytes per vertex (offset)
Ogre::HardwareVertexBufferSharedPtr vbuf =
Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
offset, mMesh->sharedVertexData->vertexCount,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
/// Upload the vertex data to the card
vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true);
/// Set vertex buffer binding so buffer 0 is bound to our vertex buffer
Ogre::VertexBufferBinding* bind =
mMesh->sharedVertexData->vertexBufferBinding;
bind->setBinding(0, vbuf);
/// Allocate index buffer of the requested number of vertices (ibufCount).
Ogre::HardwareIndexBufferSharedPtr ibuf = Ogre::HardwareBufferManager::getSingleton().
createIndexBuffer(
Ogre::HardwareIndexBuffer::IT_16BIT,
indicesSize,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
/// Upload the index data to the card.
ibuf->writeData(0, ibuf->getSizeInBytes(), indices, true);
/// Set parameters of the submesh.
sub->useSharedVertices = true;
sub->indexData->indexBuffer = ibuf;
sub->indexData->indexCount = indicesSize;
//.........这里部分代码省略.........
示例9: diffuse
Rocket::Core::CompiledGeometryHandle RocketInterface::CompileGeometry(
Rocket::Core::Vertex* vertices, int numVertices, int* indices, int numIndices,
Rocket::Core::TextureHandle texture)
{
RocketOgreGeometry* geometry = new RocketOgreGeometry();
geometry->texture = texture == 0 ? nullptr : reinterpret_cast<RocketOgreTexture*>(texture);
geometry->renderOp.vertexData = new Ogre::VertexData();
geometry->renderOp.vertexData->vertexStart = 0;
geometry->renderOp.vertexData->vertexCount = numVertices;
geometry->renderOp.indexData = new Ogre::IndexData();
geometry->renderOp.indexData->indexStart = 0;
geometry->renderOp.indexData->indexCount = numIndices;
geometry->renderOp.operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
// Set up the vertex declaration
Ogre::VertexDeclaration* vertexDecl = geometry->renderOp.vertexData->vertexDeclaration;
size_t offset = 0;
vertexDecl->addElement(0, offset, Ogre::VET_FLOAT2, Ogre::VES_POSITION);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);
vertexDecl->addElement(0, offset, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE);
offset += Ogre::VertexElement::getTypeSize(Ogre::VET_COLOUR);
vertexDecl->addElement(0, offset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES);
// Create the vertex buffer
Ogre::HardwareVertexBufferSharedPtr vb =
Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
vertexDecl->getVertexSize(0), numVertices, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
geometry->renderOp.vertexData->vertexBufferBinding->setBinding(0, vb);
// Fill the vertex buffer
RocketOgreVertex* vertexData = static_cast<RocketOgreVertex*>(
vb->lock(0, vb->getSizeInBytes(), Ogre::HardwareBuffer::HBL_NORMAL));
for (int i = 0; i < numVertices; ++i)
{
vertexData[i].position.x = vertices[i].position.x;
vertexData[i].position.y = vertices[i].position.y;
vertexData[i].uv.x = vertices[i].tex_coord[0];
vertexData[i].uv.y = vertices[i].tex_coord[1];
// Calculate colour value
Ogre::ColourValue diffuse(
vertices[i].colour.red / 255.0f, vertices[i].colour.green / 255.0f,
vertices[i].colour.blue / 255.0f, vertices[i].colour.alpha / 255.0f);
// Scale colour by gamma value (2.2)
diffuse.r = Pow(diffuse.r, 2.2f);
diffuse.g = Pow(diffuse.g, 2.2f);
diffuse.b = Pow(diffuse.b, 2.2f);
diffuse.a = Pow(diffuse.a, 2.2f);
mRenderSystem->convertColourValue(diffuse, &vertexData[i].colour);
}
vb->unlock();
// Create the index buffer
Ogre::HardwareIndexBufferSharedPtr ib =
Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
Ogre::HardwareIndexBuffer::IT_32BIT, numIndices,
Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
geometry->renderOp.indexData->indexBuffer = ib;
geometry->renderOp.useIndexes = true;
// Fill the index buffer
void* indexData = ib->lock(0, ib->getSizeInBytes(), Ogre::HardwareBuffer::HBL_NORMAL);
memcpy(indexData, indices, sizeof(unsigned int) * numIndices);
ib->unlock();
return reinterpret_cast<Rocket::Core::CompiledGeometryHandle>(geometry);
}