本文整理汇总了C++中ea::vector::size方法的典型用法代码示例。如果您正苦于以下问题:C++ vector::size方法的具体用法?C++ vector::size怎么用?C++ vector::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ea::vector
的用法示例。
在下文中一共展示了vector::size方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetBuffer
bool XMLElement::SetBuffer(const ea::string& name, const ea::vector<unsigned char>& value)
{
if (!value.size())
return SetAttribute(name, EMPTY_STRING);
else
return SetBuffer(name, &value[0], value.size());
}
示例2: ConstructBatch
void Text::ConstructBatch(UIBatch& pageBatch, const ea::vector<GlyphLocation>& pageGlyphLocation, float dx, float dy, Color* color,
float depthBias)
{
unsigned startDataSize = pageBatch.vertexData_->size();
if (!color)
pageBatch.SetDefaultColor();
else
pageBatch.SetColor(*color);
for (unsigned i = 0; i < pageGlyphLocation.size(); ++i)
{
const GlyphLocation& glyphLocation = pageGlyphLocation[i];
const FontGlyph& glyph = *glyphLocation.glyph_;
pageBatch.AddQuad(dx + glyphLocation.x_ + glyph.offsetX_, dy + glyphLocation.y_ + glyph.offsetY_, glyph.width_,
glyph.height_, glyph.x_, glyph.y_, glyph.texWidth_, glyph.texHeight_);
}
if (depthBias != 0.0f)
{
unsigned dataSize = pageBatch.vertexData_->size();
for (unsigned i = startDataSize; i < dataSize; i += UI_VERTEX_SIZE)
pageBatch.vertexData_->at(i + 2) += depthBias;
}
}
示例3: Manipulate
bool Gizmo::Manipulate(const Camera* camera, const ea::vector<WeakPtr<Node>>& nodes)
{
if (nodes.empty())
return false;
ImGuizmo::SetOrthographic(camera->IsOrthographic());
if (!IsActive())
{
if (nodes.size() > 1)
{
// Find center point of all nodes
// It is not clear what should be rotation and scale of center point for multiselection, therefore we limit
// multiselection operations to world space (see above).
Vector3
center = Vector3::ZERO;
auto count = 0;
for (const auto& node: nodes)
{
if (node.Expired() || node->GetType() == Scene::GetTypeStatic())
continue;
center += node->GetWorldPosition();
count++;
}
if (count == 0)
return false;
center /= count;
currentOrigin_.SetTranslation(center);
}
else if (!nodes.front().Expired())
currentOrigin_ = nodes.front()->GetTransform().ToMatrix4();
}
// Enums are compatible.
auto operation = static_cast<ImGuizmo::OPERATION>(operation_);
ImGuizmo::MODE mode = ImGuizmo::WORLD;
// Scaling only works in local space. Multiselections only work in world space.
if (transformSpace_ == TS_LOCAL)
mode = ImGuizmo::LOCAL;
else if (transformSpace_ == TS_WORLD)
mode = ImGuizmo::WORLD;
// Scaling is always done in local space even for multiselections.
if (operation_ == GIZMOOP_SCALE)
mode = ImGuizmo::LOCAL;
// Any other operations on multiselections are done in world space.
else if (nodes.size() > 1)
mode = ImGuizmo::WORLD;
Matrix4 view = camera->GetView().ToMatrix4().Transpose();
Matrix4 proj = camera->GetProjection().Transpose();
Matrix4 tran = currentOrigin_.Transpose();
Matrix4 delta;
ImGuiIO& io = ImGui::GetIO();
auto pos = displayPos_;
auto size = displaySize_;
if (size.x == 0 && size.y == 0)
size = io.DisplaySize;
ImGuizmo::SetRect(pos.x, pos.y, size.x, size.y);
ImGuizmo::Manipulate(&view.m00_, &proj.m00_, operation, mode, &tran.m00_, &delta.m00_, nullptr);
if (IsActive())
{
if (!wasActive_)
{
// Just started modifying nodes.
for (const auto& node: nodes)
initialTransforms_[node] = node->GetTransform();
}
wasActive_ = true;
tran = tran.Transpose();
delta = delta.Transpose();
currentOrigin_ = Matrix4(tran);
for (const auto& node: nodes)
{
if (node == nullptr)
{
URHO3D_LOGERROR("Gizmo received null pointer of node.");
continue;
}
if (operation_ == GIZMOOP_SCALE)
{
// A workaround for ImGuizmo bug where delta matrix returns absolute scale value.
if (!nodeScaleStart_.contains(node))
nodeScaleStart_[node] = node->GetScale();
node->SetScale(nodeScaleStart_[node] * delta.Scale());
}
else
{
// Delta matrix is always in world-space.
if (operation_ == GIZMOOP_ROTATE)
node->RotateAround(currentOrigin_.Translation(), -delta.Rotation(), TS_WORLD);
//.........这里部分代码省略.........
示例4: WriteOutput
void WriteOutput(const ea::string& outputFileName, bool exportAnimations, bool rotationsOnly, bool saveMaterialList)
{
/// \todo Use save functions of Model & Animation classes
// Begin serialization
{
File dest(context_);
if (!dest.Open(outputFileName, FILE_WRITE))
ErrorExit("Could not open output file " + outputFileName);
// ID
dest.WriteFileID("UMD2");
// Vertexbuffers
dest.WriteUInt(vertexBuffers_.size());
for (unsigned i = 0; i < vertexBuffers_.size(); ++i)
vertexBuffers_[i].WriteData(dest);
// Indexbuffers
dest.WriteUInt(indexBuffers_.size());
for (unsigned i = 0; i < indexBuffers_.size(); ++i)
indexBuffers_[i].WriteData(dest);
// Subgeometries
dest.WriteUInt(subGeometries_.size());
for (unsigned i = 0; i < subGeometries_.size(); ++i)
{
// Write bone mapping info from the first LOD level. It does not change for further LODs
dest.WriteUInt(subGeometries_[i][0].boneMapping_.size());
for (unsigned k = 0; k < subGeometries_[i][0].boneMapping_.size(); ++k)
dest.WriteUInt(subGeometries_[i][0].boneMapping_[k]);
// Lod levels for this subgeometry
dest.WriteUInt(subGeometries_[i].size());
for (unsigned j = 0; j < subGeometries_[i].size(); ++j)
{
dest.WriteFloat(subGeometries_[i][j].distance_);
dest.WriteUInt((unsigned)subGeometries_[i][j].primitiveType_);
dest.WriteUInt(subGeometries_[i][j].vertexBuffer_);
dest.WriteUInt(subGeometries_[i][j].indexBuffer_);
dest.WriteUInt(subGeometries_[i][j].indexStart_);
dest.WriteUInt(subGeometries_[i][j].indexCount_);
}
}
// Morphs
dest.WriteUInt(morphs_.size());
for (unsigned i = 0; i < morphs_.size(); ++i)
morphs_[i].WriteData(dest);
// Skeleton
dest.WriteUInt(bones_.size());
for (unsigned i = 0; i < bones_.size(); ++i)
{
dest.WriteString(bones_[i].name_);
dest.WriteUInt(bones_[i].parentIndex_);
dest.WriteVector3(bones_[i].bindPosition_);
dest.WriteQuaternion(bones_[i].bindRotation_);
dest.WriteVector3(bones_[i].bindScale_);
Matrix3x4 offsetMatrix(bones_[i].derivedPosition_, bones_[i].derivedRotation_, bones_[i].derivedScale_);
offsetMatrix = offsetMatrix.Inverse();
dest.Write(offsetMatrix.Data(), sizeof(Matrix3x4));
dest.WriteUByte(bones_[i].collisionMask_);
if (bones_[i].collisionMask_ & 1u)
dest.WriteFloat(bones_[i].radius_);
if (bones_[i].collisionMask_ & 2u)
dest.WriteBoundingBox(bones_[i].boundingBox_);
}
// Bounding box
dest.WriteBoundingBox(boundingBox_);
// Geometry centers
for (unsigned i = 0; i < subGeometryCenters_.size(); ++i)
dest.WriteVector3(subGeometryCenters_[i]);
}
if (saveMaterialList)
{
ea::string materialListName = ReplaceExtension(outputFileName, ".txt");
File listFile(context_);
if (listFile.Open(materialListName, FILE_WRITE))
{
for (unsigned i = 0; i < materialNames_.size(); ++i)
{
// Assume the materials will be located inside the standard Materials subdirectory
listFile.WriteLine("Materials/" + ReplaceExtension(SanitateAssetName(materialNames_[i]), ".xml"));
}
}
else
PrintLine("Warning: could not write material list file " + materialListName);
}
XMLElement skeletonRoot = skelFile_->GetRoot("skeleton");
if (skeletonRoot && exportAnimations)
{
// Go through animations
XMLElement animationsRoot = skeletonRoot.GetChild("animations");
//.........这里部分代码省略.........
示例5: Run
void Run(const ea::vector<ea::string>& arguments)
{
if (arguments.size() < 2)
{
ErrorExit(
"Usage: OgreImporter <input file> <output file> [options]\n\n"
"Options:\n"
"-l Output a material list file\n"
"-na Do not output animations\n"
"-nm Do not output morphs\n"
"-r Output only rotations from animations\n"
"-s Split each submesh into own vertex buffer\n"
"-t Generate tangents\n"
"-mb <x> Maximum number of bones per submesh, default 64\n"
);
}
bool generateTangents = false;
bool splitSubMeshes = false;
bool exportAnimations = true;
bool exportMorphs = true;
bool rotationsOnly = false;
bool saveMaterialList = false;
if (arguments.size() > 2)
{
for (unsigned i = 2; i < arguments.size(); ++i)
{
if (arguments[i].length() > 1 && arguments[i][0] == '-')
{
ea::string argument = arguments[i].substr(1).to_lower();
if (argument == "l")
saveMaterialList = true;
else if (argument == "r")
rotationsOnly = true;
else if (argument == "s")
splitSubMeshes = true;
else if (argument == "t")
generateTangents = true;
else if (argument.length() == 2 && argument[0] == 'n')
{
switch (tolower(argument[1]))
{
case 'a':
exportAnimations = false;
break;
case 'm':
exportMorphs = false;
break;
}
break;
}
else if (argument == "mb" && i < arguments.size() - 1)
{
maxBones_ = ToUInt(arguments[i + 1]);
if (maxBones_ < 1)
maxBones_ = 1;
++i;
}
}
}
}
LoadMesh(arguments[0], generateTangents, splitSubMeshes, exportMorphs);
WriteOutput(arguments[1], exportAnimations, rotationsOnly, saveMaterialList);
PrintLine("Finished");
}
示例6: LoadMesh
void LoadMesh(const ea::string& inputFileName, bool generateTangents, bool splitSubMeshes, bool exportMorphs)
{
File meshFileSource(context_);
meshFileSource.Open(inputFileName);
if (!meshFile_->Load(meshFileSource))
ErrorExit("Could not load input file " + inputFileName);
XMLElement root = meshFile_->GetRoot("mesh");
XMLElement subMeshes = root.GetChild("submeshes");
XMLElement skeletonLink = root.GetChild("skeletonlink");
if (root.IsNull())
ErrorExit("Could not load input file " + inputFileName);
ea::string skeletonName = skeletonLink.GetAttribute("name");
if (!skeletonName.empty())
LoadSkeleton(GetPath(inputFileName) + GetFileName(skeletonName) + ".skeleton.xml");
// Check whether there's benefit of avoiding 32bit indices by splitting each submesh into own buffer
XMLElement subMesh = subMeshes.GetChild("submesh");
unsigned totalVertices = 0;
unsigned maxSubMeshVertices = 0;
while (subMesh)
{
materialNames_.push_back(subMesh.GetAttribute("material"));
XMLElement geometry = subMesh.GetChild("geometry");
if (geometry)
{
unsigned vertices = geometry.GetInt("vertexcount");
totalVertices += vertices;
if (maxSubMeshVertices < vertices)
maxSubMeshVertices = vertices;
}
++numSubMeshes_;
subMesh = subMesh.GetNext("submesh");
}
XMLElement sharedGeometry = root.GetChild("sharedgeometry");
if (sharedGeometry)
{
unsigned vertices = sharedGeometry.GetInt("vertexcount");
totalVertices += vertices;
if (maxSubMeshVertices < vertices)
maxSubMeshVertices = vertices;
}
if (!sharedGeometry && (splitSubMeshes || (totalVertices > 65535 && maxSubMeshVertices <= 65535)))
{
useOneBuffer_ = false;
vertexBuffers_.resize(numSubMeshes_);
indexBuffers_.resize(numSubMeshes_);
}
else
{
vertexBuffers_.resize(1);
indexBuffers_.resize(1);
}
subMesh = subMeshes.GetChild("submesh");
unsigned indexStart = 0;
unsigned vertexStart = 0;
unsigned subMeshIndex = 0;
ea::vector<unsigned> vertexStarts;
vertexStarts.resize(numSubMeshes_);
while (subMesh)
{
XMLElement geometry = subMesh.GetChild("geometry");
XMLElement faces = subMesh.GetChild("faces");
// If no submesh vertexbuffer, process the shared geometry, but do it only once
unsigned vertices = 0;
if (!geometry)
{
vertexStart = 0;
if (!subMeshIndex)
geometry = root.GetChild("sharedgeometry");
}
if (geometry)
vertices = geometry.GetInt("vertexcount");
ModelSubGeometryLodLevel subGeometryLodLevel;
ModelVertexBuffer* vBuf;
ModelIndexBuffer* iBuf;
if (useOneBuffer_)
{
vBuf = &vertexBuffers_[0];
if (vertices)
vBuf->vertices_.resize(vertexStart + vertices);
iBuf = &indexBuffers_[0];
subGeometryLodLevel.vertexBuffer_ = 0;
subGeometryLodLevel.indexBuffer_ = 0;
}
else
{
vertexStart = 0;
//.........这里部分代码省略.........
示例7: LoadSkeleton
void LoadSkeleton(const ea::string& skeletonFileName)
{
// Process skeleton first (if found)
XMLElement skeletonRoot;
File skeletonFileSource(context_);
skeletonFileSource.Open(skeletonFileName);
if (!skelFile_->Load(skeletonFileSource))
PrintLine("Failed to load skeleton " + skeletonFileName);
skeletonRoot = skelFile_->GetRoot();
if (skeletonRoot)
{
XMLElement bonesRoot = skeletonRoot.GetChild("bones");
XMLElement bone = bonesRoot.GetChild("bone");
while (bone)
{
unsigned index = bone.GetInt("id");
ea::string name = bone.GetAttribute("name");
if (index >= bones_.size())
bones_.resize(index + 1);
// Convert from right- to left-handed
XMLElement position = bone.GetChild("position");
float x = position.GetFloat("x");
float y = position.GetFloat("y");
float z = position.GetFloat("z");
Vector3 pos(x, y, -z);
XMLElement rotation = bone.GetChild("rotation");
XMLElement axis = rotation.GetChild("axis");
float angle = -rotation.GetFloat("angle") * M_RADTODEG;
x = axis.GetFloat("x");
y = axis.GetFloat("y");
z = axis.GetFloat("z");
Vector3 axisVec(x, y, -z);
Quaternion rot(angle, axisVec);
bones_[index].name_ = name;
bones_[index].parentIndex_ = index; // Fill in the correct parent later
bones_[index].bindPosition_ = pos;
bones_[index].bindRotation_ = rot;
bones_[index].bindScale_ = Vector3::ONE;
bones_[index].collisionMask_ = 0;
bones_[index].radius_ = 0.0f;
bone = bone.GetNext("bone");
}
// Go through the bone hierarchy
XMLElement boneHierarchy = skeletonRoot.GetChild("bonehierarchy");
XMLElement boneParent = boneHierarchy.GetChild("boneparent");
while (boneParent)
{
ea::string bone = boneParent.GetAttribute("bone");
ea::string parent = boneParent.GetAttribute("parent");
unsigned i = 0, j = 0;
for (i = 0; i < bones_.size() && bones_[i].name_ != bone; ++i);
for (j = 0; j < bones_.size() && bones_[j].name_ != parent; ++j);
if (i >= bones_.size() || j >= bones_.size())
ErrorExit("Found indeterminate parent bone assignment");
bones_[i].parentIndex_ = j;
boneParent = boneParent.GetNext("boneparent");
}
// Calculate bone derived positions
for (unsigned i = 0; i < bones_.size(); ++i)
{
Vector3 derivedPosition = bones_[i].bindPosition_;
Quaternion derivedRotation = bones_[i].bindRotation_;
Vector3 derivedScale = bones_[i].bindScale_;
unsigned index = bones_[i].parentIndex_;
if (index != i)
{
for (;;)
{
derivedPosition = bones_[index].bindPosition_ + (bones_[index].bindRotation_ * (bones_[index].bindScale_ * derivedPosition));
derivedRotation = bones_[index].bindRotation_ * derivedRotation;
derivedScale = bones_[index].bindScale_ * derivedScale;
if (bones_[index].parentIndex_ != index)
index = bones_[index].parentIndex_;
else
break;
}
}
bones_[i].derivedPosition_ = derivedPosition;
bones_[i].derivedRotation_ = derivedRotation;
bones_[i].derivedScale_ = derivedScale;
bones_[i].worldTransform_ = Matrix3x4(derivedPosition, derivedRotation, derivedScale);
bones_[i].inverseWorldTransform_ = bones_[i].worldTransform_.Inverse();
}
PrintLine("Processed skeleton");
}
}
示例8: SetData
void VectorBuffer::SetData(const ea::vector<unsigned char>& data)
{
buffer_ = data;
position_ = 0;
size_ = data.size();
}