Patch - Sun Camera - V10.5.2
This commit is contained in:
25
enginecustom/src/inc/shader/master_shader.h
Normal file
25
enginecustom/src/inc/shader/master_shader.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include <d3d11.h>
|
||||
#include <DirectXMath.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
class master_shader
|
||||
{
|
||||
public :
|
||||
|
||||
master_shader();
|
||||
master_shader(const master_shader& other) = delete;
|
||||
virtual ~master_shader();
|
||||
|
||||
virtual bool initialize(ID3D11Device* device, HWND hwnd) = 0;
|
||||
|
||||
|
||||
protected:
|
||||
wchar_t vs_filename_[128], ps_filename_[128];
|
||||
|
||||
wchar_t const* vs_name_ = L"";
|
||||
wchar_t const* ps_name_ = L"";
|
||||
|
||||
|
||||
};
|
@@ -231,6 +231,8 @@ private :
|
||||
display_plane_class* display_plane_;
|
||||
int screen_width_, screen_height_;
|
||||
camera_class* camera_;
|
||||
camera_class* sun_camera_;
|
||||
camera_class* active_camera_;
|
||||
position_class* position_;
|
||||
int drawcalls_;
|
||||
|
||||
@@ -320,6 +322,7 @@ private :
|
||||
// ------------------------------------------------- //
|
||||
|
||||
input inputs_;
|
||||
bool tab_was_pressed_;
|
||||
};
|
||||
|
||||
#endif
|
@@ -50,10 +50,8 @@ public:
|
||||
bool IsSPressed() const;
|
||||
bool IsQPressed() const;
|
||||
bool IsEPressed()const;
|
||||
bool IsTildePressed() const;
|
||||
bool IsTildeReleased() const;
|
||||
|
||||
bool IsKeyDown(unsigned int) const;
|
||||
bool is_key_pressed(const unsigned int);
|
||||
|
||||
private:
|
||||
bool m_keys[256];
|
||||
|
24
enginecustom/src/src/shader/master_shader.cpp
Normal file
24
enginecustom/src/src/shader/master_shader.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "master_shader.h"
|
||||
#include "Logger.h"
|
||||
|
||||
master_shader::master_shader()
|
||||
{
|
||||
// Initialize shader filenames
|
||||
wcscpy_s(vs_filename_, 128, vs_name_);
|
||||
wcscpy_s(ps_filename_, 128, ps_name_);
|
||||
|
||||
}
|
||||
|
||||
master_shader::~master_shader()
|
||||
{
|
||||
// Destructor implementation
|
||||
}
|
||||
|
||||
bool master_shader::initialize(ID3D11Device* device, HWND hwnd)
|
||||
{
|
||||
Logger::Get().Log("Initializing master_shader", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
||||
|
||||
bool success = false;
|
||||
|
||||
return true;
|
||||
}
|
@@ -49,6 +49,7 @@ application_class::application_class() : should_quit_(false)
|
||||
light_model_ = nullptr;
|
||||
render_count_ = 0;
|
||||
drawcalls_ = 0;
|
||||
tab_was_pressed_ = false;
|
||||
}
|
||||
|
||||
application_class::~application_class()
|
||||
@@ -121,12 +122,26 @@ bool application_class::initialize(int screenWidth, int screenHeight, HWND hwnd,
|
||||
return false;
|
||||
}
|
||||
|
||||
sun_camera_ = new camera_class;
|
||||
if (!sun_camera_)
|
||||
{
|
||||
Logger::Get().Log("Could not create the sun camera object", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
sun_camera_->set_position(0.0f,0.0f,0.0f);
|
||||
sun_camera_->set_rotation(0.0f, 0.0f, 0.0f);
|
||||
sun_camera_->render();
|
||||
sun_camera_->get_view_matrix(base_view_matrix_);
|
||||
|
||||
// Set the initial position of the camera.
|
||||
camera_->set_position(0.0f, 0.0f, -12.0f);
|
||||
camera_->set_rotation(0.0f, 0.0f, 0.0f);
|
||||
camera_->render();
|
||||
camera_->get_view_matrix(base_view_matrix_);
|
||||
|
||||
active_camera_ = camera_;
|
||||
|
||||
// Create and initialize the font shader object.
|
||||
font_shader_ = new font_shader_class;
|
||||
|
||||
@@ -315,6 +330,10 @@ bool application_class::initialize(int screenWidth, int screenHeight, HWND hwnd,
|
||||
sun_light_->SetPosition(0.0f, 100.0f, 0.0f);
|
||||
sun_light_->SetIntensity(1.0f);
|
||||
|
||||
sun_camera_->set_position(sun_light_->GetPosition().x, sun_light_->GetPosition().y, sun_light_->GetPosition().z);
|
||||
sun_camera_->set_rotation(0.0f, 0.0f, 0.0f);
|
||||
sun_camera_->render();
|
||||
|
||||
// Create and initialize the normal map shader object.
|
||||
shader_manager_ = new shader_manager_class;
|
||||
|
||||
@@ -713,6 +732,14 @@ void application_class::shutdown()
|
||||
scene_texture_ = nullptr;
|
||||
}
|
||||
|
||||
if (sun_camera_)
|
||||
{
|
||||
Logger::Get().Log("Releasing the sun camera object", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
||||
delete sun_camera_;
|
||||
sun_camera_ = nullptr;
|
||||
Logger::Get().Log("Sun camera object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
||||
}
|
||||
|
||||
Logger::Get().Log("Application class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
||||
}
|
||||
|
||||
@@ -786,11 +813,36 @@ bool application_class::frame(input_class* Input)
|
||||
buttonE = Input->IsEPressed();
|
||||
position_->MoveCamera(buttonZ, buttonS, buttonQ, buttonD, buttonE, buttonA, scrollUp, scrollDown, rightMouseDown);
|
||||
position_->GetPosition(positionX, positionY, positionZ);
|
||||
|
||||
XMFLOAT3 dir = sun_light_->GetDirection();
|
||||
float pitch = asinf(-dir.y) * (180.0f / XM_PI); // en degr<67>s
|
||||
float yaw = atan2f(dir.x, dir.z) * (180.0f / XM_PI); // en degr<67>s
|
||||
float roll = 0.0f;
|
||||
|
||||
if (Input->is_key_pressed(DIK_TAB)) {
|
||||
if (!tab_was_pressed_) {
|
||||
// Alterner la cam<61>ra active
|
||||
if (active_camera_ == camera_)
|
||||
active_camera_ = sun_camera_;
|
||||
else
|
||||
active_camera_ = camera_;
|
||||
tab_was_pressed_ = true;
|
||||
}
|
||||
} else {
|
||||
tab_was_pressed_ = false;
|
||||
}
|
||||
|
||||
// Set the postion and rotation of the camera.
|
||||
camera_->set_position(positionX, positionY, positionZ);
|
||||
camera_->set_rotation(rotationX, rotationY, 0.0f);
|
||||
camera_->render();
|
||||
if (active_camera_ == camera_) {
|
||||
// Update the camera position and rotation based on the position class.
|
||||
camera_->set_position(positionX, positionY, positionZ);
|
||||
camera_->set_rotation(rotationX, rotationY, 0.0f);
|
||||
} else {
|
||||
// Update the sun camera position and rotation based on the light position.
|
||||
sun_camera_->set_position(sun_light_->GetPosition().x, sun_light_->GetPosition().y, sun_light_->GetPosition().z);
|
||||
sun_camera_->set_rotation(pitch, yaw, roll);
|
||||
}
|
||||
|
||||
active_camera_->render();
|
||||
|
||||
// render the static graphics scene.
|
||||
result = render(rotation, x, y, z, textureTranslation);
|
||||
@@ -991,11 +1043,11 @@ bool application_class::render(float rotation, float x, float y, float z, float
|
||||
blendAmount = 0.1f;
|
||||
|
||||
// Generate the view matrix based on the camera's position.
|
||||
camera_->render();
|
||||
active_camera_->render();
|
||||
|
||||
// Get the world, view, and projection matrices from the camera and d3d objects.
|
||||
worldMatrix = direct_3d_->get_world_matrix();
|
||||
camera_->get_view_matrix(viewMatrix);
|
||||
active_camera_->get_view_matrix(viewMatrix);
|
||||
projectionMatrix = direct_3d_->get_projection_matrix();
|
||||
orthoMatrix = direct_3d_->get_ortho_matrix();
|
||||
|
||||
@@ -1933,7 +1985,7 @@ void application_class::update_skybox_position()
|
||||
return;
|
||||
}
|
||||
|
||||
skybox_[0]->SetTranslateMatrix(XMMatrixTranslation(camera_->get_position().x, camera_->get_position().y, camera_->get_position().z));
|
||||
skybox_[0]->SetTranslateMatrix(XMMatrixTranslation(active_camera_->get_position().x, active_camera_->get_position().y, active_camera_->get_position().z));
|
||||
|
||||
}
|
||||
|
||||
|
@@ -432,3 +432,13 @@ bool input_class::IsScrollDown() const
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool input_class::is_key_pressed(const unsigned int key_code)
|
||||
{
|
||||
if (m_keyboardState[key_code] & 0x80)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user