1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | model = scale(model, hero->size);
v3 up = v3(0.0f,1.0f,0.0f);
v3 right = normalize(cross(gameState->cameraFront,up));
mat4 M =
{
{
{right.x,up.x,gameState->cameraFront.x,0.0f},
{right.y,up.y,gameState->cameraFront.y,0.0f},
{right.z,up.z,gameState->cameraFront.z,0.0f},
{0.0f,0.0f,0.0f,1.0f}
}
};
model = M * model;
model = translate(model, hero->p);
passUniformMatrix(opengl.shaderProgram,model,false,"model");
glDrawArrays(GL_TRIANGLES, 0, 36);
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | void
cameraTransform(Camera *camera, Input *input, Game_state *gameState)
{
beginUseProgram(opengl.shaderProgram);
if(camera->firstMouseMove)
{
camera->lastMouseX = input->mouseX;
camera->lastMouseY = input->mouseY;
camera->firstMouseMove = false;
}
s32 dtMouseX = input->mouseX - camera->lastMouseX;
s32 dtMouseY = camera->lastMouseY - input->mouseY;
dtMouseX *= camera->mouseSensitivity;
dtMouseY *= camera->mouseSensitivity;
camera->yaw += dtMouseX;
camera->pitch += dtMouseY;
if(camera->pitch > 89.0f)
{
camera->pitch = 89.0f;
}
if(camera->pitch < -89.0f)
{
camera->pitch = -89.0f;
}
gameState->cameraFront.x = cos(ToRadians(camera->yaw)) * cos(ToRadians(camera->pitch));
gameState->cameraFront.y = sin(ToRadians(camera->pitch));
gameState->cameraFront.z = sin(ToRadians(camera->yaw)) * cos(ToRadians(camera->pitch));
gameState->cameraFront = normalize(gameState->cameraFront);
mat4 viewMatrix = indentity();
viewMatrix = lookAt(gameState->cameraP,
gameState->cameraP + gameState->cameraFront,
v3(0.0f,1.0f,0.0f));
passUniformMatrix(opengl.shaderProgram,viewMatrix,false,"view");
camera->lastMouseX = WINDOW_WIDTH / 2;
camera->lastMouseY = WINDOW_HEIGHT/ 2;
endUseProgram(opengl.shaderProgram);
}
|
1 2 3 4 5 6 | Matrix4 result = {{
xAxis.x, yAxis.x, zAxis.x, 0,
xAxis.y, yAxis.y, zAxis.y, 0,
xAxis.z, yAxis.z, zAxis.z, 0,
0, 0, 0, 1
}};
|
1 2 3 4 5 6 | Matrix4 result = {{
xAxis.x, xAxis.y, xAxis.z, 0,
yAxis.x, yAxis.y, yAxis.z, 0,
zAxis.x, zAxis.y, zAxis.z, 0,
0, 0, 0, 1
}};
|
1 | P*V*M*Vertex |
1 | M*V*P*Vertex |