mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-04 09:59:44 -05:00
Redefine x resolution and y resolution to be the number of grid cells in each direction.
This commit is contained in:
@@ -79,11 +79,11 @@ void BasicGrid::validate(int xRes, int yRes) {
|
||||
}
|
||||
|
||||
inline size_t BasicGrid::numElements(int xRes, int yRes){
|
||||
return 3 * 2 * (xRes - 1)*(yRes - 1);
|
||||
return 3 * 2 * xRes * yRes;
|
||||
}
|
||||
|
||||
inline size_t BasicGrid::numVertices(int xRes, int yRes) {
|
||||
return xRes * yRes;
|
||||
return (xRes + 1) * (yRes + 1);
|
||||
}
|
||||
|
||||
std::vector<GLuint> BasicGrid::CreateElements(int xRes, int yRes) {
|
||||
@@ -91,8 +91,8 @@ std::vector<GLuint> BasicGrid::CreateElements(int xRes, int yRes) {
|
||||
|
||||
std::vector<GLuint> elements;
|
||||
elements.reserve(numElements(xRes, yRes));
|
||||
for (unsigned int y = 0; y < yRes-1; y++) {
|
||||
for (unsigned int x = 0; x < xRes-1; x++) {
|
||||
for (unsigned int y = 0; y < yRes; y++) {
|
||||
for (unsigned int x = 0; x < xRes; x++) {
|
||||
|
||||
// x v01---v11 x ..
|
||||
// | / |
|
||||
@@ -101,10 +101,10 @@ std::vector<GLuint> BasicGrid::CreateElements(int xRes, int yRes) {
|
||||
// x x x x ..
|
||||
// : : : :
|
||||
|
||||
GLuint v00 = (y + 0) * xRes + x + 0;
|
||||
GLuint v10 = (y + 0) * xRes + x + 1;
|
||||
GLuint v01 = (y + 1) * xRes + x + 0;
|
||||
GLuint v11 = (y + 1) * xRes + x + 1;
|
||||
GLuint v00 = (y + 0) * (xRes + 1) + x + 0;
|
||||
GLuint v10 = (y + 0) * (xRes + 1) + x + 1;
|
||||
GLuint v01 = (y + 1) * (xRes + 1) + x + 0;
|
||||
GLuint v11 = (y + 1) * (xRes + 1) + x + 1;
|
||||
|
||||
// add upper triangle
|
||||
elements.push_back(v00);
|
||||
@@ -147,11 +147,11 @@ std::vector<glm::vec2> BasicGrid::CreateTextureCoordinates(int xRes, int yRes){
|
||||
std::vector<glm::vec2> textureCoordinates;
|
||||
textureCoordinates.reserve(numVertices(xRes, yRes));
|
||||
|
||||
for (unsigned int y = 0; y < yRes; y++) {
|
||||
for (unsigned int x = 0; x < xRes; x++) {
|
||||
for (unsigned int y = 0; y < yRes + 1; y++) {
|
||||
for (unsigned int x = 0; x < xRes + 1; x++) {
|
||||
textureCoordinates.push_back(glm::vec2(
|
||||
static_cast<float>(x) / static_cast<float>(xRes - 1),
|
||||
static_cast<float>(y) / static_cast<float>(yRes - 1)
|
||||
static_cast<float>(x) / static_cast<float>(xRes),
|
||||
static_cast<float>(y) / static_cast<float>(yRes)
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -163,8 +163,8 @@ std::vector<glm::vec3> BasicGrid::CreateNormals(int xRes, int yRes) {
|
||||
std::vector<glm::vec3> normals;
|
||||
normals.reserve(numVertices(xRes, yRes));
|
||||
|
||||
for (unsigned int y = 0; y < yRes; y++) {
|
||||
for (unsigned int x = 0; x < xRes; x++) {
|
||||
for (unsigned int y = 0; y < yRes + 1; y++) {
|
||||
for (unsigned int x = 0; x < xRes + 1; x++) {
|
||||
normals.push_back(glm::vec3(0, 0, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,16 @@ namespace openspace {
|
||||
class BasicGrid : public Grid
|
||||
{
|
||||
public:
|
||||
/**
|
||||
\param xRes is the number of grid cells in the x direction.
|
||||
\param yRes is the number of grid cells in the y direction.
|
||||
\param usePositions determines whether or not to upload any vertex position data
|
||||
to the GPU.
|
||||
\param useTextureCoordinates determines whether or not to upload any vertex texture
|
||||
coordinate data to the GPU.
|
||||
\param useNormals determines whether or not to upload any vertex normal data
|
||||
to the GPU.
|
||||
*/
|
||||
BasicGrid(
|
||||
unsigned int xRes,
|
||||
unsigned int yRes,
|
||||
@@ -45,10 +55,19 @@ public:
|
||||
Geometry::Normals useNormals);
|
||||
~BasicGrid();
|
||||
|
||||
/**
|
||||
Returns the number of grid cells in the x direction. Hence the number of vertices
|
||||
in the x direction is xResolution + 1.
|
||||
*/
|
||||
virtual int xResolution() const;
|
||||
|
||||
/**
|
||||
Returns the number of grid cells in the y direction. Hence the number of vertices
|
||||
in the y direction is xResolution + 1.
|
||||
*/
|
||||
virtual int yResolution() const;
|
||||
|
||||
protected:
|
||||
private:
|
||||
virtual std::vector<GLuint> CreateElements( int xRes, int yRes);
|
||||
virtual std::vector<glm::vec4> CreatePositions( int xRes, int yRes);
|
||||
virtual std::vector<glm::vec2> CreateTextureCoordinates( int xRes, int yRes);
|
||||
|
||||
@@ -36,6 +36,15 @@ namespace openspace {
|
||||
// CLIPMAP GRID (Abstract class) //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
This class defines a grid used for the layers of a geometry clipmap. A geometry
|
||||
clipmap is built up from a pyramid of clipmaps so the majority of the grids used
|
||||
are of the class OuterClipMapGrid. The vertex positions and texture coordinated are
|
||||
defined differently than for a normal BasicGrid. Other than having the basic grid
|
||||
vertices it also creates padding of one grid cell on the perimeter. This padding can be
|
||||
used when rendering a ClipMapGrid so that an inner layer of the pyramid can move and
|
||||
snap to the outer layers grid cells.
|
||||
*/
|
||||
class ClipMapGrid : public Grid
|
||||
{
|
||||
public:
|
||||
@@ -45,6 +54,12 @@ public:
|
||||
|
||||
virtual int xResolution() const;
|
||||
virtual int yResolution() const;
|
||||
|
||||
/**
|
||||
Returns the resolution of the grid. A ClipMapGrid must have the resolution in x and
|
||||
y direction equal so this function works as a wrapper for xResolution() and
|
||||
yResolution().
|
||||
*/
|
||||
int resolution() const;
|
||||
};
|
||||
|
||||
@@ -52,6 +67,11 @@ public:
|
||||
// OUTER CLIPMAP GRID //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
The outer layers of a geometry clipmap pyramid can be built up by grids with sizes
|
||||
increasing with the power of 2. The OuterClipMapGrid has a whole in the middle where
|
||||
a smaller ClipMapGrid of half the size can fit.
|
||||
*/
|
||||
class OuterClipMapGrid : public ClipMapGrid
|
||||
{
|
||||
public:
|
||||
@@ -81,6 +101,11 @@ private:
|
||||
// INNER CLIPMAP GRID //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
The InnerClipMapGrid can be used for the inner most (smallest) grid of a geometry clipmap
|
||||
pyramid. The only difference from a OuterClipMapGrid is that this grid does not have
|
||||
a whole where a smaller ClipMapGrid can be positioned.
|
||||
*/
|
||||
class InnerClipMapGrid : public ClipMapGrid
|
||||
{
|
||||
public:
|
||||
@@ -88,13 +113,12 @@ public:
|
||||
|
||||
~InnerClipMapGrid();
|
||||
|
||||
protected:
|
||||
private:
|
||||
virtual std::vector<GLuint> CreateElements(int xRes, int yRes);
|
||||
virtual std::vector<glm::vec4> CreatePositions(int xRes, int yRes);
|
||||
virtual std::vector<glm::vec2> CreateTextureCoordinates(int xRes, int yRes);
|
||||
virtual std::vector<glm::vec3> CreateNormals(int xRes, int yRes);
|
||||
|
||||
private:
|
||||
void validate(int xRes, int yRes);
|
||||
|
||||
static size_t numElements(int resolution);
|
||||
|
||||
Reference in New Issue
Block a user