本文整理汇总了C++中glm::vec2方法的典型用法代码示例。如果您正苦于以下问题:C++ glm::vec2方法的具体用法?C++ glm::vec2怎么用?C++ glm::vec2使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类glm
的用法示例。
在下文中一共展示了glm::vec2方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateMotionResult
void MotionArea::updateMotionResult() {
vec2 hitpointVec = glm::normalize(vec2((posx1 - posx), (posy1 - posy)));
angle = glm::orientedAngle(hitpointVec, vec2(-1.0, 0.0));
factor = sqrt(pow((posx1 - posx), 2.0f) + pow((posy1 - posy), 2.0f)) / radius;
// cout << "angle=" << angle << " degrees=" <<
// ES_TO_DEGREES(angle) << " factor=" << factor << endl;
}
示例2: Interpolate
void Interpolate( PIXEL a, PIXEL b, vector<PIXEL>& result)
{
int N = result.size();
vec2 step1 = vec2(b.position2D-a.position2D) / float(max(N-1,1));
vec2 current1= vec2(a.position2D);
float step2 = (b.zinv-a.zinv)/float(max(N-1,1));
float current2 = a.zinv;
// vec3 step3 = (b.illumination - a.illumination)/ float(max(N-1,1));
// vec3 current3 = a.illumination;
vec3 step4 =(b.position3D - a.position3D)/ float(max(N-1,1));
vec3 current4= a.position3D;
for( int i=0; i<N; ++i )
{
result[i].position2D =ivec2(current1);
result[i].zinv = current2;
// result[i].illumination = current3;
result[i].position3D = current4;
current1 = step1+current1;
current2 = step2+current2;
// current3 = step3+current3;
current4 = step4+current4;
}
}
示例3: vec2
void Graph::CreateGrid(unsigned int cols, unsigned int rows, float screenWidth, float screenHeight)
{
GraphVertex* vertices = new GraphVertex[cols * rows];
GraphNode** gridNodes = new GraphNode*[cols * rows];
float nodeX = screenWidth / (float)cols;
float nodeY = screenHeight / (float)rows;
for (unsigned int c = 0; c < cols; ++c)
{
for (unsigned int r = 0; r < rows; ++r)
{
vertices[c * rows + r].position = vec2((float)c, (float)r);
}
}
glm::vec2 currentPos;
for (unsigned int c = 0; c < cols; c++)
{
for (unsigned int r = 0; r < rows; r++)
{
gridNodes[c * rows + r] = new GraphNode();
currentPos.x = (c * nodeX) + (nodeX / 2);
currentPos.y = (r * nodeY) + (nodeY / 2);
gridNodes[c * rows + r]->SetPos(currentPos);
gridNodes[c * rows + r]->SetLoc(vec2(c, r));
}
}
for (unsigned int c = 0; c < cols; c++)
{
for (unsigned int r = 0; r < rows; r++)
{
if (c != 0)
{
gridNodes[c * rows + r]->NewEdge(gridNodes[c * rows + r], gridNodes[(c - 1) * rows + r], 1);
}
if (c != cols - 1)
{
gridNodes[c * rows + r]->NewEdge(gridNodes[c * rows + r], gridNodes[(c + 1) * rows + r], 1);
}
if (r != 0)
{
gridNodes[c * rows + r]->NewEdge(gridNodes[c * rows + r], gridNodes[c * rows + r - 1], 1);
}
if (r != rows - 1)
{
gridNodes[c * rows + r]->NewEdge(gridNodes[c * rows + r], gridNodes[c * rows + r + 1], 1);
}
AddNode(gridNodes[c * rows + r]);
}
}
m_grid = gridNodes;
m_gridCols = cols;
m_gridRows = rows;
}
示例4: iPlane
vec2 RayTracer::iPlane(const vec3& ro, const vec3& rd, const int idx)
{
const vec4 &pln = this->objstack[idx].vec;
//t = -(ax + by + cz + d)/ (ai + bj + ck)
vec3 nor = vec3(pln.xyz);
float denom = glm::dot(rd, nor);
if(denom > 0) return vec2(FLT_MAX, idx);
float t = -1.0 *(glm::dot(ro, nor) + pln.w)/denom;
return vec2(t, idx);
}
示例5: updateBullets
void updateBullets()
{
// namespace resolution
using namespace glm;
for (int b = 0; b < MAX_BULLET; ++b)
{
// Don't update bullets that don't exist:
if (0.0f == bullets[b].rad || true == bullets[b].onPlanet) continue;
// Sum of gravitational forces:
vec2 sum = vec2(0.0f);
for (int p = 0; p < MAX_PLANET; ++p)
{
// Optimize distance check:
GLfloat dx = planets[p].pos[0] - bullets[b].pos[0];
GLfloat dy = planets[p].pos[1] - bullets[b].pos[1];
GLfloat sqrDis = dx*dx + dy*dy;
GLfloat sqrRadSum = planets[p].maxRad + bullets[b].rad;
sqrRadSum *= sqrRadSum;
// If bullet is in relative area of a planet:
//float r = distance(planets[p].pos, bullets[b].pos);
//if (r <= planets[p].maxRad+bullets[b].rad)
if (sqrDis < sqrRadSum)
{
// Check if the bullet is colliding with the planet:
if (CollisionDetector::checkCollision(planets[p], bullets[b]))
{
bullets[b].vel = vec2(0.0f);
bullets[b].startTime = glutGet(GLUT_ELAPSED_TIME)/1000.0f;
bullets[b].onPlanet = true;
bullets[b].rad = 0.0f;
break;
}
}
// Calculate the sum of all forces of gravity:
vec2 ab = normalize(planets[p].pos-bullets[b].pos);
float fg = (GRAVITATIONAL*planets[p].mass*bullets[b].mass)/(sqrDis);
sum = sum+fg*ab;
}
if (true == bullets[b].onPlanet) continue;
float t1 = glutGet(GLUT_ELAPSED_TIME)/1000.0f;
float t = t1 - bullets[b].startTime;
bullets[b].vel = sum*t + bullets[b].vel;
// Maximum velocity?
if (length(bullets[b].vel) > MAX_BULLET_SPEED)
bullets[b].vel = MAX_BULLET_SPEED*normalize(bullets[b].vel);
bullets[b].pos = sum*t*t + bullets[b].vel*t+bullets[b].pos;
}
}
示例6: makeTopology
void Room::makeTopology()
{
m_cameraTopology.clear();
vec3 pos1, pos2;
vec3 dir1, dir2;
cv::Mat intr1, intr2;
float min = 181.0f, temp_angle;
int min_index = -1;
//get
for(size_t i = 0; i < m_cameras.size(); i++)
{
pos1 = m_cameras[i]->getPosition();
dir1 = m_cameras[i]->getDirVector();
intr1 = m_cameras[i]->cameraMatrix();
for(size_t j = i+1; j < m_cameras.size(); j++)
{
pos2 = m_cameras[j]->getPosition();
dir2 = m_cameras[j]->getDirVector();
intr2 = m_cameras[j]->cameraMatrix();
temp_angle = Line::lineAngle(vec2(dir1.x, dir1.y),vec2(dir2.x, dir2.y));
if(glm::abs(temp_angle) < min)
{
min = temp_angle;
min_index = j;
}
}
if(min_index != -1)
{
Edge edge(i,min_index, m_maxError);
//edge.setFundamentalMatrix(pos1, dir1, intr1, pos2, dir2, intr2);
m_cameraTopology.push_back(edge);
}
}
resolveTopologyDuplicates();
std::cout << "new camtopology size:" << m_cameraTopology.size() << std::endl;
}
示例7: mouseToGame
// Convert mouse coordinates to game coordinates:
glm::vec2 mouseToGame()
{
using glm::vec2;
// Mouse coordinates to game coordinates:
float xScale = windowWidth/float(gameWidth);
float yScale = windowHeight/float(gameHeight);
return vec2(mouse[0]/float(xScale),(windowHeight-mouse[1])/float(yScale));
}
示例8: iSphere
vec2 RayTracer::iSphere(const vec3 &ro, const vec3 &rd, const int &idx)
{//sphere obj id = 1
const vec4 &sph = this->objstack[idx].vec;
vec3 co = sph.xyz-ro;
if(glm::dot(co, rd) < 0) //determine by geometric solution
return vec2(FLT_MAX, idx); //no intersection
vec3 oc = ro-sph.xyz;
float b = 2.0 * glm::dot(oc, rd);
float c = glm::dot(oc,oc) - sph.w*sph.w;
float h = b*b - 4.0 *c;
if(h <0.0) return vec2(FLT_MAX, idx); //no intersection
//pick smaller one(i.e, close one)
//not (-b+sqrt(h)) /2
float sqrth = sqrt(h);
float t1 = 0.5*(-b - sqrth);
return vec2(t1, idx);
}
示例9:
Point *Geometry::make_point(float x, float y, float z, float s, float t)
{
auto pnt = make_point();
auto point_positions = point_attributes().find_or_create<vec3>("point_locations");
auto point_texcoords = point_attributes().find_or_create<vec2>("point_texcoords");
point_positions->put(pnt, vec3(x, y, z));
point_texcoords->put(pnt, vec2(s, t));
return pnt;
}
示例10: Interpolate
void Interpolate(ivec2 a, ivec2 b, vector<ivec2>& result)
{
int N = result.size();
vec2 step = vec2(b - a) / float(max(N - 1, 1));
vec2 current(a);
for (int i = 0; i<N; ++i)
{
result[i] = current;
current += step;
}
}
示例11: project
inline bool project(const vec3 & obj, const mat4 & mvp, const vec4 & viewport,
vec2 & out)
{
vec4 tmp = vec4(obj, 1.0f);
tmp = mvp * tmp;
if (tmp.w < 0)
return false;
tmp /= tmp.w;
tmp = tmp * 0.5f + 0.5f;
tmp[0] = tmp[0] * viewport[2] + viewport[0];
tmp[1] = tmp[1] * viewport[3] + viewport[1];
out = vec2(tmp);
return true;
}
示例12: CalculateRayFromPixel
void Picking::CalculateRayFromPixel( const glm::ivec2& pixel, const glm::ivec2& windowSize, const glm::mat4& invViewProj, Ray* outRay ) const
{
// Clip space coordinates for the pixel. (-1,-1) in lower left corner, (-1,1) upper left corner, (1,-1) lower right corner.
const vec2 mousePosNorm = vec2( -1.0f + 2.0f * (pixel.x / static_cast<float>(windowSize.x)),
1.0f - 2.0f * (pixel.y / static_cast<float>(windowSize.y)) );
// Translating pixel at near plane and far plane to world coordinates. Z-coordinate is depth into the screen (values between -1 and 1 are in view of camera).
const vec4 nearHomogeneous = invViewProj * vec4( mousePosNorm.x, mousePosNorm.y, 0.0f, 1.0f );
const vec4 farHomogeneous = invViewProj * vec4( mousePosNorm.x, mousePosNorm.y, 1.0f, 1.0f );
const vec3 nearWorld = vec3( nearHomogeneous ) / nearHomogeneous.w;
const vec3 farWorld = vec3( farHomogeneous ) / farHomogeneous.w;
outRay->Position = nearWorld;
outRay->Direction = glm::normalize( farWorld - nearWorld );
}
示例13: movemouse
void easygl::movemouse(double x, double y){
mouse = ivec2(x, y);
vec3 screen=vec3(x,viewportSize.y - y,zbuf);
vec3 pos= unProject(screen,dragmodelview,projection,vec4(0,0, viewportSize.x, viewportSize.y));
glmouse = vec2(pos.x,pos.y);
if(dragl && screen.z != 1)
{
vec2 gldiff = (gllastmouse - glmouse);
movement -= glm::vec3(gldiff,0);
}else{
dragmodelview = modelview;
glReadPixels(x,viewportSize.y - y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&zbuf);
}
gllastmouse = glmouse;
lastMouse = mouse;
}
示例14: QGLWidget
OpenGLWindow::OpenGLWindow(QWidget *parent) : QGLWidget(parent)
{
zoom = 1.0f;
twoDimensions = false;
mdrawJoints = mdrawLines = mdrawBones = true;
roomDims = vec3(100.0f, 100.0f, 100.0f);
camRot = vec3(0.0f, 0.0f, 0.0f);
//mouse
currentMousePos = lastMousePos = vec2(0.0f, 0.0f);
leftButton = false;
//QImage temp(QDir::currentPath() + "/Pictures/checkboard_texture.jpg");
//texture = QGLWidget::convertToGLFormat(temp);
generateNewRandomColor();
}
示例15: tmp
vector<vec2> objLoader::getTextures()const
{
vector<vec2> ret;
auto texStr = "vt ";
auto texStrLen = string(texStr).size();
auto pos = m_data.find(texStr);
auto pos2 = m_data.find("\n",pos);
float x, y;
while(pos != string::npos && pos2 != string::npos)
{
stringstream tmp(m_data.substr(pos + texStrLen, pos2 - pos - texStrLen));
tmp >> x;
tmp >> y;
//printf("[TEX] x:%f, y:%f\n", x, y);
ret.emplace_back(vec2(x,y));
pos = m_data.find(texStr, pos + 1);
pos2 = m_data.find("\n", pos);
}
return ret;
}