Skip to content

Commit 349186d

Browse files
author
phillemann
committed
Added frustum culling \o/
1 parent a3e8984 commit 349186d

30 files changed

+695
-74
lines changed

graphics/camera/object.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ insula::graphics::camera::object::perspective() const
155155
far_);
156156
}
157157

158+
insula::graphics::mat4 const
159+
insula::graphics::camera::object::mvp() const
160+
{
161+
return
162+
perspective() * world();
163+
}
164+
158165
insula::graphics::gizmo const &
159166
insula::graphics::camera::object::gizmo() const
160167
{

graphics/camera/object.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class object
5858
mat4 const
5959
perspective() const;
6060

61+
mat4 const
62+
mvp() const;
63+
6164
insula::graphics::gizmo const &
6265
gizmo() const;
6366

graphics/frustum.hpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef INSULA_GRAPHICS_FRUSTUM_HPP_INCLUDED
2+
#define INSULA_GRAPHICS_FRUSTUM_HPP_INCLUDED
3+
4+
#include "scalar.hpp"
5+
#include "../math/basic_frustum.hpp"
6+
7+
namespace insula
8+
{
9+
namespace graphics
10+
{
11+
typedef
12+
math::basic_frustum<scalar>
13+
frustum;
14+
}
15+
}
16+
17+
#endif

graphics/plane.hpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef INSULA_GRAPHICS_PLANE_HPP_INCLUDED
2+
#define INSULA_GRAPHICS_PLANE_HPP_INCLUDED
3+
4+
#include "../basic_plane.hpp"
5+
#include "scalar.hpp"
6+
7+
namespace insula
8+
{
9+
namespace graphics
10+
{
11+
typedef
12+
basic_plane<scalar>
13+
plane;
14+
};
15+
}
16+
}
17+
18+
#endif

graphics/shader/object.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ insula::graphics::shader::object::object(
103103
return s + v.declaration();
104104
});
105105

106+
/*
106107
fcppt::io::cout << "Generated header: " << header << "\n";
107108
fcppt::io::cout << "Got format declaration: " << format_declaration << "\n";
108109
fcppt::io::cout << "Preprocessed vertex shader: " <<
@@ -111,6 +112,7 @@ insula::graphics::shader::object::object(
111112
vertex),
112113
std::string("$$$HEADER$$$"),
113114
format_declaration+header) << "\n";
115+
*/
114116

115117
program_ =
116118
renderer_->create_glsl_program(
@@ -131,13 +133,13 @@ insula::graphics::shader::object::object(
131133
renderer_,
132134
program_);
133135

134-
fcppt::io::cout << "Iterating through variables\n";
136+
//fcppt::io::cout << "Iterating through variables\n";
135137
BOOST_FOREACH(variable const &v,_variables)
136138
{
137139
if (v.type() != variable_type::uniform)
138140
continue;
139141

140-
fcppt::io::cout << "Setting initial value for variable " << v.name() << "\n";
142+
// fcppt::io::cout << "Setting initial value for variable " << v.name() << "\n";
141143
// TODO: See above
142144
fcppt::variant::apply_unary(
143145
uniform_setter(
@@ -147,9 +149,9 @@ insula::graphics::shader::object::object(
147149
program_->uniform(v.name()))).first->second),
148150
v.initial_value());
149151
}
150-
fcppt::io::cout << "Iterating through variables - DONE\n";
152+
//fcppt::io::cout << "Iterating through variables - DONE\n";
151153

