本文整理汇总了C++中perspective函数的典型用法代码示例。如果您正苦于以下问题:C++ perspective函数的具体用法?C++ perspective怎么用?C++ perspective使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了perspective函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: perspective
glm::mat4 Frustum::GetPerspectiveProjection() const
{
glm::mat4 perspective(0);
float aspect = height / width;
float fovScale = 1.0f / std::tan(fovY * 0.5f);
perspective[0][0] = fovScale * aspect;
perspective[1][1] = fovScale;
perspective[2][2] = (near_z + far_z) / (near_z - far_z);
perspective[3][2] = 2 * near_z * far_z / (near_z - far_z);
perspective[2][3] = -1.0f;
return perspective;
}
示例2: updateProjMatrix
void Renderer::updateProjMatrix(float width, float height)
{
this->wheight=height;
this->wwidth=width;
float nearClip = 0.5f;
float farClip = 1000.0f;
float fov_deg = 45.0f;
float aspect = (float)width/(float)height;
this->projMatrix=perspective(fov_deg, aspect,nearClip,farClip);
this->modelShader.use();
this->modelShader.setUniform("projectionMatrix",this->projMatrix);
glUseProgram(0);
}
示例3: reshape
//------------------------------------------------------------------------------
void reshape(int w, int h)
{
g_winSz[0] = w;
g_winSz[1] = h;
perspective(g_transfBlock1.m4_Proj, 45.0f, (float)g_winSz[0] / (float)g_winSz[1], 0.01f, 10.0f);
//
// Let's validate again the base of resource management to make sure things keep consistent
//
int W = g_winSz[0];
int H = g_winSz[1];
glViewport(0, 0, W, H);
perspective(g_transfBlock1.m4_Proj, 45.0f, (float)g_winSz[0] / (float)g_winSz[1], 0.01f, 10.0f);
bool failed = nvFX::getResourceRepositorySingleton()->validate(0,0,W,H,1,0,NULL ) ? false : true;
if(failed)
assert(!"Oops");
failed = nvFX::getFrameBufferObjectsRepositorySingleton()->validate(0,0,W,H,1,0,NULL ) ? false : true;
if(failed)
assert(!"Oops");
}
示例4: glClearColor
void CubMapStudyR::renderReflect()
{
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
this->camera->setDeltaTime(glfwGetTime());
this->camera->DoMovement();
mat4 model(1.0f);
mat4 view(1.0f);
mat4 projection(1.0f);
view = this->camera->GetLookAt();
projection = perspective(radians(Camera::aspect), 800.0f / 600.0f, 0.1f, 1000.0f);
//绘制物体
model = translate(model, vec3(0.0f, 0.0f, 0.7f));
model = scale(model, vec3(0.3f, 0.3f, 0.3f));
cubeShader->UseProgram();
glActiveTexture(GL_TEXTURE0);
//glBindTexture(GL_TEXTURE_2D, this->cubeTexutrueID);
glBindTexture(GL_TEXTURE_CUBE_MAP, this->skyBoxTextureID);
glUniformMatrix4fv(glGetUniformLocation(cubeShader->getProgram(), "view"), 1, GL_FALSE, value_ptr(view));
glUniformMatrix4fv(glGetUniformLocation(cubeShader->getProgram(), "projection"), 1, GL_FALSE, value_ptr(projection));
glUniformMatrix4fv(glGetUniformLocation(cubeShader->getProgram(), "model"), 1, GL_FALSE, value_ptr(model));
glUniform3fv(glGetUniformLocation(cubeShader->getProgram(), "cameraPos"),1, value_ptr(Camera::cameraPos));
glUniform1i(glGetUniformLocation(cubeShader->getProgram(), "skybox"), 0);
//glUniform1i(glGetUniformLocation(cubeShader->getProgram(), "Texture1"), 0);
glBindVertexArray(this->cubeVAO);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArray(0);
glBindTexture(GL_TEXTURE_2D, 0);
//绘制天空盒子
glDepthFunc(GL_LEQUAL);
skyboxShader->UseProgram();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_CUBE_MAP, this->skyBoxTextureID);
glUniformMatrix4fv(glGetUniformLocation(skyboxShader->getProgram(), "view"), 1, GL_FALSE, value_ptr(mat4(mat3(view))));
glUniformMatrix4fv(glGetUniformLocation(skyboxShader->getProgram(), "projection"), 1, GL_FALSE, value_ptr(projection));
glUniform1i(glGetUniformLocation(skyboxShader->getProgram(), "cubemap"), 0);
glBindVertexArray(this->skyBoxVAO);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArray(0);
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
glDepthFunc(GL_LESS);
}
示例5: update
void update() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) {
exit(0);
}
}
glFlush();
SDL_GL_SwapBuffers();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
perspective();
}
示例6: perspective
void SceneManagerTriangle::Update()
{
float aspect = (float)m_width / (float)m_height;
mat4 proj_matrix = perspective(60.0f, aspect, 0.1f, 1000.0f);
mat4 view_matrix = lookat(vec3(0.0f, 0.0f, 3.0f),
vec3(0.0f, 0.0f, 0.0f),
vec3(0.0f, 1.0f, 0.0f));
float factor = 0;// GetTickCount() / 50 % 360;
mat4 mv_matrix = view_matrix * translate(m_x_offset, m_y_offset, m_z_offset) * scale(1.0f) * rotate(factor, vec3(0.0f, 1.0f, 0.0f));
SetUniform(0, mv_matrix);
SetUniform(1, proj_matrix);
Soft3dPipeline::Instance()->Clear(0xffffff);
}
示例7: mutexScopedLock
void Renderinstance::createRenderer(const UsedRenderer usedrenderer,const int windowwidth,const int windowheight)
{
mutexScopedLock();
switch (usedrenderer) {
case UsedRenderer_Opengl:
m_pRenderer=new opengldrv::OGLRenderer(windowwidth,windowheight);
default:break;
}
if (m_pScene) m_pScene->renderer(*m_pRenderer);
m_pRenderer->resize(0,0,windowwidth,windowheight);
perspective(windowwidth,windowheight);
}
示例8: resizeWindow
/* function to reset our viewport after a window resize */
int resizeWindow( int width, int height )
{
/* Protect against a divide by zero */
if ( height == 0 )
height = 1;
current_height = height;
current_width = width;
/* Setup our viewport. */
glViewport( 0, 0, ( GLsizei )width, ( GLsizei )height );
perspective();
return TRUE;
}
示例9: updateProjMatrix
void Terrain::updateProjMatrix(float width, float height)
{
float nearClip = 0.5f;
float farClip = 1000.0f;
float fov_deg = 45.0f;
float aspect = (float)width/(float)height;
this->projMatrix=perspective(fov_deg, aspect,nearClip,farClip);
this->TerrainShader.use();
this->TerrainShader.setUniform("projectionMatrix",this->projMatrix);
this->surfaceTexShader.use();
this->surfaceTexShader.setUniform("projectionMatrix",this->projMatrix);
glUseProgram(0);
}
示例10: update
void update()
{
lastTicks=currentTicks;
currentTicks=SDL_GetTicks();
elapsedTime = (currentTicks - lastTicks) / 1000.0f;
totalTime+=elapsedTime;
projMatrix = perspective(45.0f, 640.0f / 480.0f, 0.1f, 100.0f);
viewMatrix = lookAt(cameraPosition, vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f));
for (auto iter = gameObjects.begin(); iter != gameObjects.end(); iter++)
{
(*iter)->update();
}
}
示例11: lua_gettop
int Mat4::lua_Perspective( lua_State* lua )
{
int result = 0;
int nargs = lua_gettop( lua );
if( nargs >= 4 )
{
float fov = static_cast<float>( lua_tonumber( lua, 1 ) );
float aspect = static_cast<float>( lua_tonumber( lua, 2 ) );
float nearplane = static_cast<float>( lua_tonumber( lua, 3 ) );
float farplane = static_cast<float>( lua_tonumber( lua, 4 ) );
result = lua_Write( lua, perspective( fov, aspect, nearplane, farplane ) );
}
return result;
}
示例12: functor
void GraphicsManager::setPerspective(float viewAngle, float clipNear, float clipFar) {
// Force calling it from the main thread
if (!Common::isMainThread()) {
Events::MainThreadFunctor<void> functor(boost::bind(&GraphicsManager::setPerspective, this, viewAngle, clipNear, clipFar));
return RequestMan.callInMainThread(functor);
}
perspective(viewAngle, ((float) _width) / ((float) _height), clipNear, clipFar);
_projectType = kProjectTypePerspective;
_viewAngle = viewAngle;
_clipNear = clipNear;
_clipFar = clipFar;
}
示例13: perspective
void RaycastCamera::init(u32 screenWidth, u32 screenHeight, f32 fov, f32 nearZ, f32 farZ)
{
mScreenWidth = (f32)screenWidth;
mScreenHeight = (f32)screenHeight;
mFov = fov;
mNearZ = nearZ;
mFarZ = farZ;
mAspectRatio = mScreenWidth / mScreenHeight;
mProjection = perspective(radians(60.0f),
mAspectRatio,
mNearZ,
mFarZ);
mProjectionInv = ~mProjection;
move(vec3(0.0f, 0.0f, 10.0f), quat(0, vec3(0.0f, 0.0f, -1.0f)));
vec3 rayBottomLeft = normalize(vec3(mProjectionInv * vec4(-1.0f, -1.0f, 0.0f, 1.0f)));
vec3 rayBottomRight = vec3(-rayBottomLeft.x, rayBottomLeft.y, rayBottomLeft.z);
vec3 rayTopLeft = vec3( rayBottomLeft.x, -rayBottomLeft.y, rayBottomLeft.z);
vec3 rayTopRight = vec3(-rayBottomLeft.x, -rayBottomLeft.y, rayBottomLeft.z);
f32 cosAngle = dot(rayBottomLeft, normalize(vec3(0.0f, 0.0f, mNearZ)));
f32 nearLen = -mNearZ / cosAngle;
f32 farLen = -mFarZ / cosAngle;
// calculate each corner
vec3 corBLN = rayBottomLeft * nearLen;
vec3 corBLF = rayBottomLeft * farLen;
mCornersInit[kCOR_BottomLeft].nearPos = corBLN;
mCornersInit[kCOR_BottomLeft].farPos = corBLF;
mCornersInit[kCOR_BottomRight].nearPos = vec3(-corBLN.x, corBLN.y, corBLN.z);
mCornersInit[kCOR_BottomRight].farPos = vec3(-corBLF.x, corBLF.y, corBLF.z);
mCornersInit[kCOR_TopLeft].nearPos = vec3(corBLN.x, -corBLN.y, corBLN.z);
mCornersInit[kCOR_TopLeft].farPos = vec3(corBLF.x, -corBLF.y, corBLF.z);
mCornersInit[kCOR_TopRight].nearPos = vec3(-corBLN.x, -corBLN.y, corBLN.z);
mCornersInit[kCOR_TopRight].farPos = vec3(-corBLF.x, -corBLF.y, corBLF.z);
reset();
calcPlanes();
}
示例14: redraw
void redraw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color, and reset the z-buffer
glEnable(GL_DEPTH_TEST); // enable z-buffer test
mat4x4 P = perspective(-1,1,-1,1,-1,-10);
mat4x4 M = translation(0,0,-3)*rotation_z(angle)*rotation_y(2*angle);
// Bind our vertices, texture, and GLSL program
glBindBuffer(GL_ARRAY_BUFFER,mesh_vbo);
glBindTexture(GL_TEXTURE_2D,texid);
glUseProgram(program);
// Initialize the GLSL uniform variables
glUniformMatrix4fv(glGetUniformLocation(program,"P"),1,GL_TRUE,P.ptr());
glUniformMatrix4fv(glGetUniformLocation(program,"M"),1,GL_TRUE,M.ptr());
// Since our fragment shader also has a uniform (a 'sampler2D' texture index name 'texmap'),
// we should tell our fragment shader that 'texmap' was bound to "texture unit 0" (the default)
glUniform1i(glGetUniformLocation(program,"texmap"),0);
int ploc = glGetAttribLocation(program,"p"); // index of position attribute in GLSL program
int cloc = glGetAttribLocation(program,"c"); // index of colour attribute
int tloc = glGetAttribLocation(program,"t"); // index of texcoord attribute
// Each vertex contains a position, colour, and texcoord, so we must
// tell OpenGL exactly how the memory of our vertex buffer is layed out.
// sizeof(vertex) = 16 + 16 + 8 = 40 bytes
// position: "4 floats, 40 bytes apart, with offset 0 bytes"
// colour: "4 floats, 40 bytes apart, with offset 16 bytes"
// colour: "2 floats, 40 bytes apart, with offset 32 bytes"
glVertexAttribPointer(ploc,4,GL_FLOAT,GL_FALSE,sizeof(vertex),OFFSET(vertex,p));
glVertexAttribPointer(cloc,4,GL_FLOAT,GL_FALSE,sizeof(vertex),OFFSET(vertex,c));
glVertexAttribPointer(tloc,2,GL_FLOAT,GL_FALSE,sizeof(vertex),OFFSET(vertex,t));
glEnableVertexAttribArray(ploc); // don't forget to enable each one!
glEnableVertexAttribArray(cloc);
glEnableVertexAttribArray(tloc);
// RASTERIZE!
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
// OPTIONAL
glUseProgram(0);
glBindBuffer(GL_ARRAY_BUFFER,0);
glFlush();
}
示例15: display
void display()
{
// WCS-to-VCS
mat4 WCS_to_VCS
= lookat( eyePosition, worldCentre, vec3(0,1,0) );
// WCS-to-CCS
float n = (eyePosition - worldCentre).length() - worldRadius;
float f = (eyePosition - worldCentre).length() + worldRadius;
mat4 WCS_to_CCS
= perspective( fovy, windowWidth / (float) windowHeight, n, f )
* WCS_to_VCS;
// Light direction is in the WCS, but rotates
vec3 lightDir(1,1.5,1);
lightDir = lightDir.normalize();
vec4 rotatedLightDir = rotate( theta, vec3(0,1,0) ) * vec4( lightDir, 0 );
vec3 rotatedLightDir3 = vec3( rotatedLightDir.x, rotatedLightDir.y, rotatedLightDir.z );
// Draw the objects
renderer->render( objs, WCS_to_VCS, WCS_to_CCS, rotatedLightDir3, eyePosition );
// Draw the world axes
if (showAxes && !renderer->debugOn()) {
mat4 axesTransform = WCS_to_CCS * scale( 10, 10, 10 );
axes->draw( axesTransform, rotatedLightDir3 );
}
// Output status message
char buffer[1000];
renderer->makeStatusMessage( buffer );
glColor3f(0.3,0.3,1.0);
printString( buffer, 10, 10, windowWidth, windowHeight );
// Done
glutSwapBuffers();
}