本文整理汇总了C++中camera::getProjectionMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ camera::getProjectionMatrix方法的具体用法?C++ camera::getProjectionMatrix怎么用?C++ camera::getProjectionMatrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类camera
的用法示例。
在下文中一共展示了camera::getProjectionMatrix方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: displayBoxFun
// RENDERS AN OBJECT USING A SKYBOX AS THE TEXTURE SOURCE
void displayBoxFun(GLuint shaderProg) {
Matrix4f viewMat, projMat, modelMat, m;
// set up the mode to wireframe
// setting up the transformaiton of the object from model coord. system to world coord.
modelMat = Matrix4f::identity();
//modelMat = Matrix4f::translation(0,0,0);
modelMat = Matrix4f::scale(50,50,50);
// ROATE THE OBJECT AROUND THE CAMERA VECTOR
// CAN ADD ROTATIONS AROUND THE PRIMARY AXIS
modelMat = modelMat * Matrix4f::rotateVector(cam.getLookAtVector(),angle,1);
// setting up the viewpoint transformation
viewMat = cam.getViewMatrix(NULL);
// setting up the projection transformation
projMat= cam.getProjectionMatrix(NULL);
// putting it all together
m = projMat * viewMat * modelMat;
// tell openfl which shader program to use
glUseProgram(shaderProg);
// transfer the modelViewProjection matrix to the shader
GLuint locMat= 0;
locMat=glGetUniformLocation(shaderProg, "modelViewProjMat");
glUniformMatrix4fv(locMat,1,1,(float *)m.vm);
// transfer the modelView matrix to the shader
m = viewMat * modelMat;
locMat=glGetUniformLocation(shaderProg, "modelViewMat");
glUniformMatrix4fv(locMat,1,1,(float *)m.vm);
// transfer the model matrix to the shader
m = modelMat;
locMat=glGetUniformLocation(shaderProg, "modelMat");
glUniformMatrix4fv(locMat,1,1,(float *)m.vm);
// load the camera position to the shader
locMat=glGetUniformLocation(shaderProg, "camPos");
Vector3f camPos = cam.getPosition();
glUniform3fv(locMat,1, (float *) &camPos);
// load the refract flag to the shader
locMat=glGetUniformLocation(shaderProg, "refractFlag");
glUniform1i(locMat, refractFlag);
glActiveTexture(GL_TEXTURE3);
GLuint texCube = skybox.getTexHandle();
glBindTexture(GL_TEXTURE_CUBE_MAP, texCube);
GLuint samLoc = glGetUniformLocation(shaderProg, "texCube");
glUniform1i(samLoc, 3);
GLint ttt = 0;
glGetUniformiv(shaderProg, samLoc, &ttt);
// bind the buffers to the shaders
GLuint positionLoc = glGetAttribLocation(shaderProg, "vertex_position");
GLuint normalLoc = glGetAttribLocation(shaderProg, "vertex_normal");
glEnableVertexAttribArray(positionLoc);
glEnableVertexAttribArray(normalLoc);
glBindBuffer(GL_ARRAY_BUFFER, vertex_handle);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, triangle_handle);
// Tells OpenGL how to walk through the two VBOs
struct sphereVertex v;
int relAddress = (char *) v.pos - (char *) &v;
glVertexAttribPointer(positionLoc,4,GL_FLOAT, GL_FALSE, sizeof(struct sphereVertex),(char*) NULL+relAddress);
relAddress = (char *) v.normal - (char *) &v;
glVertexAttribPointer(normalLoc,4,GL_FLOAT, GL_FALSE, sizeof(struct sphereVertex),(char*) NULL+relAddress);
// draw the triangles
glDrawElements(GL_TRIANGLES, numTriangles*3, GL_UNSIGNED_INT, (char*) NULL+0);
// glUseProgram(0);
// glUseProgram(shaderProg);
// draw the second sphere
modelMat = Matrix4f::identity();
//modelMat = Matrix4f::translation(0,0,0);
modelMat = Matrix4f::scale(50,50,50) * Matrix4f::translation(2, 0, 0);
// ROATE THE OBJECT AROUND THE CAMERA VECTOR
// CAN ADD ROTATIONS AROUND THE PRIMARY AXIS
modelMat = modelMat * Matrix4f::rotateVector(cam.getLookAtVector(),angle,1);
// setting up the viewpoint transformation
viewMat = cam.getViewMatrix(NULL);
// setting up the projection transformation
projMat= cam.getProjectionMatrix(NULL);
//.........这里部分代码省略.........
示例2: displaySkybox
void SkyBox::displaySkybox(camera cam) {
int t = 1; // remove
glDisable(GL_DEPTH_TEST); // need depth test to correctly draw 3D objects
Matrix4f viewMat, projMat, modelMat, m;
// set local camera for the skybox
camera c1 = cam;
//c1.changeAbsPoition(0,0,0);
//c1.changeLookAtVector(1, 1, 1);
//glFrontFace(GL_CW);
//glCullFace(FRONT);
// set up the mode to wireframe
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
//set up the mode to fill
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// get the transformation matrix
modelMat = Matrix4f::translation(cam.getPosition());
// setting up the viewpoint transformation
viewMat = c1.getViewMatrix(NULL);
// setting up the projection transformation make sure that it is the same
// projection as the display function!!!
//projMat = Matrix4f::symmetricPerspectiveProjectionMatrix(30, 1, 0.1, 500);
projMat = cam.getProjectionMatrix(NULL);
// frustum matrix
//projMat = Matrix4f::frustumProjectionMatrix(-1,-1,1,1, 10,100);
// putting it all together
m = projMat * viewMat * modelMat;
// load the program to the shader
glUseProgram(shaderProg);
viewMat.m = (float *) viewMat.vm;
projMat.m = (float *) projMat.vm;
// transfer the matrix to the shader
GLuint locMat= 0;
locMat=glGetUniformLocation(shaderProg, "modelViewProjMat");
glUniformMatrix4fv(locMat,1,1,(float *)m.vm);
m = viewMat*modelMat;
locMat=glGetUniformLocation(shaderProg, "modelViewMat");
glUniformMatrix4fv(locMat,1,1,(float *) m.vm);
// set the time
GLuint tLoc = glGetUniformLocation(shaderProg, "t");
glUniform1i(tLoc, t);
// set the time
GLuint cameraPositiontLoc = glGetUniformLocation(shaderProg, "cameraPosition");
glEnableVertexAttribArray(cameraPositiontLoc);
Vector3f camPos = c1.getPosition();
glUniform3f(cameraPositiontLoc, camPos.x, camPos.y, camPos.z);
//glActiveTexture (GL_TEXTURE1);
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_CUBE_MAP, texHandle);
GLuint texLoc = glGetUniformLocation(shaderProg, "texCube");
glUniform1i(texLoc, 3);
GLint ttt = 0;
glGetUniformiv(shaderProg, texLoc, &ttt);
//glUniform1i(glGetUniformLocation(skyboxProg, "texCube"), texCube);
//glDisable(GL_CULL_FACE);
// bind the buffers to the shaders
GLuint positionLoc = glGetAttribLocation(shaderProg, "vertex_position");
//GLuint normalLoc = glGetAttribLocation(shaderProg, "vertex_normal");
//GLuint texLoc = glGetAttribLocation(shaderProg, "texCoord");
glEnableVertexAttribArray(positionLoc);
//glEnableVertexAttribArray(normalLoc);
//glEnableVertexAttribArray(texLoc);
glBindBuffer(GL_ARRAY_BUFFER, vboCube);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iboCube);
// Tells OpenGL how to walk through the two VBOs
glVertexAttribPointer(positionLoc,4,GL_FLOAT, GL_FALSE, 0,0);
// draw the triangles
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, (char*) NULL+0);
//glutSwapBuffers();
glEnable(GL_DEPTH_TEST); // need depth test to correctly draw 3D objects
return;
}