Camera rotation
This commit is contained in:
		@@ -100,6 +100,9 @@ int main() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    Matrix view(1.0f);
 | 
					    Matrix view(1.0f);
 | 
				
			||||||
    Camera *camera = Camera::GetCurrentCamera();
 | 
					    Camera *camera = Camera::GetCurrentCamera();
 | 
				
			||||||
 | 
					    view = glm::rotate(view, -camera->transform.rotation.x, Vector3(1.0f, 0.0f, 0.0f));
 | 
				
			||||||
 | 
					    view = glm::rotate(view, -camera->transform.rotation.y, Vector3(0.0f, 1.0f, 0.0f));
 | 
				
			||||||
 | 
					    view = glm::rotate(view, -camera->transform.rotation.z, Vector3(0.0f, 0.0f, 1.0f));
 | 
				
			||||||
    view = glm::translate(view, -camera->transform.position);
 | 
					    view = glm::translate(view, -camera->transform.position);
 | 
				
			||||||
    shader.UpdateView(view);
 | 
					    shader.UpdateView(view);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -112,10 +115,10 @@ int main() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    for (Mesh *mesh : meshes) {
 | 
					    for (Mesh *mesh : meshes) {
 | 
				
			||||||
      Matrix model(1.0f);
 | 
					      Matrix model(1.0f);
 | 
				
			||||||
      model = glm::translate(model, mesh->transform.position);
 | 
					 | 
				
			||||||
      model = glm::rotate(model, mesh->transform.rotation.x, Vector3(1.0f, 0.0f, 0.0f));
 | 
					      model = glm::rotate(model, mesh->transform.rotation.x, Vector3(1.0f, 0.0f, 0.0f));
 | 
				
			||||||
      model = glm::rotate(model, mesh->transform.rotation.y, Vector3(0.0f, 1.0f, 0.0f));
 | 
					      model = glm::rotate(model, mesh->transform.rotation.y, Vector3(0.0f, 1.0f, 0.0f));
 | 
				
			||||||
      model = glm::rotate(model, mesh->transform.rotation.z, Vector3(0.0f, 0.0f, 1.0f));
 | 
					      model = glm::rotate(model, mesh->transform.rotation.z, Vector3(0.0f, 0.0f, 1.0f));
 | 
				
			||||||
 | 
					      model = glm::translate(model, mesh->transform.position);
 | 
				
			||||||
      shader.UpdateModel(model);
 | 
					      shader.UpdateModel(model);
 | 
				
			||||||
      mesh->Draw();
 | 
					      mesh->Draw();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										13
									
								
								main.lua
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								main.lua
									
									
									
									
									
								
							@@ -5,12 +5,15 @@ local LEFT = 263
 | 
				
			|||||||
local RIGHT = 262
 | 
					local RIGHT = 262
 | 
				
			||||||
local UP = 265
 | 
					local UP = 265
 | 
				
			||||||
local DOWN = 264
 | 
					local DOWN = 264
 | 
				
			||||||
 | 
					local Q = 81
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local vx = 0.0
 | 
					local vx = 0.0
 | 
				
			||||||
local vz = 0.0
 | 
					local vz = 0.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local ballvy = -1.0
 | 
					local ballvy = -1.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local cam_rot_x = 0.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function init()
 | 
					function init()
 | 
				
			||||||
   camera = couch.Camera()
 | 
					   camera = couch.Camera()
 | 
				
			||||||
   camera:MakeCurrent()
 | 
					   camera:MakeCurrent()
 | 
				
			||||||
@@ -27,6 +30,7 @@ end
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
function update(delta)
 | 
					function update(delta)
 | 
				
			||||||
   camera.transform:Translate(vx * delta, 0.0, vz * delta)
 | 
					   camera.transform:Translate(vx * delta, 0.0, vz * delta)
 | 
				
			||||||
 | 
					   camera.transform.rotation.y = camera.transform.rotation.y + cam_rot_x * delta
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   local loc = ball1.transform.position
 | 
					   local loc = ball1.transform.position
 | 
				
			||||||
   if loc.y > 4.0 then
 | 
					   if loc.y > 4.0 then
 | 
				
			||||||
@@ -37,6 +41,7 @@ function update(delta)
 | 
				
			|||||||
   ball1.transform.position.y = ball1.transform.position.y + ballvy * delta
 | 
					   ball1.transform.position.y = ball1.transform.position.y + ballvy * delta
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   ball.transform.rotation.z = ball.transform.rotation.z + 1.0 * delta;
 | 
					   ball.transform.rotation.z = ball.transform.rotation.z + 1.0 * delta;
 | 
				
			||||||
 | 
					   ball.transform.rotation.y = ball.transform.rotation.y + 1.0 * delta;
 | 
				
			||||||
   ball.transform.rotation.x = ball.transform.rotation.x + 1.0 * delta;
 | 
					   ball.transform.rotation.x = ball.transform.rotation.x + 1.0 * delta;
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -56,4 +61,12 @@ function onkey(key, code, action, mod)
 | 
				
			|||||||
   elseif (key == DOWN or key == UP) and action == 0 then
 | 
					   elseif (key == DOWN or key == UP) and action == 0 then
 | 
				
			||||||
      vz = 0.0
 | 
					      vz = 0.0
 | 
				
			||||||
   end
 | 
					   end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   if key == Q then
 | 
				
			||||||
 | 
					      if action == 1 then
 | 
				
			||||||
 | 
						 cam_rot_x = 1.0
 | 
				
			||||||
 | 
					      else
 | 
				
			||||||
 | 
						 cam_rot_x = 0.0
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					   end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user