本文整理汇总了C++中glm::vec3方法的典型用法代码示例。如果您正苦于以下问题:C++ glm::vec3方法的具体用法?C++ glm::vec3怎么用?C++ glm::vec3使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类glm
的用法示例。
在下文中一共展示了glm::vec3方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: importanceSampleLight
void importanceSampleLight(vec3 pt, materialLayer* ml, vec3 norm, vec2 uv, vec3 oDir, vec3* ret_iDir, color* ret_weight)
{
float r1, r2;
r1 = nrand();
r2 = nrand();
vec3 x2 = vec3(3 * r1 - 1.5, 6, 12 * r2 - 6);
vec3 dirXtoX2 = x2 - pt;
vec3 iDir = normalize(x2 - pt);
vec3 norm2 = vec3(0, -1, 0);
float prob = 1.f / (3.f * 12.f);
float cosAngle = dot(norm, iDir);
float cosAngle2 = dot(norm2, -iDir);
float G = max(0.001, cosAngle2) / dot(dirXtoX2, dirXtoX2);
color brdf = BRDF(ml, norm, uv.x, uv.y, oDir, iDir);
int chi = dot(norm, norm2) < 0 ? 1 : 0;
*ret_iDir = iDir;
//*ret_pdf = max(0.001f, prob / G);
*ret_weight = brdf * chi * max(0.001, cosAngle2) / (dot(dirXtoX2, dirXtoX2) * prob);
}
示例2: tan
Camera& Camera::stereo(float _c, float _e) {
isStereo = true;
_convergence = _c;
_eyeSep = _e;
float top, bottom, leftL, rightL, leftR, rightR;
top = nearPlane * tan(radians(fovy)/2);
bottom = -top;
float a = aspect * tan(radians(fovy)/2) * convergence();
float b = a - eyeSep()/2;
float c = a + eyeSep()/2;
leftR = -c * nearPlane/convergence();
rightR = b * nearPlane/convergence();
leftL = -b * nearPlane/convergence();
rightL = c * nearPlane/convergence();
//rightProjection = Matrix4f::perspective(leftR, rightR, bottom, top, nearPlane, farPlane );
//rightTranslate = Matrix4f::translate( -eyeSep/2, 0.0f, 0.0f );
//leftProjection = Matrix4f::perspective(leftL, rightL, bottom, top, nearPlane, farPlane );
//leftTranslate = Matrix4f::translate( eyeSep/2, 0.0f, 0.0f );
rightProjection = glm::frustum(leftR, rightR, bottom, top, nearPlane, farPlane );
rightTranslate = glm::translate(mat4(1.0), vec3(-eyeSep()/2, 0.0f, 0.0f) );
leftProjection = glm::frustum(leftL, rightL, bottom, top, nearPlane, farPlane );
leftTranslate = glm::translate(mat4(1.0), vec3(eyeSep()/2, 0.0f, 0.0f) );
isTransformed = true;
return *this;
}
示例3: setProjection
void Scene::setProjection()
{
_proj = glm::perspective(_fov, float(_width) / float(_height), _depthMin, _depthMax);
glViewport(0, 0, _width, _height);
// Set the size for the settings quad
float size = 0.03;
float qWidth = size;
float aspectRatio = float(_width) / float(_height);
float qHeight = size * aspectRatio;
float qTransX = 1.0 - qWidth - size * 0.5;
float qTransY = -1.0 + qHeight + size * 0.5;
mat4 qScale = glm::scale(mat4(), vec3(qWidth, qHeight, 1.0));
mat4 qTrans = glm::translate(mat4(), vec3(qTransX, qTransY, 0));
_settingsIconModel = qTrans * qScale;
qScale = glm::scale(mat4(), vec3(1.0 / qWidth, 1.0 / qHeight, 1.0));
qTrans = glm::translate(mat4(), vec3(-qTransX, -qTransY, 1.0));
_settingsIconModelInv = qScale * qTrans;
}
示例4: render
void SceneBasic_Uniform::render()
{
glClear(GL_COLOR_BUFFER_BIT);
rotationMatrix = glm::rotate(mat4(1.0f), angle, vec3(0.0f,0.0f,1.0f));
GLuint location = glGetUniformLocation(programHandle, "RotationMatrix");
if( location >= 0 )
{
glUniformMatrix4fv(location, 1, GL_FALSE, &rotationMatrix[0][0]);
}
glBindVertexArray(vaoHandle);
glDrawArrays(GL_TRIANGLES, 0, 3 );
}
示例5: render
void SceneSpot::render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
vec4 lightPos = vec4(10.0f * cos(angle), 10.0f, 10.0f * sin(angle), 1.0f);
prog.setUniform("Spot.position", view * lightPos);
mat3 normalMatrix = mat3( vec3(view[0]), vec3(view[1]), vec3(view[2]) );
prog.setUniform("Spot.direction", normalMatrix * vec3(-lightPos) );
prog.setUniform("Kd", 0.9f, 0.5f, 0.3f);
prog.setUniform("Ks", 0.95f, 0.95f, 0.95f);
prog.setUniform("Ka", 0.9f * 0.3f, 0.5f * 0.3f, 0.3f * 0.3f);
prog.setUniform("Shininess", 100.0f);
model = mat4(1.0f);
model *= glm::translate(vec3(0.0f,0.0f,-2.0f));
model *= glm::rotate(45.0f, vec3(0.0f,1.0f,0.0f));
model *= glm::rotate(-90.0f, vec3(1.0f,0.0f,0.0f));
setMatrices();
teapot->render();
prog.setUniform("Kd", 0.9f, 0.5f, 0.3f);
prog.setUniform("Ks", 0.95f, 0.95f, 0.95f);
prog.setUniform("Ka", 0.9f * 0.3f, 0.5f * 0.3f, 0.3f * 0.3f);
prog.setUniform("Shininess", 100.0f);
model = mat4(1.0f);
model *= glm::translate(vec3(-1.0f,0.75f,3.0f));
model *= glm::rotate(-90.0f, vec3(1.0f,0.0f,0.0f));
setMatrices();
torus->render();
prog.setUniform("Kd", 0.7f, 0.7f, 0.7f);
prog.setUniform("Ks", 0.9f, 0.9f, 0.9f);
prog.setUniform("Ka", 0.2f, 0.2f, 0.2f);
prog.setUniform("Shininess", 180.0f);
model = mat4(1.0f);
setMatrices();
plane->render();
}
示例6: initScene
void SceneDiffuse::initScene()
{
cout << "Compiling Shaders" << endl;
compileAndLinkShader();
glEnable(GL_DEPTH_TEST);
if (loadCamMatFlag){
cout << "Loading Camera Matrices: ";
camMatVec = new vector<mat4>();
//glm::mat4 camMatrix;
loadCameraMatrices("cameraMatrix.txt", camMatVec);
cout << camMatVec->size() << " matrices"<<endl;
view = (*camMatVec)[0];
//view = glm::lookAt(vec3(0.0f, 0.0f, 2.0f), vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f));
}
else{
view = glm::lookAt(vec3(0.0f, 0.0f, 2.0f), vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f));
//view = glm::mat4(1.0f);
}
cout << "Loading Mesh" << endl;
//ogre = new VBOMesh("../media/bs_ears.obj", true, false, false);
ogre = new VBOMesh("C:\\Android&BMO.obj", true, false, false);
//torus = new VBOTorus(0.7f, 0.3f, 30, 30);
model = mat4(1.0f);
//view = glm::lookAt(vec3(0.0f, 0.0f, 2.0f), vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f));
projection = mat4(1.0f);
prog.setUniform("Kd", 0.9f, 0.5f, 0.3f);
prog.setUniform("Ld", 1.0f, 1.0f, 1.0f);
prog.setUniform("LightPosition", view * vec4(5.0f, 5.0f, 2.0f, 1.0f));
}
示例7: Update
void Agent::Update(float delta)
{
vec3 testInput = vec3(m_position.x, m_position.y, 0);
m_clock += delta;
m_memoryClock += delta;
float memoryFrequency = 1.f;
if (m_memoryClock > memoryFrequency)
{
m_memoryClock -= memoryFrequency;
vec3 testInput = vec3(m_position.x, m_position.y, 0);
AddToMemory(testInput);
m_neuralNetwork->TrainNetwork(m_memory);
}
m_position += m_velocity * delta;
if (CheckBounds())
{
m_facingDirection = 44.f / 7.f * (float)((rand() % 1000) / 1000.f);
m_velocity.x = m_maxSpeed * sin(m_facingDirection);
m_velocity.y = m_maxSpeed * cos(m_facingDirection);
}
m_neuralNetwork->RenderDebug(vec2(30, 30), 200, m_memory);
m_foodClock--;
m_waterClock--;
}
示例8: render
void SceneDirectional::render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
prog.setUniform("Kd", 0.8f, 0.8f, 0.8f);
prog.setUniform("Ks", 0.9f, 0.9f, 0.9f);
prog.setUniform("Ka", 0.1f, 0.1f, 0.1f);
prog.setUniform("Shininess", 180.0f);
model = mat4(1.0f);
model *= glm::rotate(glm::radians(90.0f), vec3(0.0f,1.0f,0.0f));
setMatrices();
torus->render();
prog.setUniform("Kd", 0.4f, 0.4f, 0.4f);
prog.setUniform("Ks", 0.9f, 0.9f, 0.9f);
prog.setUniform("Ka", 0.1f, 0.1f, 0.1f);
prog.setUniform("Shininess", 180.0f);
model = mat4(1.0f);
model *= glm::translate(vec3(0.0f,-0.45f,0.0f));
setMatrices();
//plane->render();
}
示例9: randRayInSphere
vec3 randRayInSphere() {
float rx = 0, ry = 0, rz = 0;
// technically, this is faster, sooooo :P
while (rx*rx + ry*ry + rz*rz <= 1.0f)
{
rx = 2 * nrand() - 1.0f;
ry = 2 * nrand() - 1.0f;
rz = 2 * nrand() - 1.0f;
if (rx*rx + ry*ry + rz*rz >= 0.98f)
continue;
break;
}
return normalize(vec3(rx, ry, rz));
}
示例10: render
void SceneRefractCube::render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
vec3 cameraPos = vec3( 7.0f * cos(angle), 2.0f, 7.0f * sin(angle));
view = glm::lookAt(cameraPos, vec3(0.0f,0.0f,0.0f), vec3(0.0f,1.0f,0.0f));
prog.setUniform("WorldCameraPosition", cameraPos);
//view = glm::lookAt(vec3(0.0f,2.0f,0.0f), vec3(0.0f,0.0f,0.0f), vec3(0.0f,0.0f,1.0f));
prog.setUniform("DrawSkyBox", true);
model = mat4(1.0f);
setMatrices();
sky->render();
prog.setUniform("DrawSkyBox", false);
prog.setUniform("Material.Eta", 0.94f);
prog.setUniform("Material.ReflectionFactor", 0.1f);
model = mat4(1.0f);
model *= glm::translate(vec3(0.0f,-1.0f,0.0f));
model *= glm::rotate(-90.0f, vec3(1.0f,0.0f,0.0f));
setMatrices();
teapot->render();
}
示例11: paintGL
void My_OpenGLWidget::paintGL() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/************* If new attributes/uniforms are added, make sure they are set up here *********/
mat4 modelMatrix = glm::rotate(glm::rotate(downAngle, vec3(1.0f, 0.0f, 0.0f)), leftAngle, vec3(0.0f, 1.0f, 0.0f));
mat4 projMatrix = projectionMatrix * cameraMatrix;
glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, &modelMatrix[0][0]);
glUniformMatrix4fv(viewMatrixLocation, 1, GL_FALSE, &projMatrix[0][0]);
glUniform4f(camVecLocation,camLocation.x, camLocation.y, camLocation.z, 1.0f);
sg->traverse(cameraMatrix );//traverse the scene graph
sg->draw(vLocation, vNormal, vShiny, cLocation, vbo, vbo2, vbo3, cbo);
}
示例12: initScene
void SceneTessTeapotDepth::initScene()
{
compileAndLinkShader();
glClearColor(0.5f,0.5f,0.5f,1.0f);
glEnable(GL_DEPTH_TEST);
teapot = new VBOTeapotPatch();
///////////// Uniforms ////////////////////
prog.setUniform("MinTessLevel", 2);
prog.setUniform("MaxTessLevel", 15);
prog.setUniform("MaxDepth", 20.0f);
prog.setUniform("MinDepth", 2.0f);
prog.setUniform("LineWidth", 0.8f);
prog.setUniform("LineColor", vec4(0.05f,0.0f,0.05f,1.0f));
prog.setUniform("LightPosition", vec4(0.0f,0.0f,0.0f,1.0f));
prog.setUniform("LightIntensity", vec3(1.0f,1.0f,1.0f));
prog.setUniform("Kd", vec3(0.9f, 0.9f, 1.0f));
/////////////////////////////////////////////
glPatchParameteri(GL_PATCH_VERTICES, 16);
}
示例13: resizeGL
void GLWidget::resizeGL(int w, int h) {
width = w;
height = h;
radius = min(width, height) * .75;
float aspect = (float)w/h;
projMatrix = perspective(45.0f, aspect, 1.0f, 100.0f);
viewMatrix = lookAt(vec3(0,0,-10),vec3(0,0,0),vec3(0,1,0));
modelMatrix = mat4(1.0f);
glUseProgram(cubeProg);
glUniformMatrix4fv(cubeProjMatrixLoc, 1, false, value_ptr(projMatrix));
glUniformMatrix4fv(cubeViewMatrixLoc, 1, false, value_ptr(viewMatrix));
glUniformMatrix4fv(cubeModelMatrixLoc, 1, false, value_ptr(modelMatrix));
glUniformMatrix4fv(cubeRotationMatrixLoc, 1, false, value_ptr(rotationMatrix));
glUseProgram(gridProg);
glUniformMatrix4fv(gridProjMatrixLoc, 1, false, value_ptr(projMatrix));
glUniformMatrix4fv(gridViewMatrixLoc, 1, false, value_ptr(viewMatrix));
glUniformMatrix4fv(gridModelMatrixLoc, 1, false, value_ptr(modelMatrix));
glUniformMatrix4fv(gridRotationMatrixLoc, 1, false, value_ptr(rotationMatrix));
}
示例14: init
void easygl::init()
{
target = vec3(0, 1, 0);
up = vec3(0, 1, 0);
orientation = quat();
direction = vec3(0, 0, -1);
right = cross(up, direction);
up = cross(direction, right);
position = vec3(5.0f, 5.0f, 5.0f);
fieldOfView = 60.0f;
near = 0.1f, far = 1000.0f;
aspectRatio = 1.0;
dragl = false;
dragr = false;
//sphere.load("sphere.stl", vec4(1.0f, 0.0f, 1.0f, 1.0f));
for(layer &l : d.layers){
l.findcontours();
l.offset(1);
l.show();
}
}
示例15: display
void display()
{
static float angle = 0.0;
angle +=0.5;
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
shader->begin();
/// init shader data
glm::vec3 eyePos = glm::vec3(0.0,0.0,3.0);
// init light in the scene
glm::vec3 lightPos = glm::vec3(0.0,0.0,1.0);
vec3 La = vec3(0.5,0.5,0.5);
vec3 Ld = vec3(1.0,1.0,1.0);
vec3 Ls = vec3(1.0,1.0,1.0);
// init model material
vec3 Ka = vec3(0.2,0.2,0.2);
vec3 Kd = vec3(1.0,1.0,1.0);
vec3 Ks = vec3(1.0,1.0,1.0);
float shiness = 5.0;
glm::mat4 projection_matrix = glm::perspective(45.0f,(float)width/height,1.0f,1000.0f);
glm::mat4 view_matrix = glm::lookAt(eyePos,glm::vec3(0.0),glm::vec3(0.0,1.0,0.0));
view_matrix = glm::rotate(view_matrix,xAngle,glm::vec3(0.0,1.0,0.0));
view_matrix = glm::rotate(view_matrix,yAngle,glm::vec3(1.0,0.0,0.0));
glm::mat4 model_matrix = glm::rotate(glm::mat4(1.0),angle,glm::vec3(0.0,1.0,0.0));
model_matrix = glm::translate(model_matrix,glm::vec3(0.0,0.0,0));
/// populate shader data to shader
shader->setUniform("eyePos",eyePos);
// for light
shader->setUniform("light.position",lightPos);
shader->setUniform("light.La",La);
shader->setUniform("light.Ld",Ld);
shader->setUniform("light.Ls",Ls);
// for material
shader->setUniform("mat.Ka",Ka);
shader->setUniform("mat.Kd",Kd);
shader->setUniform("mat.Ks",Ks);
shader->setUniform("mat.shiness",shiness);
shader->setUniform("view_matrix",view_matrix);
shader->setUniform("projection_matrix",projection_matrix);
shader->setUniform("model_matrix",model_matrix);
model->draw();
model_matrix = glm::translate(glm::mat4(1.0),lightPos);
shader->setUniform("model_matrix",model_matrix);
glutWireSphere(0.2,10,10);
glutSwapBuffers();
}