Skip to content

Commit

Permalink
Merge pull request #101 from kimkulling/AddFrtustum
Browse files Browse the repository at this point in the history
Add ftustum
  • Loading branch information
kimkulling authored Oct 17, 2021
2 parents f895b4a + f165612 commit 58297af
Show file tree
Hide file tree
Showing 20 changed files with 184 additions and 47 deletions.
2 changes: 1 addition & 1 deletion include/osre/App/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#pragma once

#include <osre/Common/TObjPtr.h>
#include <osre/Math/BaseMath.h>
#include <osre/Common/BaseMath.h>
#include <osre/RenderBackend/RenderCommon.h>
#include <osre/Scene/SceneCommon.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------------------------------------------------------------------------------------------*/
#pragma once

#include <osre/Common/osre_common.h>
#include <osre/Common/glm_common.h>
#include <osre/Common/osre_common.h>

#include <cmath>

namespace OSRE {
namespace Math {
namespace Common {

//-------------------------------------------------------------------------------------------------
/// @class ::OSRE::Math::BaseMath
Expand Down Expand Up @@ -93,5 +93,5 @@ inline T osre_lerp(T v0, T v1, T t) {
return (1 - t) * v0 + t * v1;
}

} // Namespace Math
} // Namespace Common
} // Namespace OSRE
90 changes: 90 additions & 0 deletions include/osre/Common/Frustum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*-----------------------------------------------------------------------------------------------
The MIT License (MIT)
Copyright (c) 2015-2021 OSRE ( Open Source Render Engine ) by Kim Kulling
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------------------------------------------------------------------------------------------*/
#pragma once

#include <osre/Common/osre_common.h>
#include <osre/Common/glm_common.h>

namespace OSRE {
namespace Common {

class Frustum {
public:
enum {
Top = 0,
Bottom,
Left,
Right,
NearP,
FarP
};

Frustum();
~Frustum() = default;
bool isIn(glm::vec3 &point);
void extractFrom(const glm::mat4 &vp);
void clear();

private:
glm::vec4 mPlanes[6];
};

inline Frustum::Frustum() {
clear();
}

inline bool Frustum::isIn( glm::vec3 &point ) {
bool in = true;
for (auto & plane : mPlanes) {
const f32 d = plane.x * point.x + plane.y * point.y + plane.z * point.z + plane.w;
if (d < 0.0f) {
in = false;
break;
}
}

return in;
}

inline void Frustum::extractFrom(const glm::mat4 &vp) {
glm::vec4 rowX = glm::row(vp, 0);
glm::vec4 rowY = glm::row(vp, 1);
glm::vec4 rowZ = glm::row(vp, 2);
glm::vec4 rowW = glm::row(vp, 3);

mPlanes[0] = normalize(rowW + rowX);
mPlanes[1] = normalize(rowW - rowX);
mPlanes[2] = normalize(rowW + rowY);
mPlanes[3] = normalize(rowW - rowY);
mPlanes[4] = normalize(rowW + rowZ);
mPlanes[5] = normalize(rowW - rowZ);
}

inline void Frustum::clear() {
for (auto &plane : mPlanes) {
plane.x = plane.y = plane.z = plane.w = 0.0f;
}
}

} // namespace Common
} // namespace OSRE
File renamed without changes.
1 change: 1 addition & 0 deletions include/osre/Common/glm_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <glm/gtc/type_ptr.hpp>
#include <glm/mat4x4.hpp>
#include <glm/vec3.hpp>
#include <glm/gtc/matrix_access.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
#include <glm/common.hpp>
Expand Down
2 changes: 1 addition & 1 deletion include/osre/Scene/ParticleEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#include <osre/RenderBackend/RenderCommon.h>
#include <osre/Scene/TAABB.h>
#include <osre/Math/BaseMath.h>
#include <osre/Common/BaseMath.h>