152-
fcppt::io::cout << "Now iterating though samplers\n";
154+
//fcppt::io::cout << "Now iterating though samplers\n";
153155
sampler::texture_unit_type current_tu =
154156
static_cast<sampler::texture_unit_type>(0);
155157
BOOST_FOREACH(
@@ -159,8 +161,8 @@ insula::graphics::shader::object::object(
159161
samplers_.push_back(
160162
v);
161163

162-
fcppt::io::cout
163-
<< "Assigning " << v.name() << " the texture unit " << current_tu << "\n";
164+
/* fcppt::io::cout
165+
<< "Assigning " << v.name() << " the texture unit " << current_tu << "\n";*/
164166

165167
sge::renderer::glsl::uniform::single_value(
166168
uniforms_.insert(

math/basic_frustum.hpp

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef INSULA_MATH_BASIC_FRUSTUM_HPP_INCLUDED
2+
#define INSULA_MATH_BASIC_FRUSTUM_HPP_INCLUDED
3+
4+
#include "plane/basic.hpp"
5+
#include <array>
6+
7+
namespace insula
8+
{
9+
namespace math
10+
{
11+
template<typename T>
12+
class basic_frustum
13+
{
14+
public:
15+
typedef
16+
plane::basic<T>
17+
plane;
18+
19+
void left(plane const &v) { planes_[0] = v; }
20+
void right(plane const &v) { planes_[1] = v; }
21+
void top(plane const &v) { planes_[2] = v; }
22+
void bottom(plane const &v) { planes_[3] = v; }
23+
void near(plane const &v) { planes_[4] = v; }
24+
void far(plane const &v) { planes_[5] = v; }
25+
26+
plane const &left() const { return planes_[0]; }
27+
plane const &right() const { return planes_[1]; }
28+
plane const &top() const { return planes_[2]; }
29+
plane const &bottom() const { return planes_[3]; }
30+
plane const &near() const { return planes_[4]; }
31+
plane const &far() const { return planes_[5]; }
32+
private:
33+
typedef std::array<plane,6> array;
34+
35+
array planes_;
36+
};
37+
}
38+
}
39+
40+
#endif

math/extract_frustum.hpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef INSULA_MATH_EXTRACT_FRUSTUM_HPP_INCLUDED
2+
#define INSULA_MATH_EXTRACT_FRUSTUM_HPP_INCLUDED
3+
4+
#include "basic_frustum.hpp"
5+
#include "plane/from_vec4.hpp"
6+
#include "plane/normalize.hpp"
7+
#include "matrix_row.hpp"
8+
#include <fcppt/math/matrix/basic.hpp>
9+
#include <fcppt/math/vector/arithmetic.hpp>
10+
11+
namespace insula
12+
{
13+
namespace math
14+
{
15+
// See http://www.cs.otago.ac.nz/postgrads/alexis/planeExtraction.pdf
16+
template<typename T>
17+
basic_frustum<T> const
18+
extract_frustum(
19+
typename fcppt::math::matrix::static_<T,4,4>::type const &m)
20+
{
21+
basic_frustum<T> result;
22+
result.left(plane::normalize(plane::from_vec4<T>(matrix_row<T>(m,3) + matrix_row<T>(m,0))));
23+
result.right(plane::normalize(plane::from_vec4<T>(matrix_row<T>(m,3) - matrix_row<T>(m,0))));
24+
result.bottom(plane::normalize(plane::from_vec4<T>(matrix_row<T>(m,3) + matrix_row<T>(m,1))));
25+
result.top(plane::normalize(plane::from_vec4<T>(matrix_row<T>(m,3) - matrix_row<T>(m,1))));
26+
result.near(plane::normalize(plane::from_vec4<T>(matrix_row<T>(m,3) + matrix_row<T>(m,2))));
27+
result.far(plane::normalize(plane::from_vec4<T>(matrix_row<T>(m,3) - matrix_row<T>(m,2))));
28+
return result;
29+
}
30+
}
31+
}
32+
33+
#endif

math/matrix_row.hpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef INSULA_MATH_MATRIX_ROW_HPP_INCLUDED
2+
#define INSULA_MATH_MATRIX_ROW_HPP_INCLUDED
3+
4+
#include <fcppt/math/matrix/static.hpp>
5+
#include <fcppt/math/matrix/basic_impl.hpp>
6+
#include <fcppt/math/vector/static.hpp>
7+
#include <fcppt/math/size_type.hpp>
8+
9+
namespace insula
10+
{
11+
namespace math
12+
{
13+
template<typename T>
14+
typename
15+
fcppt::math::vector::static_<T,4>::type const
16+
matrix_row(
17+
typename fcppt::math::matrix::static_<T,4,4>::type const &m,
18+
fcppt::math::size_type const row)
19+
{
20+
return
21+
typename fcppt::math::vector::static_<T,4>::type(
22+
m[row][0],
23+
m[row][1],
24+
m[row][2],
25+
m[row][3]);
26+
}
27+
}
28+
}
29+
30+
#endif

math/plane/basic.hpp

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#ifndef INSULA_MATH_PLANE_BASIC_HPP_INCLUDED
2+
#define INSULA_MATH_PLANE_BASIC_HPP_INCLUDED
3+
4+
#include <fcppt/math/vector/static.hpp>
5+
#include <fcppt/math/vector/basic_impl.hpp>
6+
#include <fcppt/math/vector/output.hpp>
7+
#include <fcppt/io/ostream.hpp>
8+
9+
namespace insula
10+
{
11+
namespace math
12+
{
13+
namespace plane
14+
{
15+
template<typename T>
16+
class basic
17+
{
18+
public:
19+
typedef typename
20+
fcppt::math::vector::static_<T,3>::type
21+
vector;
22+
23+
typedef
24+
T
25+
scalar;
26+
27+
explicit
28+
basic()
29+
{
30+
}
31+
32+
explicit
33+
basic(
34+
vector const &_normal,
35+
scalar const _lambda)
36+
:
37+
normal_(
38+
_normal),
39+
lambda_(
40+
_lambda)
41+
{
42+
}
43+
44+
vector const
45+
normal() const
46+
{
47+
return normal_;
48+
}
49+
50+
scalar const
51+
lambda() const
52+
{
53+
return lambda_;
54+
}
55+
private:
56+
vector normal_;
57+
scalar lambda_;
58+
};
59+
}
60+
}
61+
}
62+
63+
template<typename T>
64+
fcppt::io::ostream &
65+
operator<<(
66+
fcppt::io::ostream &s,
67+
insula::math::plane::basic<T> const &p)
68+
{
69+
return
70+
s << FCPPT_TEXT('(') << p.normal() << FCPPT_TEXT(',')
71+
<< p.lambda() << FCPPT_TEXT(')');
72+
}
73+
74+
#endif

math/plane/from_vec4.hpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef INSULA_MATH_PLANE_FROM_VEC4_HPP_INCLUDED
2+
#define INSULA_MATH_PLANE_FROM_VEC4_HPP_INCLUDED
3+
4+
#include "basic.hpp"
5+
#include <fcppt/math/vector/static.hpp>
6+
#include <fcppt/math/vector/basic_impl.hpp>
7+
8+
namespace insula
9+
{
10+
namespace math
11+
{
12+
namespace plane
13+
{
14+
template<typename T>
15+
basic<T> const
16+
from_vec4(
17+
typename fcppt::math::vector::static_<T,4>::type const &v)
18+
{
19+
return
20+
basic<T>(
21+
typename basic<T>::vector(
22+
v[0],
23+
v[1],
24+
v[2]),
25+
v[3]);
26+
}
27+
}
28+
}
29+
}
30+
31+
#endif

math/plane/normalize.hpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef INSULA_MATH_PLANE_NORMALIZE_HPP_INCLUDED
2+
#define INSULA_MATH_PLANE_NORMALIZE_HPP_INCLUDED
3+
4+
#include "basic.hpp"
5+
#include <fcppt/math/vector/normalize.hpp>
6+
7+
namespace insula
8+
{
9+
namespace math
10+
{
11+
namespace plane
12+
{
13+
template<typename T>
14+
basic<T> const
15+
normalize(
16+
basic<T> const &p)
17+
{
18+
return
19+
basic<T>(
20+
fcppt::math::vector::normalize(
21+
p.normal()),
22+
p.lambda()/
23+
fcppt::math::vector::length(
24+
p.normal()));
25+
}
26+
}
27+
}
28+
}
29+
30+
#endif

media/config.po

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
game-nuggets = 2
1+
game-nuggets = 1000
22
game-nugget-model = props/beacon.md3
33
game-nugget-texture = props/beacon.png
44

notizen.org

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
- Zwei Fixes für raycastvehicle: http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=2047&hilit=rolling+friction
44
- Frustum/Occlusion culling: http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=3896
55
- Vehicles in Bullet
6+
7+
* Kurzzeitvorgehen
8+
9+
- physics::object bekommt ein neues Attribut "visible" mit Getter und Setter
10+
- physics::world bekommt eine dbvtBroadphase verpasst
11+
- physics::world bekommt update_visibility, was zunächst die Frustum
12+
Planes aus der Perspektivmatrix der Kamera extrahiert.
13+
- Dann wird die Schleife aus Bullet ausgeführt und vom broadphaseproxy
14+
zum body zum object gegangen und dort die Visibility entsprechend
15+
gesetzt
616

717
* Aktivitäten
818
** TODO Nebel
@@ -148,3 +158,4 @@ noch überlegen.
148158
*** TODO foldl in gameover durch accumulate ersetzen
149159
*** TODO vehicle::speed_kmh muss relativ zu forward sein
150160
*** TODO shape_from_model erweitern
161+
*** TODO gizmo in math verfrachten

0 commit comments

Comments
 (0)