the camera rotates with the thing yo wt
This commit is contained in:
@@ -16,7 +16,7 @@ public:
|
||||
|
||||
glm::mat4 getViewMatrix();
|
||||
glm::mat4 getProjectionMatrix();
|
||||
glm::mat4 getFrustrumMatrix();
|
||||
glm::mat4 getCameraLook();
|
||||
|
||||
void setRasterViewport(glm::vec2 viewport);
|
||||
|
||||
@@ -47,6 +47,7 @@ private:
|
||||
glm::vec2 mRayViewport = { 300.0f, 300.0f };
|
||||
glm::mat4 mViewMatrix = {};
|
||||
glm::mat4 mProjMatrix = {};
|
||||
glm::mat4 mCameraLook = {};
|
||||
bool mDidUpdate;
|
||||
|
||||
};
|
||||
|
||||
@@ -40,7 +40,7 @@ RayField RaySource::getInitialRays(bool MSAA)
|
||||
const float aspect = mReferenceCamera->getRayViewport().x / mReferenceCamera->getRayViewport().y;
|
||||
float scale = tan(mReferenceCamera->FOV / 2.0f * helpers::PI / 180.0f);
|
||||
|
||||
glm::mat4 cameraToWorld = mReferenceCamera->getViewMatrix();
|
||||
glm::mat4 cameraToWorld = mReferenceCamera->getCameraLook();
|
||||
glm::vec3 origin = mReferenceCamera->Position;
|
||||
|
||||
for (int x = 0; x < mReferenceCamera->getRayViewport().x; x++)
|
||||
@@ -51,7 +51,7 @@ RayField RaySource::getInitialRays(bool MSAA)
|
||||
|
||||
Ray* ray = new Ray;
|
||||
ray->Origin = origin;
|
||||
ray->Direction = glm::normalize(glm::vec4(Px, Py, -1.0f, 1.0f) * cameraToWorld);
|
||||
ray->Direction = glm::normalize((glm::vec4(Px, Py, -1.0f, 1.0f) * cameraToWorld));
|
||||
|
||||
field.push_back(ray);
|
||||
}
|
||||
|
||||
@@ -80,4 +80,9 @@ void RayRenderer::draw()
|
||||
glBindTexture(GL_TEXTURE_2D, mRenderTargetTexture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mRenderTargetSize.x, mRenderTargetSize.y, 0, GL_RGBA, GL_FLOAT, mTarget);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
for (auto* ray : startRays)
|
||||
{
|
||||
delete ray;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,17 +36,16 @@ Camera::Camera(int w, int h)
|
||||
|
||||
void Camera::update()
|
||||
{
|
||||
// roll can be removed
|
||||
glm::mat4 matRoll = glm::mat4(1.0f); //identity matrix
|
||||
glm::mat4 matPitch = glm::mat4(1.0f);//identity matrix
|
||||
glm::mat4 matYaw = glm::mat4(1.0f); //identity matrix
|
||||
glm::mat4 matRoll = glm::mat4(1.0f);
|
||||
glm::mat4 matPitch = glm::mat4(1.0f);
|
||||
glm::mat4 matYaw = glm::mat4(1.0f);
|
||||
|
||||
// roll, pitch and yaw
|
||||
matRoll = glm::rotate(matRoll, Roll, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
matPitch = glm::rotate(matPitch, Pitch, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
matYaw = glm::rotate(matYaw, Yaw, glm::vec3( 0.0f, 1.0f, 0.0f));
|
||||
|
||||
glm::mat4 rotate = matRoll * matPitch * matYaw;
|
||||
mCameraLook = rotate;
|
||||
|
||||
glm::mat4 translate = glm::mat4(1.0f);
|
||||
translate = glm::translate(translate, -Position);
|
||||
@@ -84,6 +83,11 @@ glm::mat4 Camera::getProjectionMatrix()
|
||||
return mProjMatrix;
|
||||
}
|
||||
|
||||
glm::mat4 Camera::getCameraLook()
|
||||
{
|
||||
return mCameraLook;
|
||||
}
|
||||
|
||||
void Camera::setRasterViewport(glm::vec2 viewport)
|
||||
{
|
||||
mViewport = viewport;
|
||||
|
||||
Reference in New Issue
Block a user