Added a target offset for camera arm #264

Merged
maverickdgg merged 1 commits from SP3-141-Camera-System into main 2022-11-23 18:29:06 +08:00
5 changed files with 35 additions and 3 deletions
Showing only changes of commit 49b475442f - Show all commits

View File

@ -8,6 +8,7 @@ namespace SHADE
SHCameraArmComponent::SHCameraArmComponent()
:pitch(0.0f), yaw(0.0f), armLength(1.0f),offset(), dirty(true), lookAtCameraOrigin(true)
, targetOffset(0.0f)
{
}
@ -33,6 +34,11 @@ namespace SHADE
return armLength;
}
SHVec3 SHCameraArmComponent::GetTargetOffset() const noexcept
{
return targetOffset;
}
void SHCameraArmComponent::SetPitch(float pitch) noexcept
{
this->pitch = pitch;
@ -51,6 +57,11 @@ namespace SHADE
dirty = true;
}
void SHCameraArmComponent::SetTargetOffset(SHVec3 offset) noexcept
{
this->targetOffset = offset;
}
}//namespace SHADE
@ -63,6 +74,8 @@ RTTR_REGISTRATION
.property("Arm Pitch", &SHCameraArmComponent::GetPitch, &SHCameraArmComponent::SetPitch)
.property("Arm Yaw", &SHCameraArmComponent::GetYaw, &SHCameraArmComponent::SetYaw)
.property("Arm Length", &SHCameraArmComponent::GetArmLength, &SHCameraArmComponent::SetArmLength)
.property("Look At Camera Origin", &SHCameraArmComponent::lookAtCameraOrigin);
.property("Look At Camera Origin", &SHCameraArmComponent::lookAtCameraOrigin)
.property("Target Offset", &SHCameraArmComponent::GetTargetOffset, &SHCameraArmComponent::SetTargetOffset)
;
}

View File

@ -17,7 +17,7 @@ namespace SHADE
bool dirty;
SHVec3 offset;
SHVec3 targetOffset;
public:
friend class SHCameraSystem;
SHCameraArmComponent();
@ -30,11 +30,13 @@ namespace SHADE
float GetPitch() const noexcept;
float GetYaw() const noexcept;
float GetArmLength() const noexcept;
SHVec3 GetTargetOffset() const noexcept;
//Setters
void SetPitch(float pitch) noexcept;
void SetYaw(float yaw) noexcept;
void SetArmLength(float length) noexcept;
void SetTargetOffset(SHVec3 offset)noexcept;
protected:

View File

@ -182,7 +182,7 @@ namespace SHADE
{
camera.offset = arm->GetOffset();
if (arm->lookAtCameraOrigin)
CameraLookAt(camera, camera.position);
CameraLookAt(camera, camera.position + arm->GetTargetOffset());
}
}

View File

@ -48,4 +48,15 @@ namespace SHADE
{
GetNativeComponent()->lookAtCameraOrigin = val;
}
Vector3 CameraArm::TargetOffset::get()
{
return Convert::ToCLI(GetNativeComponent()->GetTargetOffset());
}
void CameraArm::TargetOffset::set(Vector3 val)
{
GetNativeComponent()->SetTargetOffset(Convert::ToNative(val));
}
}

View File

@ -36,5 +36,11 @@ namespace SHADE
void set(bool val);
}
property Vector3 TargetOffset
{
Vector3 get();
void set(Vector3 val);
}
};
}