Skip to content

Commit 4f90668

Browse files
committed
More updates in camera, fixing last issues
1 parent 6367858 commit 4f90668

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

SparkEngine/ModuleCamera3D.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ update_status ModuleCamera3D::Update(float dt)
8585
//if(App->input->GetKey(SDL_SCANCODE_R) == KEY_REPEAT) newPos.y += speed;
8686
if (App->input->GetKey(SDL_SCANCODE_F) == KEY_DOWN)
8787
{
88-
if (GOSelectedAsReference()) {
88+
if (!isSelectedGOAsReference()) {
89+
SelectedGOAsReference();
8990
LookAt(Reference);
90-
focusing = true;
91-
camera_inputs_active = false;
9291
}
92+
focusing = true;
93+
camera_inputs_active = false;
9394
}
9495

9596
if (focusing) Focus();
@@ -103,7 +104,7 @@ update_status ModuleCamera3D::Update(float dt)
103104
// Mouse motion ----------------
104105
if (App->input->GetKey(SDL_SCANCODE_LALT) == KEY_REPEAT && App->input->GetMouseButton(SDL_BUTTON_LEFT) == KEY_REPEAT)
105106
{
106-
GOSelectedAsReference();//We set the select game object as reference so we now rotate around it.
107+
SelectedGOAsReference();//We set the select game object as reference so we now rotate around it.
107108
RotateAroundReference();
108109
}
109110

@@ -166,12 +167,10 @@ float* ModuleCamera3D::GetViewMatrix()
166167
return &ViewMatrix;
167168
}
168169

169-
bool ModuleCamera3D::GOSelectedAsReference()
170+
bool ModuleCamera3D::isSelectedGOAsReference()
170171
{
171-
if (App->scene->selected_gameobject) {
172-
Reference = { App->scene->selected_gameobject->transform->position.x, App->scene->selected_gameobject->transform->position.y, App->scene->selected_gameobject->transform->position.z };
173-
return true;
174-
}
172+
float3 comparator = { Reference.x, Reference.y, Reference.z };
173+
if (App->scene->selected_gameobject->transform->position.Equals(comparator)) return true;
175174
else return false;
176175
}
177176

@@ -196,7 +195,7 @@ void ModuleCamera3D::CameraInputs()
196195

197196
void ModuleCamera3D::Focus()//If theres a selected game object the camera looks at the target and moves to it. It moves slower as the camera gets closer to the target
198197
{
199-
GOSelectedAsReference();
198+
SelectedGOAsReference();
200199
float3 end_position = { Reference.x, Reference.y, Reference.z };
201200
float3 position = { Position.x, Position.y, Position.z };
202201
float distance = position.Distance(end_position);
@@ -281,4 +280,11 @@ void ModuleCamera3D::CalculateViewMatrix()
281280
{
282281
ViewMatrix = mat4x4(X.x, Y.x, Z.x, 0.0f, X.y, Y.y, Z.y, 0.0f, X.z, Y.z, Z.z, 0.0f, -dot(X, Position), -dot(Y, Position), -dot(Z, Position), 1.0f);
283282
ViewMatrixInverse = inverse(ViewMatrix);
284-
}
283+
}
284+
285+
void ModuleCamera3D::SelectedGOAsReference()
286+
{
287+
if (App->scene->selected_gameobject) {
288+
Reference = { App->scene->selected_gameobject->transform->position.x, App->scene->selected_gameobject->transform->position.y, App->scene->selected_gameobject->transform->position.z };
289+
}
290+
}

SparkEngine/ModuleCamera3D.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class ModuleCamera3D : public Module
3434
private:
3535

3636
void CalculateViewMatrix();
37-
bool GOSelectedAsReference();
37+
void SelectedGOAsReference();
38+
bool isSelectedGOAsReference();
3839
void CameraInputs();
3940
void Focus();
4041
void RotateAroundReference();

0 commit comments

Comments
 (0)