本文整理汇总了C++中vec4::xyz方法的典型用法代码示例。如果您正苦于以下问题:C++ vec4::xyz方法的具体用法?C++ vec4::xyz怎么用?C++ vec4::xyz使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec4
的用法示例。
在下文中一共展示了vec4::xyz方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pickAgainstPlane
vec3 Camera::pickAgainstPlane(float x, float y, vec4 plane)
{
float nxPos = x / 1280.0f; //replace these with your screen width and height
float nyPos = y / 720.0f;
float sxPos = nxPos - 0.5f;
float syPos = nyPos - 0.5f;
float fxPos = sxPos * 2;
float fyPos = syPos * -2;
mat4 inv_viewproj = glm::inverse(view_proj); //view_proj is the memeber variable
vec4 mouse_pos(fxPos, fyPos, 1, 1);
vec4 world_pos = inv_viewproj * mouse_pos;
world_pos /= world_pos.w;
vec3 cam_pos = world[3].xyz(); //world is the member variable
vec3 dir = world_pos.xyz() - cam_pos;
float t = -(glm::dot(cam_pos, plane.xyz()) + plane.w)
/ (glm::dot(dir, plane.xyz()));
vec3 result = cam_pos + dir * t;
return result;
}
示例2: addPoint
void Bounds::addPoint(const vec4& v) {
addPoint(v.xyz());
}
示例3: clip
MeshGeometry MeshGeometry::clip(const vec4& clipplane, double epsilon) {
// Clip all faces...
for (iterator it = begin(); it != end(); ++it)
it->clip(clipplane, epsilon);
// Remove empty faces...
for (size_t i = 0; i < faces_.size(); ++i) {
// Is face empty?
if (faces_.at(i).getVertexCount() < 3)
faces_.erase(faces_.begin() + i--);
}
// Close convex polyhedron if necessary...
typedef std::pair<VertexGeometry, VertexGeometry> EdgeType;
typedef std::vector<EdgeType> EdgeListType;
typedef std::vector<VertexGeometry> VertexListType;
EdgeListType edgeList;
FaceGeometry closingFace;
// Search all face edges on the clipping plane...
for (size_t i = 0; i < faces_.size(); ++i) {
FaceGeometry face = faces_.at(i);
VertexListType verticesOnClipplane;
for (size_t j = 0; j < face.getVertexCount(); ++j) {
if (face.getVertex(j).getDistanceToPlane(clipplane, epsilon) == 0)
verticesOnClipplane.push_back(face.getVertex(j));
// Is face in the same plane as the clipping plane?
if (verticesOnClipplane.size() > 2)
break;
}
// Does one face edge corresponds with clipping plane?
if (verticesOnClipplane.size() == 2)
edgeList.push_back(std::make_pair(verticesOnClipplane[0], verticesOnClipplane[1]));
}
// Is closing necessary?
if (edgeList.size() > 1) {
// Sort edges to produce contiguous vertex order...
bool reverseLastEdge = false;
for (size_t i = 0; i < edgeList.size() - 1; ++i) {
for (size_t j = i + 1; j < edgeList.size(); ++j) {
VertexGeometry connectionVertex;
if (reverseLastEdge)
connectionVertex = edgeList.at(i).first;
else
connectionVertex = edgeList.at(i).second;
if (edgeList.at(j).first.equals(connectionVertex, epsilon)) {
std::swap(edgeList.at(i + 1), edgeList.at(j));
reverseLastEdge = false;
break;
}
else if (edgeList.at(j).second.equals(connectionVertex, epsilon)) {
std::swap(edgeList.at(i + 1), edgeList.at(j));
reverseLastEdge = true;
break;
}
}
}
// Convert sorted edge list to sorted vertex list...
VertexListType closingFaceVertices;
for (size_t i = 0; i < edgeList.size(); ++i) {
bool reverseEdge = i != 0 && !closingFaceVertices.at(closingFaceVertices.size() - 1).equals(edgeList.at(i).first);
VertexGeometry first = (reverseEdge ? edgeList.at(i).second : edgeList.at(i).first);
VertexGeometry second = (reverseEdge ? edgeList.at(i).first : edgeList.at(i).second);
if (i == 0)
closingFaceVertices.push_back(first);
else
closingFaceVertices.at(closingFaceVertices.size() - 1).combine(first);
if (i < (edgeList.size() - 1))
closingFaceVertices.push_back(second);
else
closingFaceVertices[0].combine(second);
}
// Convert vertex order to counter clockwise if necessary...
vec3 closingFaceNormal(0, 0, 0);
for (size_t i = 0; i < closingFaceVertices.size(); ++i)
closingFaceNormal += tgt::cross(closingFaceVertices[i].getCoords(), closingFaceVertices[(i + 1) % closingFaceVertices.size()].getCoords());
closingFaceNormal = tgt::normalize(closingFaceNormal);
if (tgt::dot(clipplane.xyz(), closingFaceNormal) < 0)
std::reverse(closingFaceVertices.begin(), closingFaceVertices.end());
// Close convex polyhedron...
for (VertexListType::iterator it = closingFaceVertices.begin(); it != closingFaceVertices.end(); ++it) {
// TODO(b_bolt01): Remove debug message...
//std::cout << " cfv " << it->getCoords() << std::endl;
closingFace.addVertex(*it);
}
addFace(closingFace);
//.........这里部分代码省略.........