forked from Kolyah35/minecraft-pe-0.6.1
the whole game
This commit is contained in:
29
src/client/renderer/culling/AllowAllCuller.h
Executable file
29
src/client/renderer/culling/AllowAllCuller.h
Executable file
@@ -0,0 +1,29 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_RENDERER_CULLING__AllowAllCuller_H__
|
||||
#define NET_MINECRAFT_CLIENT_RENDERER_CULLING__AllowAllCuller_H__
|
||||
|
||||
//package net.minecraft.client.renderer.culling;
|
||||
|
||||
#include "Culler.h"
|
||||
|
||||
class AABB;
|
||||
|
||||
class AllowAllCuller: public Culler
|
||||
{
|
||||
public:
|
||||
bool isVisible(const AABB& bb) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cubeFullyInFrustum(float x1, float y1, float z1, float x2, float y2, float z2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cubeInFrustum(float x1, float y1, float z1, float x2, float y2, float z2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void prepare(float xOff, float yOff, float zOff) {
|
||||
}
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_RENDERER_CULLING__AllowAllCuller_H__*/
|
||||
22
src/client/renderer/culling/Culler.h
Executable file
22
src/client/renderer/culling/Culler.h
Executable file
@@ -0,0 +1,22 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_RENDERER_CULLING__Culler_H__
|
||||
#define NET_MINECRAFT_CLIENT_RENDERER_CULLING__Culler_H__
|
||||
|
||||
//package net.minecraft.client.renderer.culling;
|
||||
|
||||
class AABB;
|
||||
|
||||
class Culler
|
||||
{
|
||||
public:
|
||||
virtual ~Culler() {}
|
||||
|
||||
virtual bool isVisible(const AABB& bb) = 0;
|
||||
|
||||
virtual bool cubeInFrustum(float x0, float y0, float z0, float x1, float y1, float z1) = 0;
|
||||
|
||||
virtual bool cubeFullyInFrustum(float x0, float y0, float z0, float x1, float y1, float z1) = 0;
|
||||
|
||||
virtual void prepare(float xOff, float yOff, float zOff) {}
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_RENDERER_CULLING__Culler_H__*/
|
||||
3
src/client/renderer/culling/Frustum.cpp
Executable file
3
src/client/renderer/culling/Frustum.cpp
Executable file
@@ -0,0 +1,3 @@
|
||||
#include "Frustum.h"
|
||||
|
||||
Frustum Frustum::frustum;
|
||||
163
src/client/renderer/culling/Frustum.h
Executable file
163
src/client/renderer/culling/Frustum.h
Executable file
@@ -0,0 +1,163 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_RENDERER_CULLING__Frustum_H__
|
||||
#define NET_MINECRAFT_CLIENT_RENDERER_CULLING__Frustum_H__
|
||||
|
||||
//package net.minecraft.client.renderer.culling;
|
||||
|
||||
/* import static org.lwjgl.opengl.GL11.* */
|
||||
|
||||
|
||||
// 1) Stolen and ported to java from the web somewhere.
|
||||
// 2) ... and then ported back to C++!
|
||||
|
||||
//***********************************************************************//
|
||||
// //
|
||||
// - "Talk to me like I'm a 3 year old!" Programming Lessons - //
|
||||
// //
|
||||
// $Author: DigiBen digiben@gametutorials.com //
|
||||
// //
|
||||
// $Program: Frustum Culling //
|
||||
// //
|
||||
// $Description: Demonstrates checking if shapes are in view //
|
||||
// //
|
||||
// $Date: 8/28/01 //
|
||||
// //
|
||||
//***********************************************************************//
|
||||
|
||||
//#include "main.h"
|
||||
|
||||
#include "FrustumData.h"
|
||||
#include "../../../util/Mth.h"
|
||||
#include "../gles.h"
|
||||
|
||||
class Frustum: public FrustumData
|
||||
{
|
||||
private:
|
||||
static Frustum frustum;
|
||||
|
||||
public:
|
||||
static FrustumData& getFrustum() {
|
||||
frustum.calculateFrustum();
|
||||
return frustum;
|
||||
}
|
||||
|
||||
///////////////////////////////// NORMALIZE PLANE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
|
||||
/////
|
||||
///// This normalizes a plane (A side) from a given frustum.
|
||||
/////
|
||||
///////////////////////////////// NORMALIZE PLANE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
|
||||
private:
|
||||
void normalizePlane(float frustum[16][16], int side)
|
||||
{
|
||||
// Here we calculate the magnitude of the normal to the plane (point A B C)
|
||||
// Remember that (A, B, C) is that same thing as the normal's (X, Y, Z).
|
||||
// To calculate magnitude you use the equation: magnitude = sqrt( x^2 + y^2 + z^2)
|
||||
float invMagnitude = Mth::invSqrt(frustum[side][A] * frustum[side][A] + frustum[side][B] * frustum[side][B] + frustum[side][C] * frustum[side][C]);
|
||||
|
||||
// Then we divide the plane's values by it's magnitude.
|
||||
// This makes it easier to work with.
|
||||
frustum[side][A] *= invMagnitude;
|
||||
frustum[side][B] *= invMagnitude;
|
||||
frustum[side][C] *= invMagnitude;
|
||||
frustum[side][D] *= invMagnitude;
|
||||
}
|
||||
|
||||
float _proj[16];
|
||||
float _modl[16];
|
||||
float _clip[16];
|
||||
|
||||
void calculateFrustum()
|
||||
{
|
||||
// glGetFloatv() is used to extract information about our OpenGL world.
|
||||
// Below, we pass in GL_PROJECTION_MATRIX to abstract our projection matrix.
|
||||
// It then stores the matrix into an array of [16].
|
||||
glGetFloatv(GL_PROJECTION_MATRIX, proj);
|
||||
|
||||
// By passing in GL_MODELVIEW_MATRIX, we can abstract our model view matrix.
|
||||
// This also stores it in an array of [16].
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, modl);
|
||||
// Now that we have our modelview and projection matrix, if we combine these 2 matrices,
|
||||
// it will give us our clipping planes. To combine 2 matrices, we multiply them.
|
||||
|
||||
clip[0] = modl[0] * proj[0] + modl[1] * proj[4] + modl[2] * proj[8] + modl[3] * proj[12];
|
||||
clip[1] = modl[0] * proj[1] + modl[1] * proj[5] + modl[2] * proj[9] + modl[3] * proj[13];
|
||||
clip[2] = modl[0] * proj[2] + modl[1] * proj[6] + modl[2] * proj[10] + modl[3] * proj[14];
|
||||
clip[3] = modl[0] * proj[3] + modl[1] * proj[7] + modl[2] * proj[11] + modl[3] * proj[15];
|
||||
|
||||
clip[4] = modl[4] * proj[0] + modl[5] * proj[4] + modl[6] * proj[8] + modl[7] * proj[12];
|
||||
clip[5] = modl[4] * proj[1] + modl[5] * proj[5] + modl[6] * proj[9] + modl[7] * proj[13];
|
||||
clip[6] = modl[4] * proj[2] + modl[5] * proj[6] + modl[6] * proj[10] + modl[7] * proj[14];
|
||||
clip[7] = modl[4] * proj[3] + modl[5] * proj[7] + modl[6] * proj[11] + modl[7] * proj[15];
|
||||
|
||||
clip[8] = modl[8] * proj[0] + modl[9] * proj[4] + modl[10] * proj[8] + modl[11] * proj[12];
|
||||
clip[9] = modl[8] * proj[1] + modl[9] * proj[5] + modl[10] * proj[9] + modl[11] * proj[13];
|
||||
clip[10] = modl[8] * proj[2] + modl[9] * proj[6] + modl[10] * proj[10] + modl[11] * proj[14];
|
||||
clip[11] = modl[8] * proj[3] + modl[9] * proj[7] + modl[10] * proj[11] + modl[11] * proj[15];
|
||||
|
||||
clip[12] = modl[12] * proj[0] + modl[13] * proj[4] + modl[14] * proj[8] + modl[15] * proj[12];
|
||||
clip[13] = modl[12] * proj[1] + modl[13] * proj[5] + modl[14] * proj[9] + modl[15] * proj[13];
|
||||
clip[14] = modl[12] * proj[2] + modl[13] * proj[6] + modl[14] * proj[10] + modl[15] * proj[14];
|
||||
clip[15] = modl[12] * proj[3] + modl[13] * proj[7] + modl[14] * proj[11] + modl[15] * proj[15];
|
||||
|
||||
// Now we actually want to get the sides of the frustum. To do this we take
|
||||
// the clipping planes we received above and extract the sides from them.
|
||||
|
||||
// This will extract the RIGHT side of the frustum
|
||||
m_Frustum[RIGHT][A] = clip[3] - clip[0];
|
||||
m_Frustum[RIGHT][B] = clip[7] - clip[4];
|
||||
m_Frustum[RIGHT][C] = clip[11] - clip[8];
|
||||
m_Frustum[RIGHT][D] = clip[15] - clip[12];
|
||||
|
||||
// Now that we have a normal (A,B,C) and a distance (D) to the plane,
|
||||
// we want to normalize that normal and distance.
|
||||
|
||||
// Normalize the RIGHT side
|
||||
normalizePlane(m_Frustum, RIGHT);
|
||||
|
||||
// This will extract the LEFT side of the frustum
|
||||
m_Frustum[LEFT][A] = clip[3] + clip[0];
|
||||
m_Frustum[LEFT][B] = clip[7] + clip[4];
|
||||
m_Frustum[LEFT][C] = clip[11] + clip[8];
|
||||
m_Frustum[LEFT][D] = clip[15] + clip[12];
|
||||
|
||||
// Normalize the LEFT side
|
||||
normalizePlane(m_Frustum, LEFT);
|
||||
|
||||
// This will extract the BOTTOM side of the frustum
|
||||
m_Frustum[BOTTOM][A] = clip[3] + clip[1];
|
||||
m_Frustum[BOTTOM][B] = clip[7] + clip[5];
|
||||
m_Frustum[BOTTOM][C] = clip[11] + clip[9];
|
||||
m_Frustum[BOTTOM][D] = clip[15] + clip[13];
|
||||
|
||||
// Normalize the BOTTOM side
|
||||
normalizePlane(m_Frustum, BOTTOM);
|
||||
|
||||
// This will extract the TOP side of the frustum
|
||||
m_Frustum[TOP][A] = clip[3] - clip[1];
|
||||
m_Frustum[TOP][B] = clip[7] - clip[5];
|
||||
m_Frustum[TOP][C] = clip[11] - clip[9];
|
||||
m_Frustum[TOP][D] = clip[15] - clip[13];
|
||||
|
||||
// Normalize the TOP side
|
||||
normalizePlane(m_Frustum, TOP);
|
||||
|
||||
// This will extract the BACK side of the frustum
|
||||
m_Frustum[BACK][A] = clip[3] - clip[2];
|
||||
m_Frustum[BACK][B] = clip[7] - clip[6];
|
||||
m_Frustum[BACK][C] = clip[11] - clip[10];
|
||||
m_Frustum[BACK][D] = clip[15] - clip[14];
|
||||
|
||||
// Normalize the BACK side
|
||||
normalizePlane(m_Frustum, BACK);
|
||||
|
||||
// This will extract the FRONT side of the frustum
|
||||
m_Frustum[FRONT][A] = clip[3] + clip[2];
|
||||
m_Frustum[FRONT][B] = clip[7] + clip[6];
|
||||
m_Frustum[FRONT][C] = clip[11] + clip[10];
|
||||
m_Frustum[FRONT][D] = clip[15] + clip[14];
|
||||
|
||||
// Normalize the FRONT side
|
||||
normalizePlane(m_Frustum, FRONT);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_RENDERER_CULLING__Frustum_H__*/
|
||||
39
src/client/renderer/culling/FrustumCuller.h
Executable file
39
src/client/renderer/culling/FrustumCuller.h
Executable file
@@ -0,0 +1,39 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_RENDERER_CULLING__FrustumCuller_H__
|
||||
#define NET_MINECRAFT_CLIENT_RENDERER_CULLING__FrustumCuller_H__
|
||||
|
||||
//package net.minecraft.client.renderer.culling;
|
||||
|
||||
#include "FrustumData.h"
|
||||
#include "Frustum.h"
|
||||
|
||||
class FrustumCuller: public Culler {
|
||||
|
||||
private:
|
||||
FrustumData frustum;
|
||||
float xOff, yOff, zOff;
|
||||
|
||||
public:
|
||||
FrustumCuller() {
|
||||
frustum = Frustum::getFrustum();
|
||||
}
|
||||
|
||||
void prepare(float xOff, float yOff, float zOff) {
|
||||
this->xOff = xOff;
|
||||
this->yOff = yOff;
|
||||
this->zOff = zOff;
|
||||
}
|
||||
|
||||
bool cubeFullyInFrustum(float x0, float y0, float z0, float x1, float y1, float z1) {
|
||||
return frustum.cubeFullyInFrustum(x0 - xOff, y0 - yOff, z0 - zOff, x1 - xOff, y1 - yOff, z1 - zOff);
|
||||
}
|
||||
|
||||
bool cubeInFrustum(float x0, float y0, float z0, float x1, float y1, float z1) {
|
||||
return frustum.cubeInFrustum(x0 - xOff, y0 - yOff, z0 - zOff, x1 - xOff, y1 - yOff, z1 - zOff);
|
||||
}
|
||||
|
||||
bool isVisible(const AABB& bb) {
|
||||
return cubeInFrustum(bb.x0, bb.y0, bb.z0, bb.x1, bb.y1, bb.z1);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_RENDERER_CULLING__FrustumCuller_H__*/
|
||||
97
src/client/renderer/culling/FrustumData.h
Executable file
97
src/client/renderer/culling/FrustumData.h
Executable file
@@ -0,0 +1,97 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_RENDERER_CULLING__FrustumData_H__
|
||||
#define NET_MINECRAFT_CLIENT_RENDERER_CULLING__FrustumData_H__
|
||||
|
||||
//package net.minecraft.client.renderer.culling;
|
||||
|
||||
#include "../../../world/phys/AABB.h"
|
||||
|
||||
// We create an enum of the sides so we don't have to call each side 0 or 1.
|
||||
// This way it makes it more understandable and readable when dealing with frustum sides.
|
||||
class FrustumData
|
||||
{
|
||||
public:
|
||||
//enum FrustumSide
|
||||
static const int RIGHT = 0; // The RIGHT side of the frustum
|
||||
static const int LEFT = 1; // The LEFT side of the frustum
|
||||
static const int BOTTOM = 2; // The BOTTOM side of the frustum
|
||||
static const int TOP = 3; // The TOP side of the frustum
|
||||
static const int BACK = 4; // The BACK side of the frustum
|
||||
static const int FRONT = 5; // The FRONT side of the frustum
|
||||
|
||||
// Like above, instead of saying a number for the ABC and D of the plane, we
|
||||
// want to be more descriptive.
|
||||
static const int A = 0; // The X value of the plane's normal
|
||||
static const int B = 1; // The Y value of the plane's normal
|
||||
static const int C = 2; // The Z value of the plane's normal
|
||||
static const int D = 3; // The distance the plane is from the origin
|
||||
|
||||
float m_Frustum[16][16];
|
||||
float proj[16];
|
||||
float modl[16];
|
||||
float clip[16];
|
||||
|
||||
bool pointInFrustum(float x, float y, float z)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (m_Frustum[i][A] * x + m_Frustum[i][B] * y + m_Frustum[i][C] * z + m_Frustum[i][D] <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
bool sphereInFrustum(float x, float y, float z, float radius)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (m_Frustum[i][A] * x + m_Frustum[i][B] * y + m_Frustum[i][C] * z + m_Frustum[i][D] <= -radius)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
bool cubeFullyInFrustum(float x1, float y1, float z1, float x2, float y2, float z2)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (!(m_Frustum[i][A] * (x1) + m_Frustum[i][B] * (y1) + m_Frustum[i][C] * (z1) + m_Frustum[i][D] > 0)) return false;
|
||||
if (!(m_Frustum[i][A] * (x2) + m_Frustum[i][B] * (y1) + m_Frustum[i][C] * (z1) + m_Frustum[i][D] > 0)) return false;
|
||||
if (!(m_Frustum[i][A] * (x1) + m_Frustum[i][B] * (y2) + m_Frustum[i][C] * (z1) + m_Frustum[i][D] > 0)) return false;
|
||||
if (!(m_Frustum[i][A] * (x2) + m_Frustum[i][B] * (y2) + m_Frustum[i][C] * (z1) + m_Frustum[i][D] > 0)) return false;
|
||||
if (!(m_Frustum[i][A] * (x1) + m_Frustum[i][B] * (y1) + m_Frustum[i][C] * (z2) + m_Frustum[i][D] > 0)) return false;
|
||||
if (!(m_Frustum[i][A] * (x2) + m_Frustum[i][B] * (y1) + m_Frustum[i][C] * (z2) + m_Frustum[i][D] > 0)) return false;
|
||||
if (!(m_Frustum[i][A] * (x1) + m_Frustum[i][B] * (y2) + m_Frustum[i][C] * (z2) + m_Frustum[i][D] > 0)) return false;
|
||||
if (!(m_Frustum[i][A] * (x2) + m_Frustum[i][B] * (y2) + m_Frustum[i][C] * (z2) + m_Frustum[i][D] > 0)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cubeInFrustum(float x1, float y1, float z1, float x2, float y2, float z2)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (m_Frustum[i][A] * (x1) + m_Frustum[i][B] * (y1) + m_Frustum[i][C] * (z1) + m_Frustum[i][D] > 0) continue;
|
||||
if (m_Frustum[i][A] * (x2) + m_Frustum[i][B] * (y1) + m_Frustum[i][C] * (z1) + m_Frustum[i][D] > 0) continue;
|
||||
if (m_Frustum[i][A] * (x1) + m_Frustum[i][B] * (y2) + m_Frustum[i][C] * (z1) + m_Frustum[i][D] > 0) continue;
|
||||
if (m_Frustum[i][A] * (x2) + m_Frustum[i][B] * (y2) + m_Frustum[i][C] * (z1) + m_Frustum[i][D] > 0) continue;
|
||||
if (m_Frustum[i][A] * (x1) + m_Frustum[i][B] * (y1) + m_Frustum[i][C] * (z2) + m_Frustum[i][D] > 0) continue;
|
||||
if (m_Frustum[i][A] * (x2) + m_Frustum[i][B] * (y1) + m_Frustum[i][C] * (z2) + m_Frustum[i][D] > 0) continue;
|
||||
if (m_Frustum[i][A] * (x1) + m_Frustum[i][B] * (y2) + m_Frustum[i][C] * (z2) + m_Frustum[i][D] > 0) continue;
|
||||
if (m_Frustum[i][A] * (x2) + m_Frustum[i][B] * (y2) + m_Frustum[i][C] * (z2) + m_Frustum[i][D] > 0) continue;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
bool isVisible(const AABB& aabb)
|
||||
{
|
||||
return cubeInFrustum(aabb.x0, aabb.y0, aabb.z0, aabb.x1, aabb.y1, aabb.z1);
|
||||
}
|
||||
};
|
||||
#endif /*NET_MINECRAFT_CLIENT_RENDERER_CULLING__FrustumData_H__*/
|
||||
172
src/client/renderer/culling/tmp/Frustum.h
Executable file
172
src/client/renderer/culling/tmp/Frustum.h
Executable file
@@ -0,0 +1,172 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_RENDERER_CULLING__Frustum_H__
|
||||
#define NET_MINECRAFT_CLIENT_RENDERER_CULLING__Frustum_H__
|
||||
|
||||
//package net.minecraft.client.renderer.culling;
|
||||
|
||||
/* import static org.lwjgl.opengl.GL11.* */
|
||||
|
||||
#include "java/nio/FloatBuffer.h"
|
||||
|
||||
#include "client/MemoryTracker.h"
|
||||
|
||||
|
||||
// Stolen and ported to java from the web somewhere.
|
||||
|
||||
//***********************************************************************//
|
||||
// //
|
||||
// - "Talk to me like I'm a 3 year old!" Programming Lessons - //
|
||||
// //
|
||||
// $Author: DigiBen digiben@gametutorials.com //
|
||||
// //
|
||||
// $Program: Frustum Culling //
|
||||
// //
|
||||
// $Description: Demonstrates checking if shapes are in view //
|
||||
// //
|
||||
// $Date: 8/28/01 //
|
||||
// //
|
||||
//***********************************************************************//
|
||||
|
||||
//#include "main.h"
|
||||
|
||||
// We create an enum of the sides so we don't have to call each side 0 or 1.
|
||||
// This way it makes it more understandable and readable when dealing with frustum sides.
|
||||
/*public*/ class Frustum: public FrustumData
|
||||
{
|
||||
/*private*/ static Frustum frustum = /*new*/ Frustum();
|
||||
|
||||
/*public*/ static FrustumData getFrustum()
|
||||
{
|
||||
frustum.calculateFrustum();
|
||||
return frustum;
|
||||
}
|
||||
|
||||
///////////////////////////////// NORMALIZE PLANE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
|
||||
/////
|
||||
///// This normalizes a plane (A side) from a given frustum.
|
||||
/////
|
||||
///////////////////////////////// NORMALIZE PLANE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
|
||||
|
||||
/*private*/ void normalizePlane(float[][] frustum, int side)
|
||||
{
|
||||
// Here we calculate the magnitude of the normal to the plane (point A B C)
|
||||
// Remember that (A, B, C) is that same thing as the normal's (X, Y, Z).
|
||||
// To calculate magnitude you use the equation: magnitude = sqrt( x^2 + y^2 + z^2)
|
||||
float magnitude = (float) util.Mth.sqrt(frustum[side][A] * frustum[side][A] + frustum[side][B] * frustum[side][B] + frustum[side][C] * frustum[side][C]);
|
||||
|
||||
// Then we divide the plane's values by it's magnitude.
|
||||
// This makes it easier to work with.
|
||||
frustum[side][A] /= magnitude;
|
||||
frustum[side][B] /= magnitude;
|
||||
frustum[side][C] /= magnitude;
|
||||
frustum[side][D] /= magnitude;
|
||||
}
|
||||
|
||||
/*private*/ FloatBuffer _proj = MemoryTracker.createFloatBuffer(16);
|
||||
/*private*/ FloatBuffer _modl = MemoryTracker.createFloatBuffer(16);
|
||||
/*private*/ FloatBuffer _clip = MemoryTracker.createFloatBuffer(16);
|
||||
|
||||
/*private*/ void calculateFrustum()
|
||||
{
|
||||
_proj.clear();
|
||||
_modl.clear();
|
||||
_clip.clear();
|
||||
|
||||
// glGetFloatv() is used to extract information about our OpenGL world.
|
||||
// Below, we pass in GL_PROJECTION_MATRIX to abstract our projection matrix.
|
||||
// It then stores the matrix into an array of [16].
|
||||
glGetFloat(GL_PROJECTION_MATRIX, _proj);
|
||||
|
||||
// By passing in GL_MODELVIEW_MATRIX, we can abstract our model view matrix.
|
||||
// This also stores it in an array of [16].
|
||||
glGetFloat(GL_MODELVIEW_MATRIX, _modl);
|
||||
|
||||
_proj.flip().limit(16);
|
||||
_proj.get(proj);
|
||||
_modl.flip().limit(16);
|
||||
_modl.get(modl);
|
||||
|
||||
// Now that we have our modelview and projection matrix, if we combine these 2 matrices,
|
||||
// it will give us our clipping planes. To combine 2 matrices, we multiply them.
|
||||
|
||||
clip[0] = modl[0] * proj[0] + modl[1] * proj[4] + modl[2] * proj[8] + modl[3] * proj[12];
|
||||
clip[1] = modl[0] * proj[1] + modl[1] * proj[5] + modl[2] * proj[9] + modl[3] * proj[13];
|
||||
clip[2] = modl[0] * proj[2] + modl[1] * proj[6] + modl[2] * proj[10] + modl[3] * proj[14];
|
||||
clip[3] = modl[0] * proj[3] + modl[1] * proj[7] + modl[2] * proj[11] + modl[3] * proj[15];
|
||||
|
||||
clip[4] = modl[4] * proj[0] + modl[5] * proj[4] + modl[6] * proj[8] + modl[7] * proj[12];
|
||||
clip[5] = modl[4] * proj[1] + modl[5] * proj[5] + modl[6] * proj[9] + modl[7] * proj[13];
|
||||
clip[6] = modl[4] * proj[2] + modl[5] * proj[6] + modl[6] * proj[10] + modl[7] * proj[14];
|
||||
clip[7] = modl[4] * proj[3] + modl[5] * proj[7] + modl[6] * proj[11] + modl[7] * proj[15];
|
||||
|
||||
clip[8] = modl[8] * proj[0] + modl[9] * proj[4] + modl[10] * proj[8] + modl[11] * proj[12];
|
||||
clip[9] = modl[8] * proj[1] + modl[9] * proj[5] + modl[10] * proj[9] + modl[11] * proj[13];
|
||||
clip[10] = modl[8] * proj[2] + modl[9] * proj[6] + modl[10] * proj[10] + modl[11] * proj[14];
|
||||
clip[11] = modl[8] * proj[3] + modl[9] * proj[7] + modl[10] * proj[11] + modl[11] * proj[15];
|
||||
|
||||
clip[12] = modl[12] * proj[0] + modl[13] * proj[4] + modl[14] * proj[8] + modl[15] * proj[12];
|
||||
clip[13] = modl[12] * proj[1] + modl[13] * proj[5] + modl[14] * proj[9] + modl[15] * proj[13];
|
||||
clip[14] = modl[12] * proj[2] + modl[13] * proj[6] + modl[14] * proj[10] + modl[15] * proj[14];
|
||||
clip[15] = modl[12] * proj[3] + modl[13] * proj[7] + modl[14] * proj[11] + modl[15] * proj[15];
|
||||
|
||||
// Now we actually want to get the sides of the frustum. To do this we take
|
||||
// the clipping planes we received above and extract the sides from them.
|
||||
|
||||
// This will extract the RIGHT side of the frustum
|
||||
m_Frustum[RIGHT][A] = clip[3] - clip[0];
|
||||
m_Frustum[RIGHT][B] = clip[7] - clip[4];
|
||||
m_Frustum[RIGHT][C] = clip[11] - clip[8];
|
||||
m_Frustum[RIGHT][D] = clip[15] - clip[12];
|
||||
|
||||
// Now that we have a normal (A,B,C) and a distance (D) to the plane,
|
||||
// we want to normalize that normal and distance.
|
||||
|
||||
// Normalize the RIGHT side
|
||||
normalizePlane(m_Frustum, RIGHT);
|
||||
|
||||
// This will extract the LEFT side of the frustum
|
||||
m_Frustum[LEFT][A] = clip[3] + clip[0];
|
||||
m_Frustum[LEFT][B] = clip[7] + clip[4];
|
||||
m_Frustum[LEFT][C] = clip[11] + clip[8];
|
||||
m_Frustum[LEFT][D] = clip[15] + clip[12];
|
||||
|
||||
// Normalize the LEFT side
|
||||
normalizePlane(m_Frustum, LEFT);
|
||||
|
||||
// This will extract the BOTTOM side of the frustum
|
||||
m_Frustum[BOTTOM][A] = clip[3] + clip[1];
|
||||
m_Frustum[BOTTOM][B] = clip[7] + clip[5];
|
||||
m_Frustum[BOTTOM][C] = clip[11] + clip[9];
|
||||
m_Frustum[BOTTOM][D] = clip[15] + clip[13];
|
||||
|
||||
// Normalize the BOTTOM side
|
||||
normalizePlane(m_Frustum, BOTTOM);
|
||||
|
||||
// This will extract the TOP side of the frustum
|
||||
m_Frustum[TOP][A] = clip[3] - clip[1];
|
||||
m_Frustum[TOP][B] = clip[7] - clip[5];
|
||||
m_Frustum[TOP][C] = clip[11] - clip[9];
|
||||
m_Frustum[TOP][D] = clip[15] - clip[13];
|
||||
|
||||
// Normalize the TOP side
|
||||
normalizePlane(m_Frustum, TOP);
|
||||
|
||||
// This will extract the BACK side of the frustum
|
||||
m_Frustum[BACK][A] = clip[3] - clip[2];
|
||||
m_Frustum[BACK][B] = clip[7] - clip[6];
|
||||
m_Frustum[BACK][C] = clip[11] - clip[10];
|
||||
m_Frustum[BACK][D] = clip[15] - clip[14];
|
||||
|
||||
// Normalize the BACK side
|
||||
normalizePlane(m_Frustum, BACK);
|
||||
|
||||
// This will extract the FRONT side of the frustum
|
||||
m_Frustum[FRONT][A] = clip[3] + clip[2];
|
||||
m_Frustum[FRONT][B] = clip[7] + clip[6];
|
||||
m_Frustum[FRONT][C] = clip[11] + clip[10];
|
||||
m_Frustum[FRONT][D] = clip[15] + clip[14];
|
||||
|
||||
// Normalize the FRONT side
|
||||
normalizePlane(m_Frustum, FRONT);
|
||||
}
|
||||
}
|
||||
#endif /*NET_MINECRAFT_CLIENT_RENDERER_CULLING__Frustum_H__*/
|
||||
165
src/client/renderer/culling/tmp/FrustumCuller.h
Executable file
165
src/client/renderer/culling/tmp/FrustumCuller.h
Executable file
@@ -0,0 +1,165 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_RENDERER_CULLING__FrustumCuller_H__
|
||||
#define NET_MINECRAFT_CLIENT_RENDERER_CULLING__FrustumCuller_H__
|
||||
|
||||
//package net.minecraft.client.renderer.culling;
|
||||
|
||||
#include "Culler.h"
|
||||
#include "../../../world/phys/AABB.h"
|
||||
|
||||
class FrustumCuller: public Culler
|
||||
{
|
||||
float xOff, yOff, zOff;
|
||||
float frustum[6][4];
|
||||
|
||||
public:
|
||||
FrustumCuller() {
|
||||
ExtractFrustum();
|
||||
}
|
||||
|
||||
void prepare(float xOff, float yOff, float zOff) {
|
||||
this->xOff = xOff;
|
||||
this->yOff = yOff;
|
||||
this->zOff = zOff;
|
||||
}
|
||||
|
||||
//bool cubeFullyInFrustum(float x0, float y0, float z0, float x1, float y1, float z1) {
|
||||
// return frustum.cubeFullyInFrustum(x0 - xOff, y0 - yOff, z0 - zOff, x1 - xOff, y1 - yOff, z1 - zOff);
|
||||
//}
|
||||
|
||||
bool cubeFullyInFrustum( float x0, float y0, float z0, float x1, float y1, float z1 ) {
|
||||
int c2 = 0;
|
||||
for( int p = 0; p < 6; p++ ) {
|
||||
int c = 0;
|
||||
if( frustum[p][0] * (x0) + frustum[p][1] * (y0) + frustum[p][2] * (z0) + frustum[p][3] > 0 ) c++;
|
||||
if( frustum[p][0] * (x1) + frustum[p][1] * (y0) + frustum[p][2] * (z0) + frustum[p][3] > 0 ) c++;
|
||||
if( frustum[p][0] * (x0) + frustum[p][1] * (y1) + frustum[p][2] * (z0) + frustum[p][3] > 0 ) c++;
|
||||
if( frustum[p][0] * (x1) + frustum[p][1] * (y1) + frustum[p][2] * (z0) + frustum[p][3] > 0 ) c++;
|
||||
if( frustum[p][0] * (x0) + frustum[p][1] * (y0) + frustum[p][2] * (z1) + frustum[p][3] > 0 ) c++;
|
||||
if( frustum[p][0] * (x1) + frustum[p][1] * (y0) + frustum[p][2] * (z1) + frustum[p][3] > 0 ) c++;
|
||||
if( frustum[p][0] * (x0) + frustum[p][1] * (y1) + frustum[p][2] * (z1) + frustum[p][3] > 0 ) c++;
|
||||
if( frustum[p][0] * (x1) + frustum[p][1] * (y1) + frustum[p][2] * (z1) + frustum[p][3] > 0 ) c++;
|
||||
if( c == 0 )
|
||||
return false; // 0
|
||||
if( c == 8 )
|
||||
c2++;
|
||||
}
|
||||
return c2 == 6; //(c2 == 6) ? 2 : 1;
|
||||
}
|
||||
|
||||
bool isVisible(const AABB& bb) {
|
||||
printf("cube is : %s\n", bb.toString().c_str());
|
||||
return cubeInFrustum(bb.x0, bb.y0, bb.z0, bb.x1, bb.y1, bb.z1);
|
||||
}
|
||||
|
||||
bool cubeInFrustum(float x0, float y0, float z0, float x1, float y1, float z1) {
|
||||
for(int p = 0; p < 6; p++ ) {
|
||||
if( frustum[p][0] * (x0) + frustum[p][1] * (y0) + frustum[p][2] * (z0) + frustum[p][3] > 0 ) continue;
|
||||
if( frustum[p][0] * (x1) + frustum[p][1] * (y0) + frustum[p][2] * (z0) + frustum[p][3] > 0 ) continue;
|
||||
if( frustum[p][0] * (x0) + frustum[p][1] * (y1) + frustum[p][2] * (z0) + frustum[p][3] > 0 ) continue;
|
||||
if( frustum[p][0] * (x1) + frustum[p][1] * (y1) + frustum[p][2] * (z0) + frustum[p][3] > 0 ) continue;
|
||||
if( frustum[p][0] * (x0) + frustum[p][1] * (y0) + frustum[p][2] * (z1) + frustum[p][3] > 0 ) continue;
|
||||
if( frustum[p][0] * (x1) + frustum[p][1] * (y0) + frustum[p][2] * (z1) + frustum[p][3] > 0 ) continue;
|
||||
if( frustum[p][0] * (x0) + frustum[p][1] * (y1) + frustum[p][2] * (z1) + frustum[p][3] > 0 ) continue;
|
||||
if( frustum[p][0] * (x1) + frustum[p][1] * (y1) + frustum[p][2] * (z1) + frustum[p][3] > 0 ) continue;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
void ExtractFrustum() {
|
||||
float proj[16];
|
||||
float modl[16];
|
||||
float clip[16];
|
||||
float t;
|
||||
/* Get the current PROJECTION matrix from OpenGL */
|
||||
glGetFloatv( GL_PROJECTION_MATRIX, proj );
|
||||
/* Get the current MODELVIEW matrix from OpenGL */
|
||||
glGetFloatv( GL_MODELVIEW_MATRIX, modl );
|
||||
/* Combine the two matrices (multiply projection by modelview) */
|
||||
clip[ 0] = modl[ 0] * proj[ 0] + modl[ 1] * proj[ 4] + modl[ 2] * proj[ 8] + modl[ 3] * proj[12];
|
||||
clip[ 1] = modl[ 0] * proj[ 1] + modl[ 1] * proj[ 5] + modl[ 2] * proj[ 9] + modl[ 3] * proj[13];
|
||||
clip[ 2] = modl[ 0] * proj[ 2] + modl[ 1] * proj[ 6] + modl[ 2] * proj[10] + modl[ 3] * proj[14];
|
||||
clip[ 3] = modl[ 0] * proj[ 3] + modl[ 1] * proj[ 7] + modl[ 2] * proj[11] + modl[ 3] * proj[15];
|
||||
clip[ 4] = modl[ 4] * proj[ 0] + modl[ 5] * proj[ 4] + modl[ 6] * proj[ 8] + modl[ 7] * proj[12];
|
||||
clip[ 5] = modl[ 4] * proj[ 1] + modl[ 5] * proj[ 5] + modl[ 6] * proj[ 9] + modl[ 7] * proj[13];
|
||||
clip[ 6] = modl[ 4] * proj[ 2] + modl[ 5] * proj[ 6] + modl[ 6] * proj[10] + modl[ 7] * proj[14];
|
||||
clip[ 7] = modl[ 4] * proj[ 3] + modl[ 5] * proj[ 7] + modl[ 6] * proj[11] + modl[ 7] * proj[15];
|
||||
clip[ 8] = modl[ 8] * proj[ 0] + modl[ 9] * proj[ 4] + modl[10] * proj[ 8] + modl[11] * proj[12];
|
||||
clip[ 9] = modl[ 8] * proj[ 1] + modl[ 9] * proj[ 5] + modl[10] * proj[ 9] + modl[11] * proj[13];
|
||||
clip[10] = modl[ 8] * proj[ 2] + modl[ 9] * proj[ 6] + modl[10] * proj[10] + modl[11] * proj[14];
|
||||
clip[11] = modl[ 8] * proj[ 3] + modl[ 9] * proj[ 7] + modl[10] * proj[11] + modl[11] * proj[15];
|
||||
clip[12] = modl[12] * proj[ 0] + modl[13] * proj[ 4] + modl[14] * proj[ 8] + modl[15] * proj[12];
|
||||
clip[13] = modl[12] * proj[ 1] + modl[13] * proj[ 5] + modl[14] * proj[ 9] + modl[15] * proj[13];
|
||||
clip[14] = modl[12] * proj[ 2] + modl[13] * proj[ 6] + modl[14] * proj[10] + modl[15] * proj[14];
|
||||
clip[15] = modl[12] * proj[ 3] + modl[13] * proj[ 7] + modl[14] * proj[11] + modl[15] * proj[15];
|
||||
/* Extract the numbers for the RIGHT plane */
|
||||
frustum[0][0] = clip[ 3] - clip[ 0];
|
||||
frustum[0][1] = clip[ 7] - clip[ 4];
|
||||
frustum[0][2] = clip[11] - clip[ 8];
|
||||
frustum[0][3] = clip[15] - clip[12];
|
||||
/* Normalize the result */
|
||||
t = sqrt( frustum[0][0] * frustum[0][0] + frustum[0][1] * frustum[0][1] + frustum[0][2] * frustum[0][2] );
|
||||
frustum[0][0] /= t;
|
||||
frustum[0][1] /= t;
|
||||
frustum[0][2] /= t;
|
||||
frustum[0][3] /= t;
|
||||
/* Extract the numbers for the LEFT plane */
|
||||
frustum[1][0] = clip[ 3] + clip[ 0];
|
||||
frustum[1][1] = clip[ 7] + clip[ 4];
|
||||
frustum[1][2] = clip[11] + clip[ 8];
|
||||
frustum[1][3] = clip[15] + clip[12];
|
||||
/* Normalize the result */
|
||||
t = sqrt( frustum[1][0] * frustum[1][0] + frustum[1][1] * frustum[1][1] + frustum[1][2] * frustum[1][2] );
|
||||
frustum[1][0] /= t;
|
||||
frustum[1][1] /= t;
|
||||
frustum[1][2] /= t;
|
||||
frustum[1][3] /= t;
|
||||
/* Extract the BOTTOM plane */
|
||||
frustum[2][0] = clip[ 3] + clip[ 1];
|
||||
frustum[2][1] = clip[ 7] + clip[ 5];
|
||||
frustum[2][2] = clip[11] + clip[ 9];
|
||||
frustum[2][3] = clip[15] + clip[13];
|
||||
/* Normalize the result */
|
||||
t = sqrt( frustum[2][0] * frustum[2][0] + frustum[2][1] * frustum[2][1] + frustum[2][2] * frustum[2][2] );
|
||||
frustum[2][0] /= t;
|
||||
frustum[2][1] /= t;
|
||||
frustum[2][2] /= t;
|
||||
frustum[2][3] /= t;
|
||||
/* Extract the TOP plane */
|
||||
frustum[3][0] = clip[ 3] - clip[ 1];
|
||||
frustum[3][1] = clip[ 7] - clip[ 5];
|
||||
frustum[3][2] = clip[11] - clip[ 9];
|
||||
frustum[3][3] = clip[15] - clip[13];
|
||||
/* Normalize the result */
|
||||
t = sqrt( frustum[3][0] * frustum[3][0] + frustum[3][1] * frustum[3][1] + frustum[3][2] * frustum[3][2] );
|
||||
frustum[3][0] /= t;
|
||||
frustum[3][1] /= t;
|
||||
frustum[3][2] /= t;
|
||||
frustum[3][3] /= t;
|
||||
/* Extract the FAR plane */
|
||||
frustum[4][0] = clip[ 3] - clip[ 2];
|
||||
frustum[4][1] = clip[ 7] - clip[ 6];
|
||||
frustum[4][2] = clip[11] - clip[10];
|
||||
frustum[4][3] = clip[15] - clip[14];
|
||||
/* Normalize the result */
|
||||
t = sqrt( frustum[4][0] * frustum[4][0] + frustum[4][1] * frustum[4][1] + frustum[4][2] * frustum[4][2] );
|
||||
frustum[4][0] /= t;
|
||||
frustum[4][1] /= t;
|
||||
frustum[4][2] /= t;
|
||||
frustum[4][3] /= t;
|
||||
/* Extract the NEAR plane */
|
||||
frustum[5][0] = clip[ 3] + clip[ 2];
|
||||
frustum[5][1] = clip[ 7] + clip[ 6];
|
||||
frustum[5][2] = clip[11] + clip[10];
|
||||
frustum[5][3] = clip[15] + clip[14];
|
||||
/* Normalize the result */
|
||||
t = sqrt( frustum[5][0] * frustum[5][0] + frustum[5][1] * frustum[5][1] + frustum[5][2] * frustum[5][2] );
|
||||
frustum[5][0] /= t;
|
||||
frustum[5][1] /= t;
|
||||
frustum[5][2] /= t;
|
||||
frustum[5][3] /= t;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_RENDERER_CULLING__FrustumCuller_H__*/
|
||||
102
src/client/renderer/culling/tmp/FrustumData.h
Executable file
102
src/client/renderer/culling/tmp/FrustumData.h
Executable file
@@ -0,0 +1,102 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_RENDERER_CULLING__FrustumData_H__
|
||||
#define NET_MINECRAFT_CLIENT_RENDERER_CULLING__FrustumData_H__
|
||||
|
||||
//package net.minecraft.client.renderer.culling;
|
||||
|
||||
#include "world/phys/AABB.h"
|
||||
|
||||
|
||||
/*public*/ class FrustumData
|
||||
{
|
||||
//enum FrustumSide
|
||||
/*public*/ static const int RIGHT = 0; // The RIGHT side of the frustum
|
||||
/*public*/ static const int LEFT = 1; // The LEFT side of the frustum
|
||||
/*public*/ static const int BOTTOM = 2; // The BOTTOM side of the frustum
|
||||
/*public*/ static const int TOP = 3; // The TOP side of the frustum
|
||||
/*public*/ static const int BACK = 4; // The BACK side of the frustum
|
||||
/*public*/ static const int FRONT = 5; // The FRONT side of the frustum
|
||||
|
||||
// Like above, instead of saying a number for the ABC and D of the plane, we
|
||||
// want to be more descriptive.
|
||||
/*public*/ static const int A = 0; // The X value of the plane's normal
|
||||
/*public*/ static const int B = 1; // The Y value of the plane's normal
|
||||
/*public*/ static const int C = 2; // The Z value of the plane's normal
|
||||
/*public*/ static const int D = 3; // The distance the plane is from the origin
|
||||
|
||||
/*public*/ float** m_Frustum; // = /*new*/ float[16][16];
|
||||
/*public*/ float* proj; // = /*new*/ float[16];
|
||||
/*public*/ float* modl; // = /*new*/ float[16];
|
||||
/*public*/ float* clip; // = /*new*/ float[16];
|
||||
/*
|
||||
/*public*/ FrustumData(float** mFrustum, float* proj, float* modl, float* clip)
|
||||
{
|
||||
m_Frustum = mFrustum;
|
||||
this->proj = proj;
|
||||
this->modl = modl;
|
||||
this->clip = clip;
|
||||
}
|
||||
/*public*/ bool pointInFrustum(float x, float y, float z)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (m_Frustum[i][A] * x + m_Frustum[i][B] * y + m_Frustum[i][C] * z + m_Frustum[i][D] <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
/*public*/ bool sphereInFrustum(float x, float y, float z, float radius)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (m_Frustum[i][A] * x + m_Frustum[i][B] * y + m_Frustum[i][C] * z + m_Frustum[i][D] <= -radius)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
/*public*/ bool cubeFullyInFrustum(float x1, float y1, float z1, float x2, float y2, float z2)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (!(m_Frustum[i][A] * (x1) + m_Frustum[i][B] * (y1) + m_Frustum[i][C] * (z1) + m_Frustum[i][D] > 0)) return false;
|
||||
if (!(m_Frustum[i][A] * (x2) + m_Frustum[i][B] * (y1) + m_Frustum[i][C] * (z1) + m_Frustum[i][D] > 0)) return false;
|
||||
if (!(m_Frustum[i][A] * (x1) + m_Frustum[i][B] * (y2) + m_Frustum[i][C] * (z1) + m_Frustum[i][D] > 0)) return false;
|
||||
if (!(m_Frustum[i][A] * (x2) + m_Frustum[i][B] * (y2) + m_Frustum[i][C] * (z1) + m_Frustum[i][D] > 0)) return false;
|
||||
if (!(m_Frustum[i][A] * (x1) + m_Frustum[i][B] * (y1) + m_Frustum[i][C] * (z2) + m_Frustum[i][D] > 0)) return false;
|
||||
if (!(m_Frustum[i][A] * (x2) + m_Frustum[i][B] * (y1) + m_Frustum[i][C] * (z2) + m_Frustum[i][D] > 0)) return false;
|
||||
if (!(m_Frustum[i][A] * (x1) + m_Frustum[i][B] * (y2) + m_Frustum[i][C] * (z2) + m_Frustum[i][D] > 0)) return false;
|
||||
if (!(m_Frustum[i][A] * (x2) + m_Frustum[i][B] * (y2) + m_Frustum[i][C] * (z2) + m_Frustum[i][D] > 0)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*public*/ bool cubeInFrustum(float x1, float y1, float z1, float x2, float y2, float z2)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (m_Frustum[i][A] * (x1) + m_Frustum[i][B] * (y1) + m_Frustum[i][C] * (z1) + m_Frustum[i][D] > 0) continue;
|
||||
if (m_Frustum[i][A] * (x2) + m_Frustum[i][B] * (y1) + m_Frustum[i][C] * (z1) + m_Frustum[i][D] > 0) continue;
|
||||
if (m_Frustum[i][A] * (x1) + m_Frustum[i][B] * (y2) + m_Frustum[i][C] * (z1) + m_Frustum[i][D] > 0) continue;
|
||||
if (m_Frustum[i][A] * (x2) + m_Frustum[i][B] * (y2) + m_Frustum[i][C] * (z1) + m_Frustum[i][D] > 0) continue;
|
||||
if (m_Frustum[i][A] * (x1) + m_Frustum[i][B] * (y1) + m_Frustum[i][C] * (z2) + m_Frustum[i][D] > 0) continue;
|
||||
if (m_Frustum[i][A] * (x2) + m_Frustum[i][B] * (y1) + m_Frustum[i][C] * (z2) + m_Frustum[i][D] > 0) continue;
|
||||
if (m_Frustum[i][A] * (x1) + m_Frustum[i][B] * (y2) + m_Frustum[i][C] * (z2) + m_Frustum[i][D] > 0) continue;
|
||||
if (m_Frustum[i][A] * (x2) + m_Frustum[i][B] * (y2) + m_Frustum[i][C] * (z2) + m_Frustum[i][D] > 0) continue;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
/*public*/ bool isVisible(AABB aabb)
|
||||
{
|
||||
return cubeInFrustum(aabb.x0, aabb.y0, aabb.z0, aabb.x1, aabb.y1, aabb.z1);
|
||||
}
|
||||
}
|
||||
#endif /*NET_MINECRAFT_CLIENT_RENDERER_CULLING__FrustumData_H__*/
|
||||
37
src/client/renderer/culling/tmp/_FrustumCuller.h
Executable file
37
src/client/renderer/culling/tmp/_FrustumCuller.h
Executable file
@@ -0,0 +1,37 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_RENDERER_CULLING__FrustumCuller_H__
|
||||
#define NET_MINECRAFT_CLIENT_RENDERER_CULLING__FrustumCuller_H__
|
||||
|
||||
//package net.minecraft.client.renderer.culling;
|
||||
|
||||
#include "world/phys/AABB.h"
|
||||
|
||||
/*public*/ class FrustumCuller: /*implements-interface*/ public Culler {
|
||||
|
||||
/*private*/ FrustumData frustum;
|
||||
|
||||
/*public*/ FrustumCuller() {
|
||||
frustum = Frustum.getFrustum();
|
||||
}
|
||||
|
||||
/*private*/ float xOff, yOff, zOff;
|
||||
|
||||
/*public*/ void prepare(float xOff, float yOff, float zOff) {
|
||||
this->xOff = xOff;
|
||||
this->yOff = yOff;
|
||||
this->zOff = zOff;
|
||||
}
|
||||
|
||||
/*public*/ bool cubeFullyInFrustum(float x0, float y0, float z0, float x1, float y1, float z1) {
|
||||
return frustum.cubeFullyInFrustum(x0 - xOff, y0 - yOff, z0 - zOff, x1 - xOff, y1 - yOff, z1 - zOff);
|
||||
}
|
||||
|
||||
/*public*/ bool cubeInFrustum(float x0, float y0, float z0, float x1, float y1, float z1) {
|
||||
return frustum.cubeInFrustum(x0 - xOff, y0 - yOff, z0 - zOff, x1 - xOff, y1 - yOff, z1 - zOff);
|
||||
}
|
||||
|
||||
/*public*/ bool isVisible(AABB bb) {
|
||||
return cubeInFrustum(bb.x0, bb.y0, bb.z0, bb.x1, bb.y1, bb.z1);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_RENDERER_CULLING__FrustumCuller_H__*/
|
||||
Reference in New Issue
Block a user