-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UPBGE: Implement Moto function to generate frustum box.
The new function MT_FrustumBox in MT_Frustum is used to generate the 8 vertices of a box using the combinaison of the projection and modelview matrix of a camera.
- Loading branch information
1 parent
db5bc1b
commit 4216f5c
Showing
5 changed files
with
121 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* ***** BEGIN GPL LICENSE BLOCK ***** | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Contributor(s): Tristan Porteries. | ||
* | ||
* ***** END GPL LICENSE BLOCK ***** | ||
*/ | ||
|
||
/** \file moto/include/MT_Frustum.h | ||
* \ingroup moto | ||
*/ | ||
|
||
#include "MT_Matrix4x4.h" | ||
|
||
#include <array> | ||
|
||
void MT_FrustumBox(const MT_Matrix4x4& mat, std::array<MT_Vector3, 8>& box); | ||
|
||
#ifdef GEN_INLINED | ||
# include "MT_Frustum.inl" | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* ***** BEGIN GPL LICENSE BLOCK ***** | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Contributor(s): Tristan Porteries. | ||
* | ||
* ***** END GPL LICENSE BLOCK ***** | ||
*/ | ||
|
||
/** \file moto/include/MT_Frustum.inl | ||
* \ingroup moto | ||
*/ | ||
|
||
#include "MT_Optimize.h" | ||
|
||
GEN_INLINE void MT_FrustumBox(const MT_Matrix4x4& mat, std::array<MT_Vector3, 8>& box) | ||
{ | ||
static const MT_Vector3 normalizedBox[8] = { | ||
MT_Vector3(-1.0f, -1.0f, -1.0f), | ||
MT_Vector3(-1.0f, 1.0f, -1.0f), | ||
MT_Vector3(1.0f, 1.0f, -1.0f), | ||
MT_Vector3(1.0f, -1.0f, -1.0f), | ||
MT_Vector3(-1.0f, -1.0f, 1.0f), | ||
MT_Vector3(-1.0f, 1.0f, 1.0f), | ||
MT_Vector3(1.0f, 1.0f, 1.0f), | ||
MT_Vector3(1.0f, -1.0f, 1.0f) | ||
}; | ||
|
||
for (unsigned short i = 0; i < 8; ++i) { | ||
const MT_Vector3& p3 = normalizedBox[i]; | ||
const MT_Vector4 p4 = mat * MT_Vector4(p3.x(), p3.y(), p3.z(), 1.0f); | ||
|
||
box[i] = p4.to3d() / p4.w(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* ***** BEGIN GPL LICENSE BLOCK ***** | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Contributor(s): Tristan Porteries. | ||
* | ||
* ***** END GPL LICENSE BLOCK ***** | ||
*/ | ||
|
||
/** \file moto/include/MT_Frustum.cpp | ||
* \ingroup moto | ||
*/ | ||
|
||
|
||
#include "MT_Frustum.h" | ||
|
||
#ifndef GEN_INLINED | ||
# include "MT_Frustum.inl" | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters