tyrav2 init

This commit is contained in:
h4570
2022-07-17 10:21:35 +02:00
parent 44c1ee4fe8
commit c8b22ff331
249 changed files with 18187 additions and 0 deletions
@@ -0,0 +1,43 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
#include <vector>
#include "./core_bbox_frustum.hpp"
#include "math/m4x4.hpp"
#include "math/plane.hpp"
namespace Tyra {
/** Bounding box */
class CoreBBox {
public:
explicit CoreBBox(Vec4* t_vertices, u32* faces, u32 t_count);
explicit CoreBBox(Vec4* t_vertices, u32 t_count);
explicit CoreBBox(Vec4* t_vertices);
explicit CoreBBox(CoreBBox** t_bboxes, const u32& count);
explicit CoreBBox(const std::vector<CoreBBox>& t_bboxes,
const u32& startIndex, const u32& stopIndex);
const Vec4& operator[](const u8& i) { return _vertices[i]; }
const Vec4& getVertex(const u8& i) { return _vertices[i]; }
Vec4* getVertices() { return _vertices; }
void print() const;
void print(const char* name) const;
void print(const std::string& name) const { print(name.c_str()); }
std::string getPrint(const char* name = nullptr) const;
protected:
Vec4 _vertices[8];
};
} // namespace Tyra
@@ -0,0 +1,17 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
namespace Tyra {
enum CoreBBoxFrustum { IN_FRUSTUM, OUTSIDE_FRUSTUM, PARTIALLY_IN_FRUSTUM };
} // namespace Tyra
@@ -0,0 +1,35 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
#include <vector>
#include "./core_bbox.hpp"
namespace Tyra {
/** Bounding box */
class RenderBBox : public CoreBBox {
public:
explicit RenderBBox(Vec4* t_vertices, u32* faces, u32 t_count);
explicit RenderBBox(Vec4* t_vertices, u32 t_count);
explicit RenderBBox(Vec4* t_vertices);
explicit RenderBBox(CoreBBox** t_bboxes, const u32& count);
explicit RenderBBox(const std::vector<CoreBBox>& t_bboxes,
const u32& startIndex, const u32& stopIndex);
CoreBBoxFrustum isInFrustum(const Plane* frustumPlanes, const M4x4& model,
const float* margins = nullptr) const;
CoreBBoxFrustum clipIsInFrustum(const Plane* frustumPlanes,
const M4x4& model) const;
};
} // namespace Tyra
@@ -0,0 +1,29 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
#include "math/vec4.hpp"
namespace Tyra {
class CameraInfo3D {
public:
CameraInfo3D(Vec4* cameraPosition, Vec4* cameraLooksAt,
Vec4* cameraUp = nullptr);
~CameraInfo3D();
Vec4 *position, *looksAt, *up;
private:
static Vec4 defaultCameraUp;
};
} // namespace Tyra
@@ -0,0 +1,45 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
#include <sstream>
#include "renderer/renderer_settings.hpp"
#include "./camera_info_3d.hpp"
#include "math/plane.hpp"
namespace Tyra {
class Renderer3DFrustumPlanes {
public:
Renderer3DFrustumPlanes();
~Renderer3DFrustumPlanes();
void init(RendererSettings* settings, const float& fov);
void update(const CameraInfo3D& cameraInfo, const float& fov);
const Plane& get(u8 index) const { return frustumPlanes[index]; }
const Plane* getAll() const { return frustumPlanes; }
const Plane& operator[](u8 index) const { return frustumPlanes[index]; }
void print() const;
void print(const char* name) const;
void print(const std::string& name) const { print(name.c_str()); }
std::string getPrint(const char* name = nullptr) const;
private:
void computeStaticData(const float& fov);
float lastFov;
RendererSettings* settings;
Plane frustumPlanes[6];
float nearHeight, nearWidth, farHeight, farWidth;
Vec4 nearCenter, farCenter, X, Y, Z, ntl, ntr, nbl, nbr, ftl, fbr, ftr, fbl;
};
} // namespace Tyra
@@ -0,0 +1,90 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
#include <algorithm>
#include "renderer/renderer_settings.hpp"
#include "./renderer_3d_frustum_planes.hpp"
#include "./camera_info_3d.hpp"
#include "renderer/core/texture/models/texture.hpp"
#include "renderer/core/3d/bbox/core_bbox.hpp"
#include "renderer/core/paths/path1/path1.hpp"
namespace Tyra {
class RendererCore3D {
public:
RendererCore3D();
~RendererCore3D();
/** Current camera frustum planes. */
Renderer3DFrustumPlanes frustumPlanes;
/** Called by renderer. */
void init(RendererSettings* settings, Path1* t_path1);
const float& getFov() const { return fov; }
void setFov(const float& t_fov);
/**
* Called by beginFrame();
* Updates camera info, to get proper frustum culling.
*/
void update(const CameraInfo3D& cameraInfo);
/** Get projection (screen) matrix */
const M4x4& getProjection() { return projection; }
/**
* Get view (camera) matrix
* Updated at every beginFrame()
*/
const M4x4& getView() { return view; }
/**
* Get projection * view matrix
* Updated at every beginFrame()
*/
const M4x4& getViewProj() { return viewProj; }
/**
* @brief
* Upload VU1 program.
* Please pay attention that you will be REPLACING
* current VU1 programs
*
* @param address Starting address of your program.
* @return Address of the end of your program, so next program can start from
* this + 1
*/
u32 uploadVU1Program(VU1Program* program, const u32& address);
/**
* @brief Set VU1 double buffer
*
* @param startingAddress Starting address. Example 10.
* @param bufferSize Buffer size. Example 490, so second buffer will start
* from 490+10
*/
void setVU1DoubleBuffers(const u16& startingAddress, const u16& bufferSize);
private:
M4x4 view, projection, viewProj;
float fov;
RendererSettings* settings;
Path1* path1;
void setProjection();
};
} // namespace Tyra