本文整理汇总了C++中glm::mat3方法的典型用法代码示例。如果您正苦于以下问题:C++ glm::mat3方法的具体用法?C++ glm::mat3怎么用?C++ glm::mat3使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类glm
的用法示例。
在下文中一共展示了glm::mat3方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: renderScene
void ScenePostProcessSimple::renderScene(double delta)
{
m_shadingProg->use();
glClearColor(.5f, .5f, .5f, 1.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
m_sceneCam->update();
m_shadingProg->setUniform("Light.lightPos_CAM",
(m_sceneCam->getViewMatrix() * m_light->getWorldTransform()) * m_light->getPosition());
// Render plane
{
m_shadingProg->setUniform("MainTex", 0);
SceneObject* obj = m_sceneObjects[1];
obj->update(delta);
mat4 mvp, mv;
mat3 normal;
mv = m_sceneCam->getViewMatrix() * obj->getWorldTransform();
mvp = m_sceneCam->getMVP(obj->getWorldTransform());
normal = mat3(vec3(mv[0]), vec3(mv[1]), vec3(mv[2]));
m_shadingProg->setUniform("MODELVIEW", mv);
m_shadingProg->setUniform("MVP", mvp);
m_shadingProg->setUniform("NORMAL", normal);
obj->getMesh()->uploadMaterialProperties(m_shadingProg);
obj->render();
}
// Render box
{
m_shadingProg->setUniform("MainTex", 1);
SceneObject* obj = m_sceneObjects[0];
obj->rotate(25 * delta, vec3(0, 1, 0));
obj->update(delta);
mat4 mvp, mv;
mat3 normal;
mv = m_sceneCam->getViewMatrix() * obj->getWorldTransform();
mvp = m_sceneCam->getMVP(obj->getWorldTransform());
normal = mat3(vec3(mv[0]), vec3(mv[1]), vec3(mv[2]));
m_shadingProg->setUniform("MODELVIEW", mv);
m_shadingProg->setUniform("MVP", mvp);
m_shadingProg->setUniform("NORMAL", normal);
obj->getMesh()->uploadMaterialProperties(m_shadingProg);
obj->render();
}
}
示例2: update
void SceneNormalMapping::update(double delta)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_program->use();
m_sceneCam->update();
//m_sceneLight->rotate(200 * delta, vec3(.5, 1, -1));
m_program->setUniform("Light.lightPos_CAM",
(m_sceneCam->getViewMatrix() * m_sceneLight->getWorldTransform()) * m_sceneLight->getPosition());
{
SceneObject* obj = m_sceneObjects.at(0);
//obj->rotate(75 * delta, vec3(.75, .5, -1));
//obj->rotate(75 * delta, vec3(0, 1, 0));
obj->update(delta);
mat4 mvp, mv;
mat3 normal;
mv = m_sceneCam->getViewMatrix() * obj->getWorldTransform();
mvp = m_sceneCam->getMVP(obj->getWorldTransform());
normal = mat3(vec3(mv[0]), vec3(mv[1]), vec3(mv[2]));
m_program->setUniform("MODELVIEW", mv);
m_program->setUniform("MVP", mvp);
m_program->setUniform("NORMAL", normal);
obj->getMesh()->uploadMaterialProperties(m_program);
obj->render();
}
}
示例3: VertexShader
// THE PROBLEM PROBABLY COMES FROM HERE
void VertexShader( const vec3& v, Pixel& p ){
//It should take the 3D position of a vertex v and compute its 2D image position and store it in the given 2D
//integer vector p. glm::ivec2 is a data type for 2D integer vectors, i.e. a pixel position will be represented by two
//integers.
cout << "in function VertexShader _ 1\n";
vec3 newV = v-cameraPos;
float cosYaw = cos(yaw);
float sinYaw = sin(yaw);
vec3 firstColumn = vec3(cosYaw, 0.0, -sinYaw);
vec3 secondColumn = vec3(0.0, 1.0, 0.0);
vec3 thirdColumn = vec3(sinYaw, 0.0, cosYaw);
R = mat3(firstColumn,secondColumn,thirdColumn);
// WE CHANGED d IN ORDER TO DO A ROTATION
newV=R*newV;
//cout << "newV:("<<newV.x<<","<<newV.y<<","<<newV.z<<")\n";
p.x = focal_length * (newV.x/newV.z) + SCREEN_WIDTH/2.f;
p.y = focal_length * (newV.y/newV.z) +SCREEN_HEIGHT/2.f;
// PROBLEM: DOUBT ABOUT THIS PART
p.zinv = 1/newV.z;
/*
if (p.zinv>depthBuffer[p.x][p.y])
depthBuffer[p.x][p.y]=p.zinv;
*/
//cout <<"pixel p:("<<p.x<<","<<p.y<<","<<p.zinv<<")\n";
//cout <<"depthBuffer["<<p.x<<","<<p.y<<"]: "<<depthBuffer[p.x][p.y]<<"\n";
}
示例4: rotate_local_z
void GLFrame::rotate_local_z(float angle)
{
mat4 rot_mat4;
mat3 rot_mat;
// Only the up vector needs to be rotated
rot_mat = mat3(glm::rotate(rot_mat4, angle, forward));
up = rot_mat * up;
}
示例5: rotate_world
// Rotate in world coordinates...
//Rotates in place around a vector in world coordinates
//Does NOT rotate the frame itself around the world origin (ie the pos of the frame doesn't change)
void GLFrame::rotate_world(float angle, float x, float y, float z)
{
mat4 rot_mat4;
mat3 rot_mat;
// Create the Rotation matrix
rot_mat = mat3(glm::rotate(rot_mat4, angle, vec3(x,y,z)));
//transform up and forward axis
up = rot_mat * up;
forward = rot_mat * forward;
}
示例6: rotate_local_y
void GLFrame::rotate_local_y(float angle)
{
mat4 rot_mat4;
mat3 rot_mat;
// Just Rotate around the up vector
// Create a rotation matrix around my Up (Y) vector
rot_mat = mat3(glm::rotate(rot_mat4, angle, up));
// Rotate forward pointing vector
forward = rot_mat * forward;
}
示例7: ProcessEntities
void GuiMeshRender::ProcessEntities(const EntityMap &entities) {
if (entities.empty()) {
//printf("Warning: GuiMeshRender: Entity list is empty\n");
return;
}
EntityMap::const_iterator it, ite;
GuiMeshPtr mesh;
TransformPtr transform;
mat4 model, view, projection, model_view, mvp;
mat3 normal;
// warning: make sure the values here are all floats
projection = glm::ortho(0.0f, 800.0f, 600.0f, 0.0f, -1.0f, 1.0f);
for (it = entities.begin(), ite = entities.end(); it != ite; ++it) {
mesh = gui_mesh_mapper_(it->second);
transform = transform_mapper_(it->second);
model = transform->world();
model_view = model; // camera does not need to effect this
mvp = projection * model_view;
normal = inverse(transpose(mat3(model_view)));
shared_ptr<BasicMaterial> material = boost::dynamic_pointer_cast<BasicMaterial>(mesh->material);
vec4 light_pos = material->light_position_;
// hack to have light move with world
// todo: implement light as entity
material->light_position_ = model_view * light_pos;
// do things like setup colors and lights
// and attach shader program
mesh->material->PreRender();
material->light_position_ = light_pos;
// push matrices up
mesh->material->PushMatrices(model_view, projection, mvp, normal);
// call draw
mesh->geometry->Draw();
// let go of shader program
mesh->material->PostRender();
}
}
示例8: rotate_local_x
void GLFrame::rotate_local_x(float angle)
{
mat3 rot_mat;
mat4 rot_mat4;
vec3 local_x;
//get local x axis
local_x = glm::cross(up, forward);
rot_mat = mat3(glm::rotate(rot_mat4, angle, local_x));
//have to rotate both up and forward vectors
up = rot_mat * up;
forward = rot_mat * forward;
}
示例9: local_to_world
// Convert Coordinate Systems
// This is pretty much, do the transformation represented by the rotation
// and position on the point
// Is it better to stick to the convention that the destination always comes
// first, or use the conventions that "sounds" like the function...
vec3 GLFrame::local_to_world(const vec3 local, bool rot_only)
{
vec3 world;
// Create the rotation matrix based on the vectors
mat3 rot_mat = mat3(get_matrix(true));
// Do the rotation
world = rot_mat * local;
// Translate the point
if(!rot_only)
world += origin;
return world;
}
示例10: setUp
void LegacyMathTest::setUp() {
using glm::quat;
using glm::mat3;
// Data from:
// http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/steps/index.htm
// http://www.euclideanspace.com/maths/algebra/matrix/transforms/examples/index.htm
// Identity (no rotation)
addTestData(quat( 1.f, 0.0f, 0.0f, 0.0f), Anglef( 0, 0, 0), mat3( 1, 0, 0, 0, 1, 0, 0, 0, 1));
// 90 degrees about y axis
addTestData(quat(0.7071f, 0.0f, 0.7071f, 0.0f), Anglef( 90, 0, 0), mat3( 0, 0, 1, 0, 1, 0, -1, 0, 0));
// 180 degrees about y axis
addTestData(quat( 0.0f, 0.0f, 1.f, 0.0f), Anglef(180, 0, 0), mat3(-1, 0, 0, 0, 1, 0, 0, 0,-1));
// 270 degrees about y axis
addTestData(quat(0.7071f, 0.0f,-0.7071f, 0.0f), Anglef(-90, 0, 0), mat3( 0, 0,-1, 0, 1, 0, 1, 0, 0));
addTestData(quat(0.7071f, 0.0f, 0.0f, 0.7071f), Anglef( 0, 90, 0), mat3( 0,-1, 0, 1, 0, 0, 0, 0, 1));
addTestData(quat( 0.5f, 0.5f, 0.5f, 0.5f), Anglef( 90, 90, 0), mat3( 0, 0, 1, 1, 0, 0, 0, 1, 0));
addTestData(quat( 0.0f, 0.7071f, 0.7071f, 0.0f), Anglef(180, 90, 0), mat3( 0, 1, 0, 1, 0, 0, 0, 0,-1));
addTestData(quat( 0.5f, -0.5f, -0.5f, 0.5f), Anglef(-90, 90, 0), mat3( 0, 0,-1, 1, 0, 0, 0,-1, 0));
addTestData(quat(0.7071f, 0.0f, 0.0f,-0.7071f), Anglef( 0,-90, 0), mat3( 0, 1, 0, -1, 0, 0, 0, 0, 1));
addTestData(quat( 0.5f, -0.5f, 0.5f, -0.5f), Anglef( 90,-90, 0), mat3( 0, 0, 1, -1, 0, 0, 0,-1, 0));
addTestData(quat( 0.0f,-0.7071f, 0.7071f, 0.0f), Anglef(180,-90, 0), mat3( 0,-1, 0, -1, 0, 0, 0, 0,-1));
addTestData(quat( 0.5f, 0.5f, -0.5f, -0.5f), Anglef(-90,-90, 0), mat3( 0, 0,-1, -1, 0, 0, 0, 1, 0));
addTestData(quat(0.7071f, 0.7071f, 0.0f, 0.0f), Anglef( 0, 0, 90), mat3( 1, 0, 0, 0, 0,-1, 0, 1, 0));
addTestData(quat( 0.5f, 0.5f, 0.5f, -0.5f), Anglef( 90, 0, 90), mat3( 0, 1, 0, 0, 0,-1, -1, 0, 0));
addTestData(quat( 0.0f, 0.0f, 0.7071f,-0.7071f), Anglef(180, 0, 90), mat3(-1, 0, 0, 0, 0,-1, 0,-1, 0));
addTestData(quat( 0.5f, 0.5f, -0.5f, 0.5f), Anglef(-90, 0, 90), mat3( 0,-1, 0, 0, 0,-1, 1, 0, 0));
addTestData(quat( 0.0f, 1.0f, 0.0f, 0.0f), Anglef( 0, 0,180), mat3( 1, 0, 0, 0,-1, 0, 0, 0,-1));
addTestData(quat( 0.0f, 0.7071f, 0.0f,-0.7071f), Anglef( 90, 0,180), mat3( 0, 0,-1, 0,-1, 0, -1, 0, 0));
addTestData(quat( 0.0f, 0.0f, 0.0f, 1.0f), Anglef(180, 0,180), mat3(-1, 0, 0, 0,-1, 0, 0, 0, 1));
addTestData(quat( 0.0f, 0.7071f, 0.0f, 0.7071f), Anglef(-90, 0,180), mat3( 0, 0, 1, 0,-1, 0, 1, 0, 0));
addTestData(quat(0.7071f,-0.7071f, 0.0f, 0.0f), Anglef( 0, 0,-90), mat3( 1, 0, 0, 0, 0, 1, 0,-1, 0));
addTestData(quat( 0.5f, -0.5f, 0.5f, 0.5f), Anglef( 90, 0,-90), mat3( 0,-1, 0, 0, 0, 1, -1, 0, 0));
addTestData(quat( 0.0f, 0.0f, 0.7071f, 0.7071f), Anglef(180, 0,-90), mat3(-1, 0, 0, 0, 0, 1, 0, 1, 0));
addTestData(quat( 0.5f, -0.5f, -0.5f, -0.5f), Anglef(-90, 0,-90), mat3( 0, 1, 0, 0, 0, 1, 1, 0, 0));
}
示例11: main
//.........这里部分代码省略.........
size_t total_size = (torus.tris.size()*3 + sphere.tris.size()*3) * sizeof(vert_attribs);
size_t sphere_offset = torus.tris.size()*3;
glBufferData(GL_ARRAY_BUFFER, total_size, &vert_data[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(vert_attribs), 0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(vert_attribs), (void*)sizeof(vec3));
GLuint inst_buf;
glGenBuffers(1, &inst_buf);
glBindBuffer(GL_ARRAY_BUFFER, inst_buf);
glBufferData(GL_ARRAY_BUFFER, instance_pos.size()*3*sizeof(float), &instance_pos[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, 0);
glVertexAttribDivisor(3, 1);
GLuint basic_shader = load_shader_file_pair("../media/shaders/basic_transform.vp", "../media/shaders/uniform_color.fp");
GLuint gouraud_shader = load_shader_file_pair("../media/shaders/gouraud_ads.vp", "../media/shaders/gouraud_ads.fp");
GLuint phong_shader = load_shader_file_pair("../media/shaders/phong_ads.vp", "../media/shaders/phong_ads.fp");
mat4 proj_mat = glm::perspective(DEG_TO_RAD(35.0f), WIDTH/(float)HEIGHT, 0.3f, 100.0f);
mat4 view_mat;
mat4 mvp_mat;
mat3 normal_mat;
mat4 translate_sphere = glm::translate(mat4(1), vec3(0.8f, 0.4f, 0.0f));
vec4 floor_color(0, 1, 0, 1);
vec3 torus_ambient(0.0, 0, 0);
vec3 torus_diffuse(1.0, 0, 0);
vec3 torus_specular(0, 0, 0);
vec3 sphere_ambient(0, 0, 0.2);
vec3 sphere_diffuse(0, 0, 0.7);
vec3 sphere_specular(1, 1, 1);
glUseProgram(basic_shader);
set_uniform4fv(basic_shader, "color", glm::value_ptr(floor_color));
glUseProgram(gouraud_shader);
glUseProgram(phong_shader);
set_uniform1f(phong_shader, "shininess", 128.0f);
vec3 light_direction(0, 10, 5);
glUseProgram(basic_shader);
GLFrame camera(true);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
示例12: cameraPos
const int SCREEN_HEIGHT = 500;
SDL_Surface* screen;
/* Depth buffer*/
float depthBuffer[SCREEN_HEIGHT][SCREEN_WIDTH];
/* Camera */
vec3 cameraPos(0, 0, -3.001);
float focalLength = SCREEN_WIDTH;
// Rotation angle controlling camera rotation around y-axis
float yaw = 0;
// Rotation constant - Angle update on the y axis for a rotation
float ROTATION = 0.1;
float TRANSLATION = 0.5;
// Rotation matrix
mat3 R = mat3(0, 0, 0, 0, 0, 0, 0, 0, 0);
/* Light */
vec3 lightPos(0, -0.5, -0.7);
vec3 lightPower = 14.f*vec3(1, 1, 1);
vec3 indirectLightPowerPerArea = 0.5f*vec3(1, 1, 1);
vec3 currentNormal;
vec3 currentReflectance;
// ----------------------------------------------------------------------------
// FUNCTIONS
void PixelShader(Pixel& p);
void DrawPolygon(const vector<Vertex>& vertices);
void DrawPolygonRows(const vector<Pixel>& leftPixels, const vector<Pixel>& rightPixels);
示例13: Update
void Update()
{
// Compute frame time:
int t2 = SDL_GetTicks();
float dt = float(t2 - t);
t = t2;
cout << "Render time: " << dt << " ms." << endl;
Uint8* keystate = SDL_GetKeyState(0);
if (keystate[SDLK_w]){
lightPos += forwardDir;
}
if (keystate[SDLK_s]){
lightPos -= forwardDir;
}
if (keystate[SDLK_a]){
lightPos -= rightDir;
}
if (keystate[SDLK_d]){
lightPos += rightDir;
}
if (keystate[SDLK_q]){
lightPos -= downDir;
}
if (keystate[SDLK_e]){
lightPos += downDir;
}
if (keystate[SDLK_UP])
{
// Move camera forward
cameraPos += forwardDir;
}
if (keystate[SDLK_DOWN])
{
// Move camera backward
cameraPos -= forwardDir;
}
if (keystate[SDLK_LEFT])
{
/* // Move camera to the left
cameraPos.x--;
*/
// Rotate camera anti-clockwise around y-axis
yaw += dyaw;
cout << yaw;
vec3 col1(cosf(yaw), 0, -sinf(yaw));
vec3 col3(sinf(yaw), 0, cosf(yaw));
R = mat3(col1, vec3(0, 1, 0), col3);
vec3 rightDir(R[0][0], R[0][1], R[0][2]);
vec3 downDir(R[1][0], R[1][1], R[1][2]);
vec3 forwardDir(R[2][0], R[2][1], R[2][2]);
}
if (keystate[SDLK_RIGHT])
{
/*
// Move camera to the right
cameraPos.x++;
*/
// Rotate camera clockwise around y-axis
yaw -= dyaw;
vec3 col1(cosf(yaw), 0, -sinf(yaw));
vec3 col3(sinf(yaw), 0, cosf(yaw));
R = mat3(col1, vec3(0, 1, 0), col3);
vec3 rightDir(R[0][0], R[0][1], R[0][2]);
vec3 downDir(R[1][0], R[1][1], R[1][2]);
vec3 forwardDir(R[2][0], R[2][1], R[2][2]);
}
}