#include <GL/glew.h>
#include <GL/gl.h>
Expand Down
2 changes: 1 addition & 1 deletion samples/01_ModelLoading/ModelLoading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <osre/App/Entity.h>
#include <osre/App/World.h>
#include <osre/IO/Uri.h>
#include <osre/Math/BaseMath.h>
#include <osre/Common/BaseMath.h>
#include <osre/Platform/AbstractWindow.h>
#include <osre/Platform/PlatformOperations.h>
#include <osre/Properties/Settings.h>
Expand Down
2 changes: 1 addition & 1 deletion samples/03_Instancing/Instancing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <osre/App/World.h>
#include <osre/Common/Ids.h>
#include <osre/IO/Uri.h>
#include <osre/Math/BaseMath.h>
#include <osre/Common/BaseMath.h>
#include <osre/Platform/AbstractWindow.h>
#include <osre/Properties/Settings.h>
#include <osre/RenderBackend/RenderBackendService.h>
Expand Down
10 changes: 5 additions & 5 deletions src/Editor_cpp/src/OsreEdApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,27 @@ namespace Colors {
const glm::vec3 Blue(0, 0, 1);
}

static Mesh *createCoordAxis() {
static Mesh *createCoordAxis(ui32 size) {
Mesh *axis = Mesh::create(1, VertexType::ColorVertex);
ColorVert v1, v2, v3, v4, v5, v6;
v1.position.x = v1.position.y = v1.position.z = 0;
v1.color0 = Colors::Red;

v2.position.x = 1000;
v2.position.x = size;
v2.position.y = v2.position.z = 0;
v2.color0 = Colors::Red;

v3.position.x = v3.position.y = v3.position.z = 0;
v3.color0 = Colors::Green;

v4.position.y = 1000;
v4.position.y = size;
v4.position.x = v4.position.z = 0;
v4.color0 = Colors::Green;

v5.position.x = v5.position.y = v5.position.z = 0;
v5.color0 = Colors::Blue;

v6.position.z = 1000;
v6.position.z = size;
v6.position.x = v6.position.y = 0;
v6.color0 = Colors::Blue;

Expand Down Expand Up @@ -321,7 +321,7 @@ bool OsreEdApp::onCreate() {
Entity *editorEntity = new Entity("editor.entity", *getIdContainer(), world);
Mesh *grid = createGrid(60);
editorEntity->addStaticMesh(grid);
editorEntity->addStaticMesh(createCoordAxis());
editorEntity->addStaticMesh(createCoordAxis(1000));
//createUI();

mPythonInterface = new PythonInterface;
Expand Down
17 changes: 4 additions & 13 deletions src/Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ SET( common_inc
${HEADER_PATH}/Common/Event.h
${HEADER_PATH}/Common/EventBus.h
${HEADER_PATH}/Common/EventTriggerer.h
${HEADER_PATH}/Common/Frustum.h
${HEADER_PATH}/Common/Ids.h
${HEADER_PATH}/Common/Logger.h
${HEADER_PATH}/Common/Object.h
Expand All @@ -87,9 +88,12 @@ SET( common_inc
${HEADER_PATH}/Common/Tokenizer.h
${HEADER_PATH}/Common/osre_common.h
${HEADER_PATH}/Common/glm_common.h
${HEADER_PATH}/Common/BaseMath.h
${HEADER_PATH}/Common/TRay.h
)
SET( common_src
Common/ArgumentParser.cpp
Common/BaseMath.cpp
Common/Common.cpp
Common/DateTime.cpp
Common/Event.cpp
Expand Down Expand Up @@ -154,17 +158,6 @@ SET( io_inc
${HEADER_PATH}/IO/Uri.h
)

#==============================================================================
# Math
#==============================================================================
SET( math_src
Math/BaseMath.cpp
)
SET( math_inc
${HEADER_PATH}/Math/BaseMath.h
${HEADER_PATH}/Math/TRay.h
)

#==============================================================================
# Platform
#==============================================================================
Expand Down Expand Up @@ -483,15 +476,13 @@ ADD_LIBRARY( osre SHARED
${scripting_mono_inc}
${threading_inc}
${renderbackend_inc}
${math_inc}

${app_src}
${Common_src}
${components_src}
${debugging_src}
${debugging_windows_src}
${io_src}
${math_src}
${memory_src}
${system_src}
${system_impl_src}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------------------------------------------------------------------------------------------*/
#include <osre/Math/BaseMath.h>
#include <osre/Common/BaseMath.h>

namespace OSRE {
namespace Math {
namespace Common {

BaseMath::BaseMath() {
// empty
Expand All @@ -41,5 +41,5 @@ f32 BaseMath::getPI() {
return 3.141592653589f;
}

} // namespace Math
} // namespace Common
} // namespace OSRE
3 changes: 1 addition & 2 deletions src/Engine/RenderBackend/OGLRenderer/OGLRenderCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#pragma once

#include <osre/Common/osre_common.h>
#include <osre/Math/BaseMath.h>
#include <osre/Common/BaseMath.h>

#include <cppcore/Container/TArray.h>

Expand All @@ -34,7 +34,6 @@ class OGLRenderContext;
class OGLRenderBackend;
class OGLShader;
class RenderCmdBuffer;
//class HWBufferManager;
class OGLRenderEventHandler;
class Mesh;

Expand Down
2 changes: 1 addition & 1 deletion src/Engine/RenderBackend/OGLRenderer/RenderCmdBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#pragma once

#include <cppcore/Container/TArray.h>
#include <osre/Math/BaseMath.h>
#include <osre/Common/BaseMath.h>
#include <osre/RenderBackend/RenderStates.h>

#include <map>
Expand Down
5 changes: 1 addition & 4 deletions src/Engine/Scene/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ void Camera::onUpdate(Time dt) {
}

void Camera::onRender(RenderBackendService *rbSrv) {
if (nullptr == rbSrv) {
osre_debug(Tag, "Pointer to renderbackend service is nullptr.");
return;
}
osre_assert(nullptr != rbSrv);

rbSrv->setMatrix(MatrixType::View, m_view);
rbSrv->setMatrix(MatrixType::Projection, m_projection);
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/Scene/DbgRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------------------------------------------------------------------------------------------*/
#include <osre/Debugging/osre_debugging.h>
#include <osre/Math/BaseMath.h>
#include <osre/Common/BaseMath.h>
#include <osre/RenderBackend/Mesh.h>
#include <osre/RenderBackend/Pipeline.h>
#include <osre/RenderBackend/RenderBackendService.h>
Expand Down
4 changes: 2 additions & 2 deletions src/Engine/Scene/TrackBall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------------------------------------------------------------------------------------------*/
#include <osre/Math/BaseMath.h>
#include <osre/Common/BaseMath.h>
#include <osre/Platform/PlatformInterface.h>
#include <osre/Scene/TrackBall.h>
#include <osre/Scene/Node.h>
Expand Down Expand Up @@ -139,7 +139,7 @@ void TrackBall::mapToSphere(const Vec2f *pNewPt, Vec3f *newVector) {

void TrackBall::computeRotation() {
Vec3f perp = mStartVector.crossProduct(mEndVector);
if (perp.getLength() > Math::BaseMath::getSPEPS()) {
if (perp.getLength() > Common::BaseMath::getSPEPS()) {
m_rotation.x = perp.getX();
m_rotation.y = perp.getX();
m_rotation.z = perp.getZ();
Expand Down
9 changes: 3 additions & 6 deletions test/UnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ SET ( unittest_common_src
src/Common/EventTest.cpp
src/Common/EventBusTest.cpp
src/Common/IdsTest.cpp
src/Common/FrustumTest.cpp
src/Common/BaseMathTest.cpp
src/Common/TRayTest.cpp
)

SET ( unittest_collision_src
Expand All @@ -53,11 +56,6 @@ SET( unittest_io_src
src/IO/UriTest.cpp
)

SET( unittest_math_src
src/Math/BaseMathTest.cpp
src/Math/TRayTest.cpp
)

SET( unittest_platform_src
src/Platform/AbstractDynamicLoaderTest.cpp
src/Platform/AbstractThreadTest.cpp
Expand Down Expand Up @@ -106,7 +104,6 @@ SOURCE_GROUP( src\\Common FILES ${unittest_common_src} )
SOURCE_GROUP( src\\Collision FILES ${unittest_collision_src})
SOURCE_GROUP( src\\Debugging FILES ${unittest_debugging_src})
SOURCE_GROUP( src\\IO FILES ${unittest_io_src} )
SOURCE_GROUP( src\\Math FILES ${unittest_math_src} )
SOURCE_GROUP( src\\Platform FILES ${unittest_platform_src})
SOURCE_GROUP( src\\Profiling FILES ${unittest_profiling_src})
SOURCE_GROUP( src\\RenderBackend FILES ${unittest_rb_src} )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------------------------------------------------------------------------------------------*/
#include "osre_testcommon.h"
#include <osre/Math/BaseMath.h>
#include <osre/Common/BaseMath.h>

namespace OSRE {
namespace UnitTest {

using namespace ::OSRE::Math;
using namespace ::OSRE::Common;

class BaseMathTest : public testing::Test {
// empty
Expand Down
Loading

0 comments on commit 58297af

Please sign in to comment.