本文整理汇总了C++中Vertex函数的典型用法代码示例。如果您正苦于以下问题:C++ Vertex函数的具体用法?C++ Vertex怎么用?C++ Vertex使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Vertex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Vertex
vector<int> Graph::getShortestPath(int start, int finish) {
map<int,int> distances;
priority_queue<Vertex> nodes;
map<int,Vertex> previous;
vector<int> path;
map<int, vector<Vertex> >::iterator it;
map<int, int>::iterator dis_it;
map<int, Vertex>::iterator pre_it;
for(it = this->vertexes.begin(); it != this->vertexes.end(); ++it) {
if (it->first == start) {
distances.insert(make_pair(start, 0));
nodes.push(Vertex(start, 0));
} else {
distances.insert(make_pair(it->first, MAX_VALUE));
nodes.push(Vertex(it->first, MAX_VALUE));
}
previous.insert(make_pair(it->first, Vertex(-1, 0)));
}
while(!nodes.empty()) {
Vertex smallest = nodes.top();
nodes.pop();
if (smallest.getId() == finish) {
while((pre_it = previous.find(smallest.getId())) != previous.end() && pre_it->second.getId()!=-1) {
path.push_back(pre_it->first);
smallest = pre_it->second;
}
if (!path.empty()) {
path.push_back(start);
}
return path;
}
dis_it = distances.find(smallest.getId());
if (dis_it == distances.end()) {
cout << "can not find distance for:" << smallest.getId() << endl;
return path;
}
int distanceValue = dis_it->second;
if (distanceValue == MAX_VALUE) {
break;
}
it = this->vertexes.find(smallest.getId());
if (it == vertexes.end()) {
return path;
}
vector<Vertex> nearNodes = it->second;
for(int i = 0; i<nearNodes.size(); i++) {
int n_id = nearNodes[i].getId();
int n_dis = nearNodes[i].getDistance();
int alt = distanceValue + n_dis;
dis_it = distances.find(n_id);
if (dis_it == distances.end()) {
cout << "----------a----"<<endl;
return path;
}
int dd = dis_it->second;
bool need_fill = false;
if (alt < dd) {
//map无法覆盖key,只能下标方式
distances[n_id] = alt;
previous[n_id] = smallest;
vector<Vertex> tmp;
need_fill = true;
}
vector<Vertex> tmp;
while(!nodes.empty()) {
Vertex v = nodes.top();
nodes.pop();
if (v.getId() == n_id && need_fill == true) {
v.setDistance(alt);
}
tmp.push_back(v);
}
for (int k=0; k < tmp.size(); k++) {
nodes.push(tmp[k]);
}
}
}
vector<int> v;
//for(dis_it= distances.begin(); dis_it != distances.end(); dis_it++) {
// v.push_back(dis_it->first);
//}
return v;
}
示例2: preallocateMeshElements
bool MeshBuilder::buildMesh(const MeshData& data, Mesh& mesh)
{
std::map<std::pair<int, int>, int> edgeCount;
std::map<std::pair<int, int>, HalfEdgeIter> existingHalfEdges;
std::map<int, VertexIter> indexToVertex;
std::map<HalfEdgeIter, bool> hasFlipEdge;
preallocateMeshElements(data, mesh);
// insert vertices into mesh and map vertex indices to vertex pointers
for (unsigned int i = 0; i < data.positions.size(); i++) {
VertexIter vertex = mesh.vertices.insert(mesh.vertices.end(), Vertex());
vertex->position = data.positions[i];
vertex->he = isolated.begin();
indexToVertex[i] = vertex;
}
// insert uvs into mesh
for (unsigned int i = 0; i < data.uvs.size(); i++) {
VectorIter uv = mesh.uvs.insert(mesh.uvs.end(), Eigen::Vector3d());
*uv = data.uvs[i];
}
// insert normals into mesh
for (unsigned int i = 0; i < data.normals.size(); i++) {
VectorIter normal = mesh.normals.insert(mesh.normals.end(), Eigen::Vector3d());
*normal = data.normals[i];
}
// insert faces into mesh
int faceIndex = 0;
bool degenerateFaces = false;
for (std::vector<std::vector<Index>>::const_iterator f = data.indices.begin();
f != data.indices.end();
f ++) {
int n = (int)f->size();
// check if face is degenerate
if (n < 3) {
std::cerr << "Error: face " << faceIndex << " is degenerate" << std::endl;
degenerateFaces = true;
continue;
}
// create face
FaceIter newFace = mesh.faces.insert(mesh.faces.end(), Face());
// create a halfedge for each edge of the face
std::vector<HalfEdgeIter> halfEdges(n);
for (int i = 0; i < n; i++) {
halfEdges[i] = mesh.halfEdges.insert(mesh.halfEdges.end(), HalfEdge());
}
// initialize the halfedges
for (int i = 0; i < n; i++) {
// vertex indices
int a = (*f)[i].position;
int b = (*f)[(i+1)%n].position;
// set halfedge attributes
halfEdges[i]->next = halfEdges[(i+1)%n];
halfEdges[i]->vertex = indexToVertex[a];
int uv = (*f)[i].uv;
if (uv >= 0) halfEdges[i]->uv = data.uvs[uv];
else halfEdges[i]->uv.setZero();
int normal = (*f)[i].normal;
if (normal >= 0) halfEdges[i]->normal = data.normals[normal];
else halfEdges[i]->normal.setZero();
halfEdges[i]->onBoundary = false;
// keep track of which halfedges have flip edges defined (for deteting boundaries)
hasFlipEdge[halfEdges[i]] = false;
// point vertex a at the current halfedge
indexToVertex[a]->he = halfEdges[i];
// point new face and halfedge to each other
halfEdges[i]->face = newFace;
newFace->he = halfEdges[i];
// if an edge between a and b has been created in the past, it is the flip edge of the current halfedge
if (a > b) std::swap(a, b);
if (existingHalfEdges.find(std::pair<int, int>(a, b)) != existingHalfEdges.end()) {
halfEdges[i]->flip = existingHalfEdges[std::pair<int, int>(a, b)];
halfEdges[i]->flip->flip = halfEdges[i];
halfEdges[i]->edge = halfEdges[i]->flip->edge;
hasFlipEdge[halfEdges[i]] = true;
hasFlipEdge[halfEdges[i]->flip] = true;
} else {
// create an edge and set its halfedge
halfEdges[i]->edge = mesh.edges.insert(mesh.edges.end(), Edge());
halfEdges[i]->edge->he = halfEdges[i];
edgeCount[std::pair<int, int>(a, b)] = 0;
}
// record that halfedge has been created from a to b
//.........这里部分代码省略.........
示例3: glClearDepth
void Scene::render(RenderContext* renderContext)
{
renderContext->scene = this;
renderContext->viewpoint = viewpoint;
//
// CLEAR BUFFERS
//
GLbitfield clearFlags = 0;
// Depth Buffer
glClearDepth(1.0);
glDepthFunc(GL_LESS);
clearFlags |= GL_DEPTH_BUFFER_BIT;
// Color Buffer (optional - depends on background node)
clearFlags |= background->setupClear(renderContext);
// clear
glClear(clearFlags);
//
// SETUP LIGHTING MODEL
//
setupLightModel(renderContext);
Sphere total_bsphere;
if (data_bbox.isValid()) {
//
// GET DATA VOLUME SPHERE
//
total_bsphere = Sphere( (bboxDeco) ? bboxDeco->getBoundingBox(data_bbox) : data_bbox );
} else {
total_bsphere = Sphere( Vertex(0,0,0), 1 );
}
//
// SETUP VIEWPORT TRANSFORMATION
//
glViewport(0,0,renderContext->size.width, renderContext->size.height);
//
//
//
viewpoint->setupFrustum( renderContext, total_bsphere );
//
// RENDER BACKGROUND
//
background->render(renderContext);
//
// RENDER MODEL
//
if (data_bbox.isValid() ) {
//
// SETUP CAMERA
//
viewpoint->setupTransformation( renderContext, total_bsphere);
//
// RENDER BBOX DECO
//
if (bboxDeco)
bboxDeco->render(renderContext);
//
// RENDER SOLID SHAPES
//
glEnable(GL_DEPTH_TEST);
ListIterator iter(&shapes);
for(iter.first(); !iter.isDone(); iter.next() ) {
Shape* shape = (Shape*) iter.getCurrent();
//.........这里部分代码省略.........
示例4: Mesh
Model ModelsFactory::cylinder(long double radius, long double height, int sides)
{
height /= 2.0L;
Mesh *mesh = new Mesh();
Model model = Model(QString("(G) cylinder"), mesh, RGBA(0, 255, 0, 255));
int nbVerticesCap = sides + 1;
int verticesLength = nbVerticesCap + nbVerticesCap;// + sides * 2 + 2;
Vertex *vertices = new Vertex[verticesLength];
int vert = 0;
const long double _2pi = M_PI * 2.0L;
// Bottom cap
// Центральная вершина нижней крышки
vertices[vert++] = Vertex(0.0L, -height, 0.0L);
while (vert <= sides) {
long double rad = (long double)vert / sides * _2pi;
vertices[vert] = Vertex(std::cos(rad) * radius, -height, std::sin(rad) * radius);
vert++;
}
// Top cap
vertices[vert++] = Vertex(0.0L, height, 0.0L);
while (vert <= sides * 2 + 1) {
long double rad = (long double)(vert - sides - 1) / sides * _2pi;
vertices[vert] = Vertex(std::cos(rad) * radius, height, std::sin(rad) * radius);
vert++;
}
// Triangles
int nbTriangles = sides * 4;//sides * sides;// + sides * 2;
int *triangles = new int[nbTriangles * 3/* + 3*/];
// Bottom cap
int tri = 0;
int i = 0;
while (tri < sides - 1) {
triangles[i] = 0;
triangles[i + 1] = tri + 1;
triangles[i + 2] = tri + 2;
tri++;
i += 3;
}
triangles[i] = 0;
triangles[i + 1] = tri + 1;
triangles[i + 2] = 1;
tri++;
i += 3;
// Top cap
tri++;
while (tri < sides * 2) {
triangles[i] = tri + 2;
triangles[i + 1] = tri + 1;
triangles[i + 2] = nbVerticesCap;
tri++;
i += 3;
}
triangles[i] = nbVerticesCap + 1;
triangles[i + 1] = tri + 1;
triangles[i + 2] = nbVerticesCap;
tri++;
i += 3;
tri++;
// Sides
int j = tri;
while (j <= nbTriangles - 2) {
triangles[i] = tri - nbVerticesCap * 2 + 1;
triangles[i + 1] = tri - nbVerticesCap + 1;
triangles[i + 2] = tri - nbVerticesCap * 2 + 2;
//tri++;
j++;
i += 3;
triangles[i] = tri - nbVerticesCap * 2 + 2;
triangles[i + 1] = tri - nbVerticesCap + 1;
triangles[i + 2] = tri - nbVerticesCap + 2;
tri++;
j++;
i += 3;
}
triangles[i] = tri - nbVerticesCap * 2 + 1;
triangles[i + 1] = tri - nbVerticesCap + 1;
triangles[i + 2] = 1;
i += 3;
triangles[i] = 1;
triangles[i + 1] = tri - nbVerticesCap + 1;
//.........这里部分代码省略.........
示例5: ls
void
GeometricHelperTest::LineSegmentLineIntersectionTest() {
{
LineSegment ls(Vertex(0, 1), Vertex(1, 1));
Line line(Vertex(0, 0), Vertex(1, 2));
// segment/line intersect
boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, line);
CPPUNIT_ASSERT_MESSAGE("Intersection point expected", bool(intersection_point_opt));
Vertex intersection_point = *intersection_point_opt;
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Intersection point error", 0.5, intersection_point.x(), 1E-10);
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Intersection point error", 1.0, intersection_point.y(), 1E-10);
}
{
LineSegment ls(Vertex(0, 3), Vertex(1, 3));
Line line(Vertex(0, 0), Vertex(0.25, 1));
// segment/line intersect
boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, line);
CPPUNIT_ASSERT_MESSAGE("Intersection point expected", bool(intersection_point_opt));
Vertex intersection_point = *intersection_point_opt;
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Intersection point error", 0.75, intersection_point.x(), 1E-10);
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Intersection point error", 3.0, intersection_point.y(), 1E-10);
}
{
LineSegment ls(Vertex(0, 1), Vertex(1, 1));
Line line(Vertex(0.25, 2), Vertex(1, 4));
// segment/line do not intersect
boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, line);
CPPUNIT_ASSERT_MESSAGE("No intersection point expected", !bool(intersection_point_opt));
}
{
LineSegment ls(Vertex(0, 1), Vertex(1, 1));
Line line(Vertex(0, 0), Vertex(2, 1));
// segments do not intersect
boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, line);
CPPUNIT_ASSERT_MESSAGE("No intersection point expected", !bool(intersection_point_opt));
}
{
LineSegment ls(Vertex(0, 1), Vertex(1, 1));
Line line(Vertex(0.5, 1), Vertex(2, 1));
// segment/line overlap
boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, line);
CPPUNIT_ASSERT_MESSAGE("No intersection point expected", !bool(intersection_point_opt));
}
{
LineSegment ls(Vertex(0.5, 1), Vertex(1, 1));
Line line(Vertex(0, 1), Vertex(2, 1));
// segment contained in line
boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, line);
CPPUNIT_ASSERT_MESSAGE("No intersection point expected", !bool(intersection_point_opt));
}
{
LineSegment ls(Vertex(0, 1), Vertex(1, 1));
Line line(Vertex(1.5, 1), Vertex(2, 1));
// segment and line parallel
boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, line);
CPPUNIT_ASSERT_MESSAGE("No intersection point expected", !bool(intersection_point_opt));
}
{
LineSegment ls(Vertex(0, 1), Vertex(1, 1));
Line line(Vertex(1.5, 2), Vertex(2, 2));
// segment and line parallel, but not collinear
boost::optional<Vertex> intersection_point_opt = GeometricHelper::intersect(ls, line);
CPPUNIT_ASSERT_MESSAGE("No intersection point expected", !bool(intersection_point_opt));
}
}
示例6: ComputeLineDistanceFilter
NV_INT32 ComputeLineDistanceFilter (NV_F64_COORD2 lineStart, NV_F64_COORD2 lineEnd, MISC *misc, OPTIONS *options)
{
NV_INT32 numPointsWithin = 0;
NV_FLOAT64 utmE, utmN;
NV_BOOL hitMax = NVFalse;
QColor color;
QColor GetAVShotColor (NV_INT32 index, MISC *misc, OPTIONS *options);
for (NV_INT32 i = 0; i < misc->abe_share->point_cloud_count; i++)
{
// only check non-deleted shots
if ((!check_bounds (options, misc, i, NVTrue, NVFalse)) && misc->data[i].type == PFM_CZMIL_DATA)
{
NV_FLOAT64 x = misc->data[i].x * NV_DEG_TO_RAD;
NV_FLOAT64 y = misc->data[i].y * NV_DEG_TO_RAD;
pj_transform (misc->pj_latlon, misc->pj_utm, 1, 1, &x, &y, NULL);
utmE = x;
utmN = y;
Vertex ptOfInterest (utmE, utmN, 0.0f);
Vertex closestPt = Vector::ClosestPtOnLine (Vertex (lineStart.x, lineStart.y, 0.0f), Vertex (lineEnd.x, lineEnd.y, 0.0f), ptOfInterest);
if (Vector::GetDistance (ptOfInterest, closestPt) < options->distThresh)
{
// load up the shots array for AV
misc->avb.shotArray[numPointsWithin].recordNumber = misc->data[i].rec;
misc->avb.shotArray[numPointsWithin].subRecordNumber = misc->data[i].sub;
misc->avb.shotArray[numPointsWithin].pfmHandle = misc->pfm_handle[misc->data[i].pfm];
misc->avb.shotArray[numPointsWithin].fileNo = misc->data[i].file;
misc->avb.shotArray[numPointsWithin].masterIdx = i;
misc->avb.shotArray[numPointsWithin].type = misc->data[i].type;
color = GetAVShotColor (i, misc, options);
misc->avb.shotArray[numPointsWithin].colorH = color.hue ();
misc->avb.shotArray[numPointsWithin].colorS = color.saturation();
misc->avb.shotArray[numPointsWithin].colorV = color.value();
numPointsWithin++;
if (numPointsWithin == MAX_ATTRIBUTE_SHOTS)
{
hitMax = NVTrue;
// If we hit the maximum, send a message out for the user to re-select.
QString msg = QString (pfmEdit3D::tr ("The line specified results in more shots satisfying the threshold than can be held (MAX = %1).\n").arg
(MAX_ATTRIBUTE_SHOTS) +
pfmEdit3D::tr ("Please draw a shorter line or change the distance threshold parameter"));
QMessageBox::warning (0, pfmEdit3D::tr ("pfmEdit3D"), msg);
return 0;
break;
}
}
}
}
// lock shared memory and load up shots and notify AV new data is coming
misc->abeShare->lock();
if (numPointsWithin > 0)
{
misc->av_dist_count = numPointsWithin;
misc->av_dist_list = (NV_INT32 *) realloc (misc->av_dist_list, (misc->av_dist_count + 1) * sizeof (NV_INT32));
if (misc->av_dist_list == NULL)
{
perror ("Allocating misc->av_dist_list memory in pfmEdit3D");
exit (-1);
}
for (NV_INT32 i = 0; i < numPointsWithin; i++)
{
misc->abe_share->avShare.shots[i] = misc->avb.shotArray[i];
misc->av_dist_list[i] = misc->avb.shotArray[i].masterIdx;
}
}
misc->abe_share->avShare.numShots = numPointsWithin;
misc->abe_share->avShare.avNewData = NVTrue;
misc->abe_share->avShare.hitMax = hitMax;
misc->abeShare->unlock();
return (numPointsWithin);
}
示例7: Vertex
void CSimpleUGraph< ObjT, Compare >::AddVertex( const ObjT &oNewVertex )
{
Vertex u;
typename DataVertexMapT::iterator vMapPos;
bool bInserted;
if( oDataToVertexMap.find( oNewVertex ) != oDataToVertexMap.end() )
return;
// note that Vertex() is just a place holder
boost::tie( vMapPos, bInserted ) = oDataToVertexMap.insert( std::make_pair( oNewVertex, Vertex() ) );
if ( bInserted ) // If data is not already added in the map
{
u = add_vertex( oBoostGraph ); // add new vertex to graph
oVertexToDataMap[ u ] = oNewVertex; // name the vertex with the current data
vMapPos->second = u; // assign the correct vertex to the map
}
// If data (NewVertex) already exist in the map, do nothing
}
示例8: while
void AnimatedMesh::LoadFromFile(string file)
{
// if substr of the last 4 = .obj do this: - else load other format / print error
ObjLoader oj;
// Get the directory correct
string tempFilename = file;
string pathfolder = "";
size_t slashpos = tempFilename.find("/");
while(slashpos != string::npos)
{
slashpos = tempFilename.find("/");
pathfolder += tempFilename.substr(0, slashpos+1);
tempFilename = tempFilename.substr(slashpos + 1);
}
ifstream anifile;
anifile.open(file);
if(anifile)
{
string line = "";
getline(anifile, line);
int nrOfKeyframes = atoi(line.c_str());
for(int a = 0; a < nrOfKeyframes; a++)
{
int time = 0;
string path = "";
getline(anifile, line);
time = atoi(line.c_str());
getline(anifile, path);
KeyFrame* frame = new KeyFrame();
frame->time = time;
{
ObjData* od = oj.LoadObjFile(pathfolder + path);
MaloW::Array<MaterialData>* mats = od->mats;
for(int q = 0; q < mats->size(); q++)
{
bool hasFace = false;
MeshStrip* strip = new MeshStrip();
int nrOfVerts = 0;
Vertex* tempverts = new Vertex[od->faces->size()*3];
for(int i = 0; i < od->faces->size(); i++)
{
if(od->faces->get(i).material == mats->get(q).name)
{
int vertpos = od->faces->get(i).data[0][0] - 1;
int textcoord = od->faces->get(i).data[0][1] - 1;
int norm = od->faces->get(i).data[0][2] - 1;
tempverts[nrOfVerts] = Vertex(od->vertspos->get(vertpos), od->textcoords->get(textcoord), od->vertsnorms->get(norm));
nrOfVerts++;
vertpos = od->faces->get(i).data[2][0] - 1;
textcoord = od->faces->get(i).data[2][1] - 1;
norm = od->faces->get(i).data[2][2] - 1;
tempverts[nrOfVerts] = Vertex(od->vertspos->get(vertpos), od->textcoords->get(textcoord), od->vertsnorms->get(norm));
nrOfVerts++;
vertpos = od->faces->get(i).data[1][0] - 1;
textcoord = od->faces->get(i).data[1][1] - 1;
norm = od->faces->get(i).data[1][2] - 1;
tempverts[nrOfVerts] = Vertex(od->vertspos->get(vertpos), od->textcoords->get(textcoord), od->vertsnorms->get(norm));
nrOfVerts++;
hasFace = true;
}
}
strip->setNrOfVerts(nrOfVerts);
Vertex* verts = new Vertex[nrOfVerts];
for(int z = 0; z < nrOfVerts; z++)
{
verts[z] = tempverts[z];
}
delete tempverts;
strip->SetVerts(verts);
strip->SetTexturePath(od->mats->get(q).texture);
Material* mat = new Material();
mat->AmbientColor = od->mats->get(q).ka;
if(mat->AmbientColor == D3DXVECTOR3(0.0f, 0.0f, 0.0f)) //////////// MaloW Fix, otherwise completely black with most objs
mat->AmbientColor += D3DXVECTOR3(0.2f, 0.2f, 0.2f); //////////// MaloW Fix, otherwise completely black with most objs
mat->DiffuseColor = od->mats->get(q).kd;
if(mat->DiffuseColor == D3DXVECTOR3(0.0f, 0.0f, 0.0f)) //////////// MaloW Fix, otherwise completely black with most objs
mat->DiffuseColor += D3DXVECTOR3(0.6f, 0.6f, 0.6f); //////////// MaloW Fix, otherwise completely black with most objs
mat->SpecularColor = od->mats->get(q).ks;
strip->SetMaterial(mat);
if(hasFace)
frame->strips->add(strip);
//.........这里部分代码省略.........
示例9: assert
void Text::UpdateGeometry()
{
assert(myFont != NULL);
// Clear the previous geometry
myVertices.Clear();
// No text: nothing to draw
if (myString.IsEmpty())
return;
// Compute values related to the text style
bool bold = (myStyle & Bold) != 0;
bool underlined = (myStyle & Underlined) != 0;
float italic = (myStyle & Italic) ? 0.208f : 0.f; // 12 degrees
float underlineOffset = myCharacterSize * 0.1f;
float underlineThickness = myCharacterSize * (bold ? 0.1f : 0.07f);
// Precompute the variables needed by the algorithm
float hspace = static_cast<float>(myFont->GetGlyph(L' ', myCharacterSize, bold).Advance);
float vspace = static_cast<float>(myFont->GetLineSpacing(myCharacterSize));
float x = 0.f;
float y = static_cast<float>(myCharacterSize);
// Create one quad for each character
Uint32 prevChar = 0;
for (std::size_t i = 0; i < myString.GetSize(); ++i)
{
Uint32 curChar = myString[i];
// Apply the kerning offset
x += static_cast<float>(myFont->GetKerning(prevChar, curChar, myCharacterSize));
prevChar = curChar;
// If we're using the underlined style and there's a new line, draw a line
if (underlined && (curChar == L'\n'))
{
float top = y + underlineOffset;
float bottom = top + underlineThickness;
myVertices.Append(Vertex(Vector2f(0, top), myColor, Vector2f(1, 1)));
myVertices.Append(Vertex(Vector2f(x, top), myColor, Vector2f(2, 1)));
myVertices.Append(Vertex(Vector2f(x, bottom), myColor, Vector2f(2, 2)));
myVertices.Append(Vertex(Vector2f(0, bottom), myColor, Vector2f(1, 2)));
}
// Handle special characters
switch (curChar)
{
case L' ' : x += hspace; continue;
case L'\t' : x += hspace * 4; continue;
case L'\n' : y += vspace; x = 0; continue;
case L'\v' : y += vspace * 4; continue;
}
// Extract the current glyph's description
const Glyph& glyph = myFont->GetGlyph(curChar, myCharacterSize, bold);
int left = glyph.Bounds.Left;
int top = glyph.Bounds.Top;
int right = glyph.Bounds.Left + glyph.Bounds.Width;
int bottom = glyph.Bounds.Top + glyph.Bounds.Height;
float u1 = static_cast<float>(glyph.TextureRect.Left);
float v1 = static_cast<float>(glyph.TextureRect.Top);
float u2 = static_cast<float>(glyph.TextureRect.Left + glyph.TextureRect.Width);
float v2 = static_cast<float>(glyph.TextureRect.Top + glyph.TextureRect.Height);
// Add a quad for the current character
myVertices.Append(Vertex(Vector2f(x + left - italic * top, y + top), myColor, Vector2f(u1, v1)));
myVertices.Append(Vertex(Vector2f(x + right - italic * top, y + top), myColor, Vector2f(u2, v1)));
myVertices.Append(Vertex(Vector2f(x + right - italic * bottom, y + bottom), myColor, Vector2f(u2, v2)));
myVertices.Append(Vertex(Vector2f(x + left - italic * bottom, y + bottom), myColor, Vector2f(u1, v2)));
// Advance to the next character
x += glyph.Advance;
}
// If we're using the underlined style, add the last line
if (underlined)
{
float top = y + underlineOffset;
float bottom = top + underlineThickness;
myVertices.Append(Vertex(Vector2f(0, top), myColor, Vector2f(1, 1)));
myVertices.Append(Vertex(Vector2f(x, top), myColor, Vector2f(2, 1)));
myVertices.Append(Vertex(Vector2f(x, bottom), myColor, Vector2f(2, 2)));
myVertices.Append(Vertex(Vector2f(0, bottom), myColor, Vector2f(1, 2)));
}
// Recompute the bounding rectangle
myBounds = myVertices.GetBounds();
}
示例10: CreateRect
static Polygon CreateRect (float x, float y, float width, float height) { return CreateRect(Vertex(x, y), width, height); }
示例11: v
void GraphicsSystem::Vertex(float x, float y, float z)
{
Vect v(x, y, z);
Vertex(v);
}
示例12: Vertex
void Cuboid::CreateVertexBuffer(const float width, const float height, const float depth)
{
Vertex cubeVerts[] =
{
//Front
Vertex(glm::vec3(width, height, -depth), glm::vec2(0.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f)),
Vertex(glm::vec3(-width, height, -depth), glm::vec2(1.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f)),
Vertex(glm::vec3(-width, -height, -depth), glm::vec2(1.0f, 1.0f), glm::vec3(0.0f, 0.0f, -1.0f)),
Vertex(glm::vec3(width, -height, -depth), glm::vec2(0.0f, 1.0f), glm::vec3(0.0f, 0.0f, -1.0f)),
//Back
Vertex(glm::vec3(width, height, depth), glm::vec2(0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f)),
Vertex(glm::vec3(-width, height, depth), glm::vec2(1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f)),
Vertex(glm::vec3(-width, -height, depth), glm::vec2(1.0f, 1.0f), glm::vec3(0.0f, 0.0f, 1.0f)),
Vertex(glm::vec3(width, -height, depth), glm::vec2(0.0f, 1.0f), glm::vec3(0.0f, 0.0f, 1.0f)),
//Right
Vertex(glm::vec3(-width, height, -depth), glm::vec2(0.0f, 0.0f), glm::vec3(-1.0f, 0.0f, 0.0f)),
Vertex(glm::vec3(-width, height, depth), glm::vec2(1.0f, 0.0f), glm::vec3(-1.0f, 0.0f, 0.0f)),
Vertex(glm::vec3(-width, -height, depth), glm::vec2(1.0f, 1.0f), glm::vec3(-1.0f, 0.0f, 0.0f)),
Vertex(glm::vec3(-width, -height, -depth), glm::vec2(0.0f, 1.0f), glm::vec3(-1.0f, 0.0f, 0.0f)),
//Left
Vertex(glm::vec3(width, height, -depth), glm::vec2(0.0f, 0.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
Vertex(glm::vec3(width, height, depth), glm::vec2(1.0f, 0.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
Vertex(glm::vec3(width, -height, depth), glm::vec2(1.0f, 1.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
Vertex(glm::vec3(width, -height, -depth), glm::vec2(0.0f, 1.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
//Top
Vertex(glm::vec3(-width, height, depth), glm::vec2(0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)),
Vertex(glm::vec3(width, height, depth), glm::vec2(1.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)),
Vertex(glm::vec3(width, height, -depth), glm::vec2(1.0f, 1.0f), glm::vec3(0.0f, 1.0f, 0.0f)),
Vertex(glm::vec3(-width, height, -depth), glm::vec2(0.0f, 1.0f), glm::vec3(0.0f, 1.0f, 0.0f)),
//Bottom
Vertex(glm::vec3(-width, -height, depth), glm::vec2(0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
Vertex(glm::vec3(width, -height, depth), glm::vec2(1.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
Vertex(glm::vec3(width, -height, -depth), glm::vec2(1.0f, 1.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
Vertex(glm::vec3(-width, -height, -depth), glm::vec2(0.0f, 1.0f), glm::vec3(0.0f, -1.0f, 0.0f))
};
glm::vec3 cVerts[] =
{
//Front
glm::vec3(width, height, -depth),
glm::vec3(-width, height, -depth),
glm::vec3(-width, -height, -depth),
glm::vec3(width, -height, -depth),
//Back
glm::vec3(width, height, depth),
glm::vec3(-width, height, depth),
glm::vec3(-width, -height, depth),
glm::vec3(width, -height, depth),
};
renderVertsCount = 24;
colliderVertsCount = 8;
faceIndicesCount = 30;
verts.reserve(renderVertsCount);
for(int i = 0; i < renderVertsCount; i++)
verts.push_back(cubeVerts[i]);
collisionVerts.reserve(colliderVertsCount);
for(int i = 0; i < colliderVertsCount; i++)
collisionVerts.push_back(cVerts[i]);
const int arr[] =
{
4, 0,3,2,1, //Front
4, 4,5,6,7, //Back
4, 1,2,6,5, //Right
4, 0,4,7,3, //Left
4, 5,4,0,1, //Top
4, 6,2,3,7 //Bottom
};
faceIndices.reserve(faceIndicesCount);
for(int i = 0; i < faceIndicesCount; i++)
faceIndices.push_back(arr[i]);
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(cubeVerts), cubeVerts, GL_STATIC_DRAW);
}
示例13: Point
//.........这里部分代码省略.........
tempHolder2.push_back(points[i].neighbour[h]);
}
}
int xSign = 1; int zSign = 1;
if (points[i].x < 0) xSign = -1;
if (points[i].z < 0) zSign = -1;
if (points[i].z * zSign < points[i].x * xSign) {
if (tempHolder2[0]->z * xSign < tempHolder2[1]->z * xSign) tempHolder.push_back(tempHolder2[1]);
else tempHolder.push_back(tempHolder2[0]);
}
else {
if (tempHolder2[0]->x * zSign > tempHolder2[1]->x * zSign) tempHolder.push_back(tempHolder2[1]);
else tempHolder.push_back(tempHolder2[0]);
}
//now find the rest of them
for (unsigned j = 2; j < points[i].neighbours; j++) {
for (unsigned h = 1; h < points[i].neighbours; h++) {
if(std::find(tempHolder.begin(), tempHolder.end(), points[i].neighbour[h]) == tempHolder.end()
&& std::find(points[i].neighbour[h]->neighbour.begin(), points[i].neighbour[h]->neighbour.end(), tempHolder[j - 1]) != points[i].neighbour[h]->neighbour.end()) {
tempHolder.push_back(points[i].neighbour[h]);
h = points[i].neighbours; //break this loop
}
}
}
points[i].neighbour = tempHolder;
faces.push_back(Face(points[i].neighbours, points[i].ID)); //then create the hexagon or pentagon
Vector3f temp3f;
faces[i].corners.push_back((points[i] + *points[i].neighbour[0] + *points[i].neighbour[points[i].neighbours - 1]) / 3);
temp3f += (points[i] + *points[i].neighbour[0] + *points[i].neighbour[points[i].neighbours - 1]) / 3;
for (unsigned j = 1; j < points[i].neighbours; j++) {
faces[i].corners.push_back((points[i] + *points[i].neighbour[j] + *points[i].neighbour[j - 1]) / 3);
temp3f += (points[i] + *points[i].neighbour[j] + *points[i].neighbour[j - 1]) / 3;
}
faces[i].center = temp3f / faces[i].n;
}
std::sort(faces.begin(), faces.end(), [](Face a, Face b) { return a.ID > b.ID; }); //now sort the faces by ID for testing purposes. This will ruin pointers but its okay for now as they are not currently needed
//Now lets make the masks. First increase the dimensions so that they just barely overtake the faces
masks = faces;
for (unsigned int i = 0; i < vSize; i++) {
masks[i].center *= 1.0001;
for (unsigned int j = 0; j < faces[i].n; j++) {
masks[i].corners[j] *= 1.0001;
}
}
std::vector<Vertex> _VBO;
radius = 2 / (faces[1].center - faces[0].center).length();
for (unsigned i = 0; i < faces.size(); i++) {
if (faces[i].ID != -1) {
int j;
for (j = faces[i].ID; j > 100; j -= 100) {}
if (faces[i].n == 6) {
_VBO.push_back(Vertex(faces[i].corners[5] * radius, Vector2f(0.0f, 0.075f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[4] * radius, Vector2f(0.05f, 0.1f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[3] * radius, Vector2f(0.1f, 0.075f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[5] * radius, Vector2f(0.0f, 0.075f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[3] * radius, Vector2f(0.1f, 0.075f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[2] * radius, Vector2f(0.1f, 0.025f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[0] * radius, Vector2f(0.0f, 0.025f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[5] * radius, Vector2f(0.0f, 0.075f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[2] * radius, Vector2f(0.1f, 0.025f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[1] * radius, Vector2f(0.05f, 0.0f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[0] * radius, Vector2f(0.0f, 0.025f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[2] * radius, Vector2f(0.1f, 0.025f) + textureGrid[j], faces[i].center));
}
if (faces[i].n == 5) {
_VBO.push_back(Vertex(faces[i].corners[4] * radius, Vector2f(0.0f, 0.062f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[3] * radius, Vector2f(0.05f, 0.1f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[2] * radius, Vector2f(0.1f, 0.062f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[0] * radius, Vector2f(0.02f, 0.0f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[4] * radius, Vector2f(0.0f, 0.062f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[2] * radius, Vector2f(0.1f, 0.062f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[1] * radius, Vector2f(0.08f, 0.0f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[0] * radius, Vector2f(0.02f, 0.0f) + textureGrid[j], faces[i].center));
_VBO.push_back(Vertex(faces[i].corners[2] * radius, Vector2f(0.1f, 0.062f) + textureGrid[j], faces[i].center));
}
}
}
glGenBuffers(1, &VBO);
numV = _VBO.size();
roundNormals(&_VBO[0], numV);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, numV * sizeof(Vertex), &_VBO[0], GL_STATIC_DRAW);
//end of test code
//debug ===============================================================================================================
newTime = SDL_GetTicks();
std::cout << (newTime - currentTime) << '\n';
currentTime = SDL_GetTicks();
}
示例14: FloatRect
void Text::ensureGeometryUpdate() const
{
// Do nothing, if geometry has not changed
if (!m_geometryNeedUpdate)
return;
// Mark geometry as updated
m_geometryNeedUpdate = false;
// Clear the previous geometry
m_vertices.clear();
m_bounds = FloatRect();
// No font: nothing to draw
if (!m_font)
return;
// No text: nothing to draw
if (m_string.isEmpty())
return;
// Compute values related to the text style
bool bold = (m_style & Bold) != 0;
bool underlined = (m_style & Underlined) != 0;
float italic = (m_style & Italic) ? 0.208f : 0.f; // 12 degrees
float underlineOffset = m_characterSize * 0.1f;
float underlineThickness = m_characterSize * (bold ? 0.1f : 0.07f);
// Precompute the variables needed by the algorithm
float hspace = static_cast<float>(m_font->getGlyph(L' ', m_characterSize, bold).advance);
float vspace = static_cast<float>(m_font->getLineSpacing(m_characterSize));
float x = 0.f;
float y = static_cast<float>(m_characterSize);
// Create one quad for each character
float minX = static_cast<float>(m_characterSize);
float minY = static_cast<float>(m_characterSize);
float maxX = 0.f;
float maxY = 0.f;
Uint32 prevChar = 0;
for (std::size_t i = 0; i < m_string.getSize(); ++i)
{
Uint32 curChar = m_string[i];
// Apply the kerning offset
x += static_cast<float>(m_font->getKerning(prevChar, curChar, m_characterSize));
prevChar = curChar;
// If we're using the underlined style and there's a new line, draw a line
if (underlined && (curChar == L'\n'))
{
float top = y + underlineOffset;
float bottom = top + underlineThickness;
m_vertices.append(Vertex(Vector2f(0, top), m_color, Vector2f(1, 1)));
m_vertices.append(Vertex(Vector2f(x, top), m_color, Vector2f(1, 1)));
m_vertices.append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
m_vertices.append(Vertex(Vector2f(0, bottom), m_color, Vector2f(1, 1)));
m_vertices.append(Vertex(Vector2f(x, top), m_color, Vector2f(1, 1)));
m_vertices.append(Vertex(Vector2f(x, bottom), m_color, Vector2f(1, 1)));
}
// Handle special characters
if ((curChar == ' ') || (curChar == '\t') || (curChar == '\n'))
{
// Update the current bounds (min coordinates)
minX = std::min(minX, x);
minY = std::min(minY, y);
switch (curChar)
{
case ' ' : x += hspace; break;
case '\t' : x += hspace * 4; break;
case '\n' : y += vspace; x = 0; break;
}
// Update the current bounds (max coordinates)
maxX = std::max(maxX, x);
maxY = std::max(maxY, y);
// Next glyph, no need to create a quad for whitespace
continue;
}
// Extract the current glyph's description
const Glyph& glyph = m_font->getGlyph(curChar, m_characterSize, bold);
int left = glyph.bounds.left;
int top = glyph.bounds.top;
int right = glyph.bounds.left + glyph.bounds.width;
int bottom = glyph.bounds.top + glyph.bounds.height;
float u1 = static_cast<float>(glyph.textureRect.left);
float v1 = static_cast<float>(glyph.textureRect.top);
float u2 = static_cast<float>(glyph.textureRect.left + glyph.textureRect.width);
float v2 = static_cast<float>(glyph.textureRect.top + glyph.textureRect.height);
// Add a quad for the current character
m_vertices.append(Vertex(Vector2f(x + left - italic * top, y + top), m_color, Vector2f(u1, v1)));
m_vertices.append(Vertex(Vector2f(x + right - italic * top, y + top), m_color, Vector2f(u2, v1)));
//.........这里部分代码省略.........
示例15: D3DXVec3Normalize
void Sphere::buildStacks(VertexList& vertices, IndexList& indices)
{
float phiStep = PI/mNumStacks;
// do not count the poles as rings
UINT numRings = mNumStacks-1;
// Compute vertices for each stack ring.
for(UINT i = 1; i <= numRings; ++i)
{
float phi = i*phiStep;
// vertices of ring
float thetaStep = 2.0f*PI/mNumSlices;
for(UINT j = 0; j <= mNumSlices; ++j)
{
float theta = j*thetaStep;
Vertex v;
// spherical to cartesian
v.pos.x = mRadius*sinf(phi)*cosf(theta);
v.pos.y = mRadius*cosf(phi);
v.pos.z = mRadius*sinf(phi)*sinf(theta);
// partial derivative of P with respect to theta
v.tangent.x = -mRadius*sinf(phi)*sinf(theta);
v.tangent.y = 0.0f;
v.tangent.z = mRadius*sinf(phi)*cosf(theta);
D3DXVec3Normalize(&v.normal, &v.pos);
v.texC.x = theta / (2.0f*PI);
v.texC.y = phi / PI;
vertices.push_back( v );
}
}
// poles: note that there will be texture coordinate distortion
vertices.push_back( Vertex(0.0f, -mRadius, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f) );
vertices.push_back( Vertex(0.0f, mRadius, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f) );
UINT northPoleIndex = (UINT)vertices.size()-1;
UINT southPoleIndex = (UINT)vertices.size()-2;
UINT numRingVertices = mNumSlices+1;
// Compute indices for inner stacks (not connected to poles).
for(UINT i = 0; i < mNumStacks-2; ++i)
{
for(UINT j = 0; j < mNumSlices; ++j)
{
indices.push_back(i*numRingVertices + j);
indices.push_back(i*numRingVertices + j+1);
indices.push_back((i+1)*numRingVertices + j);
indices.push_back((i+1)*numRingVertices + j);
indices.push_back(i*numRingVertices + j+1);
indices.push_back((i+1)*numRingVertices + j+1);
}
}
// Compute indices for top stack. The top stack was written
// first to the vertex buffer.
for(UINT i = 0; i < mNumSlices; ++i)
{
indices.push_back(northPoleIndex);
indices.push_back(i+1);
indices.push_back(i);
}
// Compute indices for bottom stack. The bottom stack was written
// last to the vertex buffer, so we need to offset to the index
// of first vertex in the last ring.
UINT baseIndex = (numRings-1)*numRingVertices;
for(UINT i = 0; i < mNumSlices; ++i)
{
indices.push_back(southPoleIndex);
indices.push_back(baseIndex+i);
indices.push_back(baseIndex+i+1);
}
}