math.hpp
This commit is contained in:
parent
b8f041584f
commit
0aefa70fb8
@ -164,7 +164,12 @@ void MainWindow::draw_frame(){
|
||||
//Resources::Texture tutel(Resources::getResource("tutel.png"), sdl_renderer);
|
||||
static Resources::CacheStorage<Resources::Texture> textures;
|
||||
Resources::Texture& tutel = textures.getOrCreate("tutel.png", sdl_renderer);
|
||||
tutel.render(SDL_FRectConstruct(100, 100, 400, 400));
|
||||
Resources::SDL_RenderCopyExF_Params rp;
|
||||
rp.target_section = SDL_FRectConstruct(100, 100, 400, 400);
|
||||
static int si = 1;
|
||||
rp.rotation_angle = M_PI_4 * (si++ / fps_max);
|
||||
tutel.render(rp);
|
||||
|
||||
|
||||
ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData(), sdl_renderer);
|
||||
// Swap buffers
|
||||
@ -193,7 +198,6 @@ void MainWindow::startUpdateLoop(){
|
||||
nsec_t after_update_time_ns = getMonotonicTimeNsec();
|
||||
nsec_t frame_delay_ns = (nsec_t)1e9 / fps_max - (after_update_time_ns - update_time_ns);
|
||||
if(frame_delay_ns > 0){
|
||||
std::cout<<"frameDelay: "<<frame_delay_ns / 1e9f<<std::endl;
|
||||
SDL_Delay(frame_delay_ns / 1e6);
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ class MainWindow {
|
||||
public:
|
||||
ImVec4 clear_color = RGBAHexToF(35,35,50,255);
|
||||
f32 default_font_size = 14.0f;
|
||||
int fps_max = 30;
|
||||
int fps_max = 60;
|
||||
// called on each frame
|
||||
UpdatingFunc update = nullptr;
|
||||
|
||||
|
||||
0
src/GUI/SceneView.hpp
Normal file
0
src/GUI/SceneView.hpp
Normal file
15
src/Game/GameObject.hpp
Normal file
15
src/Game/GameObject.hpp
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "../math.hpp"
|
||||
#include <set>
|
||||
|
||||
class GameObject {
|
||||
public:
|
||||
Vec2 scale = { 1, 1 };
|
||||
Vec2 position;
|
||||
angle_t rotation;
|
||||
|
||||
private:
|
||||
// std::set<Component> components;
|
||||
};
|
||||
|
||||
7
src/Game/Scene.hpp
Normal file
7
src/Game/Scene.hpp
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "GameObject.hpp"
|
||||
|
||||
class Scene {
|
||||
|
||||
};
|
||||
@ -41,7 +41,7 @@ void Texture::render(const SDL_RenderCopyExF_Params& p){
|
||||
SDL_RenderCopyExF(renderer, texture.get(),
|
||||
optional_value_ptr_or_null(p.texture_section),
|
||||
optional_value_ptr_or_null(p.target_section),
|
||||
p.rotation_angle,
|
||||
-1.0f * angleToDegree(normalizeAngle(p.rotation_angle)),
|
||||
optional_value_ptr_or_null(p.rotation_center),
|
||||
p.flip
|
||||
)
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include <memory>
|
||||
#include <SDL.h>
|
||||
#include "Resources.hpp"
|
||||
#include "../math.hpp"
|
||||
|
||||
namespace ougge::Resources {
|
||||
|
||||
@ -22,7 +23,7 @@ struct SDL_RenderCopyExF_Params {
|
||||
std::optional<SDL_Rect> texture_section;
|
||||
std::optional<SDL_FRect> target_section;
|
||||
std::optional<SDL_FPoint> rotation_center;
|
||||
double rotation_angle;
|
||||
angle_t rotation_angle;
|
||||
SDL_RendererFlip flip;
|
||||
|
||||
SDL_RenderCopyExF_Params();
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
#define SDL_MAIN_HANDLED
|
||||
#include <iostream>
|
||||
#include "std.hpp"
|
||||
#include "GUI/MainWindow.hpp"
|
||||
#include "Resources/Resources.hpp"
|
||||
#include "Game/Scene.hpp"
|
||||
#include "format.hpp"
|
||||
#include "exceptions.hpp"
|
||||
|
||||
using namespace ougge;
|
||||
|
||||
void update(f64 deltaTime){
|
||||
std::cout<<"deltaTime: "<<deltaTime<<std::endl;
|
||||
// std::cout<<"deltaTime: "<<deltaTime<<std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, const char** argv){
|
||||
|
||||
31
src/math.hpp
Normal file
31
src/math.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "std.hpp"
|
||||
#include <cmath>
|
||||
|
||||
struct Vec2 {
|
||||
f32 x = 0, y = 0;
|
||||
};
|
||||
|
||||
struct Vec3 {
|
||||
f32 x = 0, y = 0, z = 0;
|
||||
};
|
||||
|
||||
struct Vec4 {
|
||||
f32 x = 0, y = 0, z = 0, w = 0;
|
||||
};
|
||||
|
||||
/// radians
|
||||
typedef f32 angle_t;
|
||||
|
||||
static inline angle_t normalizeAngle(angle_t a){
|
||||
return std::fmodf(a + M_PI, 2*M_PI) - M_PI;
|
||||
}
|
||||
|
||||
static inline f32 angleToDegree(angle_t a){
|
||||
return (a / M_PI) * 180;
|
||||
}
|
||||
|
||||
static inline angle_t degreeToRadian(f32 d){
|
||||
return (d / 180) * M_PI;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user