Browse Source

正交投影视锥体

master
blobt 4 years ago
parent
commit
fe39c57984
  1. BIN
      .vs/shader2/v14/.suo
  2. 26
      frustum.cpp
  3. 1
      frustum.h
  4. 7
      main.cpp

BIN
.vs/shader2/v14/.suo

26
frustum.cpp

@ -54,6 +54,32 @@ void Frustum::InitPerspective(float fov, float aspect, float zNear, float zFar)
}
void Frustum::InitOrtho(float left, float right, float bottom, float top, float zNear, float zFar)
{
float vertexes[24] = {
left,bottom,-zNear,
right,bottom,-zNear,
right,top,-zNear,
left,top,-zNear,
left,bottom,-zFar,
right,bottom,-zFar,
right,top,-zFar,
left,top,-zFar,
};
mVBO = CreateBufferObject(GL_ARRAY_BUFFER, sizeof(float) * 24, GL_STATIC_DRAW, vertexes);
unsigned int indexes[] = {
0,1,1,2,2,3,3,0, //½ü¼ô²ÃÃæ
4,5,5,6,6,7,7,4, //Ô¶¼ô²ÃÃæ
0,4,3,7,2,6,1,5
};
mIBO = CreateBufferObject(GL_ELEMENT_ARRAY_BUFFER, sizeof(int) * 24, GL_STATIC_DRAW, indexes);
}
void Frustum::Draw(float* M, float* V, float* P)
{
glUseProgram(mProgram);

1
frustum.h

@ -10,5 +10,6 @@ public:
Frustum();
void Init();
void InitPerspective(float fov, float aspect, float zNear, float zFar);
void InitOrtho(float left, float right, float bottom, float top, float zNear, float zFar);
void Draw(float* M, float* V, float* P);
};

7
main.cpp

@ -133,6 +133,8 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
glEnable(GL_DEPTH_TEST);
glEnable(GL_POINT_SPRITE);
glEnable(GL_PROGRAM_POINT_SIZE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glViewport(0,0, windowWidth, windowHeight);
//创建一个单位矩阵和一个投影矩阵,后面用来传递到shader
@ -143,13 +145,14 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
0,0,0,1
};
glm::mat4 model = glm::translate(-1.0f, 0.0f, -3.0f)*glm::rotate(-20.0f, 0.0f, 1.0f, 0.0f);
glm::mat4 model = glm::translate(0.0f, 0.0f, -3.0f)*glm::rotate(-20.0f, 0.0f, 1.0f, 0.0f);
glm::mat4 projection = glm::perspective(45.0f, (float)windowWidth / (float)windowHeight, 0.1f, 1000.0f);
glm::mat4 normalMatrix = glm::inverseTranspose(model);
Frustum frustum;
frustum.Init();
frustum.InitPerspective(45.0f, (float)windowWidth / (float)windowHeight, 0.1f, 4.0f);
//frustum.InitPerspective(45.0f, (float)windowWidth / (float)windowHeight, 0.1f, 4.0f);
frustum.InitOrtho(-0.5f, 0.5f,-0.5, 0.5,0.1f,4.0f);
/*显示窗口*/
ShowWindow(hwnd, SW_SHOW);

Loading…
Cancel
Save