mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-20 03:49:31 -06:00
Rename resolution to segments in grid classes.
This commit is contained in:
@@ -31,32 +31,32 @@ namespace {
|
||||
namespace openspace {
|
||||
|
||||
BasicGrid::BasicGrid(
|
||||
unsigned int xRes,
|
||||
unsigned int yRes,
|
||||
unsigned int xSegments,
|
||||
unsigned int ySegments,
|
||||
Geometry::Positions usePositions,
|
||||
Geometry::TextureCoordinates useTextureCoordinates,
|
||||
Geometry::Normals useNormals)
|
||||
: Grid(
|
||||
xRes,
|
||||
yRes,
|
||||
xSegments,
|
||||
ySegments,
|
||||
usePositions,
|
||||
useTextureCoordinates,
|
||||
useNormals)
|
||||
{
|
||||
_geometry = std::unique_ptr<Geometry>(new Geometry(
|
||||
CreateElements(xRes, yRes),
|
||||
CreateElements(xSegments, ySegments),
|
||||
usePositions,
|
||||
useTextureCoordinates,
|
||||
useNormals));
|
||||
|
||||
if (usePositions == Geometry::Positions::Yes) {
|
||||
_geometry->setVertexPositions(CreatePositions(_xRes, _yRes));
|
||||
_geometry->setVertexPositions(CreatePositions(_xSegments, _ySegments));
|
||||
}
|
||||
if (useTextureCoordinates == Geometry::TextureCoordinates::Yes) {
|
||||
_geometry->setVertexTextureCoordinates(CreateTextureCoordinates(_xRes, _yRes));
|
||||
_geometry->setVertexTextureCoordinates(CreateTextureCoordinates(_xSegments, _ySegments));
|
||||
}
|
||||
if (useNormals == Geometry::Normals::Yes) {
|
||||
_geometry->setVertexNormals(CreateNormals(_xRes, _yRes));
|
||||
_geometry->setVertexNormals(CreateNormals(_xSegments, _ySegments));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,34 +65,34 @@ BasicGrid::~BasicGrid()
|
||||
|
||||
}
|
||||
|
||||
int BasicGrid::xResolution() const {
|
||||
return _xRes;
|
||||
int BasicGrid::xSegments() const {
|
||||
return _xSegments;
|
||||
}
|
||||
|
||||
int BasicGrid::yResolution() const {
|
||||
return _yRes;
|
||||
int BasicGrid::ySegments() const {
|
||||
return _ySegments;
|
||||
}
|
||||
|
||||
void BasicGrid::validate(int xRes, int yRes) {
|
||||
ghoul_assert(xRes > 0 && yRes > 0,
|
||||
"Resolution must be at least 1x1. (" << xRes << ", " << yRes << ")");
|
||||
void BasicGrid::validate(int xSegments, int ySegments) {
|
||||
ghoul_assert(xSegments > 0 && ySegments > 0,
|
||||
"Resolution must be at least 1x1. (" << xSegments << ", " << ySegments << ")");
|
||||
}
|
||||
|
||||
inline size_t BasicGrid::numElements(int xRes, int yRes){
|
||||
return 3 * 2 * xRes * yRes;
|
||||
inline size_t BasicGrid::numElements(int xSegments, int ySegments){
|
||||
return 3 * 2 * xSegments * ySegments;
|
||||
}
|
||||
|
||||
inline size_t BasicGrid::numVertices(int xRes, int yRes) {
|
||||
return (xRes + 1) * (yRes + 1);
|
||||
inline size_t BasicGrid::numVertices(int xSegments, int ySegments) {
|
||||
return (xSegments + 1) * (ySegments + 1);
|
||||
}
|
||||
|
||||
std::vector<GLuint> BasicGrid::CreateElements(int xRes, int yRes) {
|
||||
validate(xRes, yRes);
|
||||
std::vector<GLuint> BasicGrid::CreateElements(int xSegments, int ySegments) {
|
||||
validate(xSegments, ySegments);
|
||||
|
||||
std::vector<GLuint> elements;
|
||||
elements.reserve(numElements(xRes, yRes));
|
||||
for (unsigned int y = 0; y < yRes; y++) {
|
||||
for (unsigned int x = 0; x < xRes; x++) {
|
||||
elements.reserve(numElements(xSegments, ySegments));
|
||||
for (unsigned int y = 0; y < ySegments; y++) {
|
||||
for (unsigned int x = 0; x < xSegments; 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 + 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;
|
||||
GLuint v00 = (y + 0) * (xSegments + 1) + x + 0;
|
||||
GLuint v10 = (y + 0) * (xSegments + 1) + x + 1;
|
||||
GLuint v01 = (y + 1) * (xSegments + 1) + x + 0;
|
||||
GLuint v11 = (y + 1) * (xSegments + 1) + x + 1;
|
||||
|
||||
// add upper triangle
|
||||
elements.push_back(v00);
|
||||
@@ -122,15 +122,15 @@ std::vector<GLuint> BasicGrid::CreateElements(int xRes, int yRes) {
|
||||
}
|
||||
|
||||
std::vector<glm::vec4> BasicGrid::CreatePositions(
|
||||
int xRes,
|
||||
int yRes)
|
||||
int xSegments,
|
||||
int ySegments)
|
||||
{
|
||||
validate(xRes, yRes);
|
||||
validate(xSegments, ySegments);
|
||||
std::vector<glm::vec4> positions;
|
||||
positions.reserve(numVertices(xRes, yRes));
|
||||
positions.reserve(numVertices(xSegments, ySegments));
|
||||
|
||||
// Copy from 2d texture coordinates and use as template to create positions
|
||||
std::vector<glm::vec2> templateTextureCoords = CreateTextureCoordinates(xRes, yRes);
|
||||
std::vector<glm::vec2> templateTextureCoords = CreateTextureCoordinates(xSegments, ySegments);
|
||||
for (unsigned int i = 0; i < templateTextureCoords.size(); i++)
|
||||
{
|
||||
positions.push_back(glm::vec4(
|
||||
@@ -142,29 +142,29 @@ std::vector<glm::vec4> BasicGrid::CreatePositions(
|
||||
return positions;
|
||||
}
|
||||
|
||||
std::vector<glm::vec2> BasicGrid::CreateTextureCoordinates(int xRes, int yRes){
|
||||
validate(xRes, yRes);
|
||||
std::vector<glm::vec2> BasicGrid::CreateTextureCoordinates(int xSegments, int ySegments){
|
||||
validate(xSegments, ySegments);
|
||||
std::vector<glm::vec2> textureCoordinates;
|
||||
textureCoordinates.reserve(numVertices(xRes, yRes));
|
||||
textureCoordinates.reserve(numVertices(xSegments, ySegments));
|
||||
|
||||
for (unsigned int y = 0; y < yRes + 1; y++) {
|
||||
for (unsigned int x = 0; x < xRes + 1; x++) {
|
||||
for (unsigned int y = 0; y < ySegments + 1; y++) {
|
||||
for (unsigned int x = 0; x < xSegments + 1; x++) {
|
||||
textureCoordinates.push_back(glm::vec2(
|
||||
static_cast<float>(x) / static_cast<float>(xRes),
|
||||
static_cast<float>(y) / static_cast<float>(yRes)
|
||||
static_cast<float>(x) / static_cast<float>(xSegments),
|
||||
static_cast<float>(y) / static_cast<float>(ySegments)
|
||||
));
|
||||
}
|
||||
}
|
||||
return textureCoordinates;
|
||||
}
|
||||
|
||||
std::vector<glm::vec3> BasicGrid::CreateNormals(int xRes, int yRes) {
|
||||
validate(xRes, yRes);
|
||||
std::vector<glm::vec3> BasicGrid::CreateNormals(int xSegments, int ySegments) {
|
||||
validate(xSegments, ySegments);
|
||||
std::vector<glm::vec3> normals;
|
||||
normals.reserve(numVertices(xRes, yRes));
|
||||
normals.reserve(numVertices(xSegments, ySegments));
|
||||
|
||||
for (unsigned int y = 0; y < yRes + 1; y++) {
|
||||
for (unsigned int x = 0; x < xRes + 1; x++) {
|
||||
for (unsigned int y = 0; y < ySegments + 1; y++) {
|
||||
for (unsigned int x = 0; x < xSegments + 1; x++) {
|
||||
normals.push_back(glm::vec3(0, 0, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ 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 xSegments is the number of grid cells in the x direction.
|
||||
\param ySegments 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
|
||||
@@ -48,24 +48,16 @@ public:
|
||||
to the GPU.
|
||||
*/
|
||||
BasicGrid(
|
||||
unsigned int xRes,
|
||||
unsigned int yRes,
|
||||
unsigned int xSegments,
|
||||
unsigned int ySegments,
|
||||
Geometry::Positions usePositions,
|
||||
Geometry::TextureCoordinates useTextureCoordinates,
|
||||
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;
|
||||
|
||||
virtual int xSegments() const;
|
||||
virtual int ySegments() const;
|
||||
|
||||
private:
|
||||
virtual std::vector<GLuint> CreateElements( int xRes, int yRes);
|
||||
@@ -73,10 +65,10 @@ private:
|
||||
virtual std::vector<glm::vec2> CreateTextureCoordinates( int xRes, int yRes);
|
||||
virtual std::vector<glm::vec3> CreateNormals( int xRes, int yRes);
|
||||
|
||||
void validate(int xRes, int yRes);
|
||||
void validate(int xSegments, int ySegments);
|
||||
|
||||
inline size_t numElements(int xRes, int yRes);
|
||||
inline size_t numVertices(int xRes, int yRes);
|
||||
inline size_t numElements(int xSegments, int ySegments);
|
||||
inline size_t numVertices(int xSegments, int ySegments);
|
||||
};
|
||||
} // namespace openspace
|
||||
#endif // __BASICGRIDGEOMETRY_H__
|
||||
@@ -36,8 +36,8 @@ namespace openspace {
|
||||
// CLIPMAP GRID (Abstract class) //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ClipMapGrid::ClipMapGrid(unsigned int resolution)
|
||||
: Grid(resolution, resolution, Geometry::Positions::No, Geometry::TextureCoordinates::Yes, Geometry::Normals::No)
|
||||
ClipMapGrid::ClipMapGrid(unsigned int segments)
|
||||
: Grid(segments, segments, Geometry::Positions::No, Geometry::TextureCoordinates::Yes, Geometry::Normals::No)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -47,32 +47,32 @@ ClipMapGrid::~ClipMapGrid()
|
||||
|
||||
}
|
||||
|
||||
int ClipMapGrid::xResolution() const {
|
||||
return resolution();
|
||||
int ClipMapGrid::xSegments() const {
|
||||
return segments();
|
||||
}
|
||||
|
||||
int ClipMapGrid::yResolution() const {
|
||||
return resolution();
|
||||
int ClipMapGrid::ySegments() const {
|
||||
return segments();
|
||||
}
|
||||
|
||||
int ClipMapGrid::resolution() const {
|
||||
return _xRes;
|
||||
int ClipMapGrid::segments() const {
|
||||
return _xSegments;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// OUTER CLIPMAP GRID //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
OuterClipMapGrid::OuterClipMapGrid(unsigned int resolution)
|
||||
: ClipMapGrid(resolution)
|
||||
OuterClipMapGrid::OuterClipMapGrid(unsigned int segments)
|
||||
: ClipMapGrid(segments)
|
||||
{
|
||||
_geometry = std::unique_ptr<Geometry>(new Geometry(
|
||||
CreateElements(resolution, resolution),
|
||||
CreateElements(segments, segments),
|
||||
Geometry::Positions::No,
|
||||
Geometry::TextureCoordinates::Yes,
|
||||
Geometry::Normals::No));
|
||||
|
||||
_geometry->setVertexTextureCoordinates(CreateTextureCoordinates(resolution, resolution));
|
||||
_geometry->setVertexTextureCoordinates(CreateTextureCoordinates(segments, segments));
|
||||
}
|
||||
|
||||
OuterClipMapGrid::~OuterClipMapGrid()
|
||||
@@ -80,57 +80,57 @@ OuterClipMapGrid::~OuterClipMapGrid()
|
||||
|
||||
}
|
||||
|
||||
size_t OuterClipMapGrid::numElements(int resolution)
|
||||
size_t OuterClipMapGrid::numElements(int segments)
|
||||
{
|
||||
int numElementsInTotalSquare = 6 * (resolution + 1) * (resolution + 1);
|
||||
int numElementsInHole = 6 * (resolution / 4 * resolution / 4);
|
||||
int numElementsInTotalSquare = 6 * (segments + 1) * (segments + 1);
|
||||
int numElementsInHole = 6 * (segments / 4 * segments / 4);
|
||||
return numElementsInTotalSquare - numElementsInHole;
|
||||
}
|
||||
|
||||
size_t OuterClipMapGrid::numVerticesBottom(int resolution)
|
||||
size_t OuterClipMapGrid::numVerticesBottom(int segments)
|
||||
{
|
||||
return (resolution + 1 + 2) * (resolution / 4 + 1 + 1);
|
||||
return (segments + 1 + 2) * (segments / 4 + 1 + 1);
|
||||
}
|
||||
|
||||
size_t OuterClipMapGrid::numVerticesLeft(int resolution)
|
||||
size_t OuterClipMapGrid::numVerticesLeft(int segments)
|
||||
{
|
||||
return (resolution / 4 + 1 + 1) * (resolution / 2 + 1);
|
||||
return (segments / 4 + 1 + 1) * (segments / 2 + 1);
|
||||
}
|
||||
|
||||
size_t OuterClipMapGrid::numVerticesRight(int resolution)
|
||||
size_t OuterClipMapGrid::numVerticesRight(int segments)
|
||||
{
|
||||
return (resolution / 4 + 1 + 1) * (resolution / 2 + 1);
|
||||
return (segments / 4 + 1 + 1) * (segments / 2 + 1);
|
||||
}
|
||||
|
||||
size_t OuterClipMapGrid::numVerticesTop(int resolution)
|
||||
size_t OuterClipMapGrid::numVerticesTop(int segments)
|
||||
{
|
||||
return (resolution + 1 + 2) * (resolution / 4 + 1 + 1);
|
||||
return (segments + 1 + 2) * (segments / 4 + 1 + 1);
|
||||
}
|
||||
|
||||
size_t OuterClipMapGrid::numVertices(int resolution)
|
||||
size_t OuterClipMapGrid::numVertices(int segments)
|
||||
{
|
||||
return numVerticesBottom(resolution) +
|
||||
numVerticesLeft(resolution) +
|
||||
numVerticesRight(resolution) +
|
||||
numVerticesTop(resolution);
|
||||
return numVerticesBottom(segments) +
|
||||
numVerticesLeft(segments) +
|
||||
numVerticesRight(segments) +
|
||||
numVerticesTop(segments);
|
||||
}
|
||||
|
||||
void OuterClipMapGrid::validate(int xRes, int yRes) {
|
||||
|
||||
ghoul_assert(xRes == yRes,
|
||||
"Resolution must be equal in x and in y. ");
|
||||
int resolution = xRes;
|
||||
ghoul_assert(resolution >= 8,
|
||||
"Resolution must be at least 8. (" << resolution << ")");
|
||||
ghoul_assert(resolution == pow(2, int(log2(resolution))),
|
||||
"Resolution must be a power of 2. (" << resolution << ")");
|
||||
"segments must be equal in x and in y. ");
|
||||
int segments = xRes;
|
||||
ghoul_assert(segments >= 8,
|
||||
"segments must be at least 8. (" << segments << ")");
|
||||
ghoul_assert(segments == pow(2, int(log2(segments))),
|
||||
"segments must be a power of 2. (" << segments << ")");
|
||||
}
|
||||
|
||||
std::vector<GLuint> OuterClipMapGrid::CreateElements(int xRes, int yRes) {
|
||||
validate(xRes, yRes);
|
||||
int resolution = xRes;
|
||||
int segments = xRes;
|
||||
std::vector<GLuint> elements;
|
||||
elements.reserve(numElements(resolution));
|
||||
elements.reserve(numElements(segments));
|
||||
|
||||
// The clipmap geometry is built up by four parts as follows:
|
||||
// 0 = Bottom part
|
||||
@@ -155,17 +155,17 @@ std::vector<GLuint> OuterClipMapGrid::CreateElements(int xRes, int yRes) {
|
||||
|
||||
unsigned int previousVerts[4];
|
||||
previousVerts[0] = 0;
|
||||
previousVerts[1] = previousVerts[0] + numVerticesBottom(resolution);
|
||||
previousVerts[2] = previousVerts[1] + numVerticesLeft(resolution);
|
||||
previousVerts[3] = previousVerts[2] + numVerticesRight(resolution);
|
||||
previousVerts[1] = previousVerts[0] + numVerticesBottom(segments);
|
||||
previousVerts[2] = previousVerts[1] + numVerticesLeft(segments);
|
||||
previousVerts[3] = previousVerts[2] + numVerticesRight(segments);
|
||||
|
||||
// Build the bottom part of the clipmap geometry
|
||||
for (unsigned int y = 0; y < resolution / 4 + 1; y++) {
|
||||
for (unsigned int x = 0; x < resolution + 2; x++) {
|
||||
GLuint v00 = previousVerts[0] + (y + 0) * (resolution + 3) + x + 0;
|
||||
GLuint v10 = previousVerts[0] + (y + 0) * (resolution + 3) + x + 1;
|
||||
GLuint v01 = previousVerts[0] + (y + 1) * (resolution + 3) + x + 0;
|
||||
GLuint v11 = previousVerts[0] + (y + 1) * (resolution + 3) + x + 1;
|
||||
for (unsigned int y = 0; y < segments / 4 + 1; y++) {
|
||||
for (unsigned int x = 0; x < segments + 2; x++) {
|
||||
GLuint v00 = previousVerts[0] + (y + 0) * (segments + 3) + x + 0;
|
||||
GLuint v10 = previousVerts[0] + (y + 0) * (segments + 3) + x + 1;
|
||||
GLuint v01 = previousVerts[0] + (y + 1) * (segments + 3) + x + 0;
|
||||
GLuint v11 = previousVerts[0] + (y + 1) * (segments + 3) + x + 1;
|
||||
|
||||
elements.push_back(v00);
|
||||
elements.push_back(v10);
|
||||
@@ -178,12 +178,12 @@ std::vector<GLuint> OuterClipMapGrid::CreateElements(int xRes, int yRes) {
|
||||
}
|
||||
|
||||
// Build the left part of the clipmap geometry
|
||||
for (unsigned int y = 0; y < resolution / 2; y++) {
|
||||
for (unsigned int x = 0; x < resolution / 4 + 1; x++) {
|
||||
GLuint v00 = previousVerts[1] + (y + 0) * (resolution / 4 + 2) + x + 0;
|
||||
GLuint v10 = previousVerts[1] + (y + 0) * (resolution / 4 + 2) + x + 1;
|
||||
GLuint v01 = previousVerts[1] + (y + 1) * (resolution / 4 + 2) + x + 0;
|
||||
GLuint v11 = previousVerts[1] + (y + 1) * (resolution / 4 + 2) + x + 1;
|
||||
for (unsigned int y = 0; y < segments / 2; y++) {
|
||||
for (unsigned int x = 0; x < segments / 4 + 1; x++) {
|
||||
GLuint v00 = previousVerts[1] + (y + 0) * (segments / 4 + 2) + x + 0;
|
||||
GLuint v10 = previousVerts[1] + (y + 0) * (segments / 4 + 2) + x + 1;
|
||||
GLuint v01 = previousVerts[1] + (y + 1) * (segments / 4 + 2) + x + 0;
|
||||
GLuint v11 = previousVerts[1] + (y + 1) * (segments / 4 + 2) + x + 1;
|
||||
|
||||
elements.push_back(v00);
|
||||
elements.push_back(v10);
|
||||
@@ -196,12 +196,12 @@ std::vector<GLuint> OuterClipMapGrid::CreateElements(int xRes, int yRes) {
|
||||
}
|
||||
|
||||
// Build the left part of the clipmap geometry
|
||||
for (unsigned int y = 0; y < resolution / 2; y++) {
|
||||
for (unsigned int x = 0; x < resolution / 4 + 1; x++) {
|
||||
GLuint v00 = previousVerts[2] + (y + 0) * (resolution / 4 + 2) + x + 0;
|
||||
GLuint v10 = previousVerts[2] + (y + 0) * (resolution / 4 + 2) + x + 1;
|
||||
GLuint v01 = previousVerts[2] + (y + 1) * (resolution / 4 + 2) + x + 0;
|
||||
GLuint v11 = previousVerts[2] + (y + 1) * (resolution / 4 + 2) + x + 1;
|
||||
for (unsigned int y = 0; y < segments / 2; y++) {
|
||||
for (unsigned int x = 0; x < segments / 4 + 1; x++) {
|
||||
GLuint v00 = previousVerts[2] + (y + 0) * (segments / 4 + 2) + x + 0;
|
||||
GLuint v10 = previousVerts[2] + (y + 0) * (segments / 4 + 2) + x + 1;
|
||||
GLuint v01 = previousVerts[2] + (y + 1) * (segments / 4 + 2) + x + 0;
|
||||
GLuint v11 = previousVerts[2] + (y + 1) * (segments / 4 + 2) + x + 1;
|
||||
|
||||
elements.push_back(v00);
|
||||
elements.push_back(v10);
|
||||
@@ -214,12 +214,12 @@ std::vector<GLuint> OuterClipMapGrid::CreateElements(int xRes, int yRes) {
|
||||
}
|
||||
|
||||
// Build the left part of the clipmap geometry
|
||||
for (unsigned int y = 0; y < resolution / 4 + 1; y++) {
|
||||
for (unsigned int x = 0; x < resolution + 2; x++) {
|
||||
GLuint v00 = previousVerts[3] + (y + 0) * (resolution + 3) + x + 0;
|
||||
GLuint v10 = previousVerts[3] + (y + 0) * (resolution + 3) + x + 1;
|
||||
GLuint v01 = previousVerts[3] + (y + 1) * (resolution + 3) + x + 0;
|
||||
GLuint v11 = previousVerts[3] + (y + 1) * (resolution + 3) + x + 1;
|
||||
for (unsigned int y = 0; y < segments / 4 + 1; y++) {
|
||||
for (unsigned int x = 0; x < segments + 2; x++) {
|
||||
GLuint v00 = previousVerts[3] + (y + 0) * (segments + 3) + x + 0;
|
||||
GLuint v10 = previousVerts[3] + (y + 0) * (segments + 3) + x + 1;
|
||||
GLuint v01 = previousVerts[3] + (y + 1) * (segments + 3) + x + 0;
|
||||
GLuint v11 = previousVerts[3] + (y + 1) * (segments + 3) + x + 1;
|
||||
|
||||
elements.push_back(v00);
|
||||
elements.push_back(v10);
|
||||
@@ -236,9 +236,9 @@ std::vector<GLuint> OuterClipMapGrid::CreateElements(int xRes, int yRes) {
|
||||
std::vector<glm::vec4> OuterClipMapGrid::CreatePositions(int xRes, int yRes)
|
||||
{
|
||||
validate(xRes, yRes);
|
||||
int resolution = xRes;
|
||||
int segments = xRes;
|
||||
std::vector<glm::vec4> positions;
|
||||
positions.reserve(numVertices(resolution));
|
||||
positions.reserve(numVertices(segments));
|
||||
std::vector<glm::vec2> templateTextureCoords = CreateTextureCoordinates(xRes, yRes);
|
||||
|
||||
// Copy from 2d texture coordinates and use as template to create positions
|
||||
@@ -257,43 +257,43 @@ std::vector<glm::vec4> OuterClipMapGrid::CreatePositions(int xRes, int yRes)
|
||||
|
||||
std::vector<glm::vec2> OuterClipMapGrid::CreateTextureCoordinates(int xRes, int yRes){
|
||||
validate(xRes, yRes);
|
||||
int resolution = xRes;
|
||||
int segments = xRes;
|
||||
std::vector<glm::vec2> textureCoordinates;
|
||||
textureCoordinates.reserve(numVertices(resolution));
|
||||
textureCoordinates.reserve(numVertices(segments));
|
||||
|
||||
// Build the bottom part of the clipmap geometry
|
||||
for (int y = -1; y < resolution / 4 + 1; y++) {
|
||||
for (int x = -1; x < resolution + 2; x++) {
|
||||
for (int y = -1; y < segments / 4 + 1; y++) {
|
||||
for (int x = -1; x < segments + 2; x++) {
|
||||
textureCoordinates.push_back(glm::vec2(
|
||||
static_cast<float>(x) / resolution,
|
||||
static_cast<float>(y) / resolution));
|
||||
static_cast<float>(x) / segments,
|
||||
static_cast<float>(y) / segments));
|
||||
}
|
||||
}
|
||||
|
||||
// Build the left part of the clipmap geometry
|
||||
for (int y = resolution / 4; y < 3 * resolution / 4 + 1; y++) {
|
||||
for (int x = -1; x < resolution / 4 + 1; x++) {
|
||||
for (int y = segments / 4; y < 3 * segments / 4 + 1; y++) {
|
||||
for (int x = -1; x < segments / 4 + 1; x++) {
|
||||
textureCoordinates.push_back(glm::vec2(
|
||||
static_cast<float>(x) / resolution,
|
||||
static_cast<float>(y) / resolution));
|
||||
static_cast<float>(x) / segments,
|
||||
static_cast<float>(y) / segments));
|
||||
}
|
||||
}
|
||||
|
||||
// Build the right part of the clipmap geometry
|
||||
for (int y = resolution / 4; y < 3 * resolution / 4 + 1; y++) {
|
||||
for (int x = 3 * resolution / 4; x < resolution + 2; x++) {
|
||||
float u = static_cast<float>(x) / resolution;
|
||||
float v = static_cast<float>(y) / resolution;
|
||||
for (int y = segments / 4; y < 3 * segments / 4 + 1; y++) {
|
||||
for (int x = 3 * segments / 4; x < segments + 2; x++) {
|
||||
float u = static_cast<float>(x) / segments;
|
||||
float v = static_cast<float>(y) / segments;
|
||||
textureCoordinates.push_back(glm::vec2(u, v));
|
||||
}
|
||||
}
|
||||
|
||||
// Build the top part of the clipmap geometry
|
||||
for (int y = 3 * resolution / 4; y < resolution + 2; y++) {
|
||||
for (int x = -1; x < resolution + 2; x++) {
|
||||
for (int y = 3 * segments / 4; y < segments + 2; y++) {
|
||||
for (int x = -1; x < segments + 2; x++) {
|
||||
textureCoordinates.push_back(glm::vec2(
|
||||
static_cast<float>(x) / resolution,
|
||||
static_cast<float>(y) / resolution));
|
||||
static_cast<float>(x) / segments,
|
||||
static_cast<float>(y) / segments));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,12 +302,12 @@ std::vector<glm::vec2> OuterClipMapGrid::CreateTextureCoordinates(int xRes, int
|
||||
|
||||
std::vector<glm::vec3> OuterClipMapGrid::CreateNormals(int xRes, int yRes) {
|
||||
validate(xRes, yRes);
|
||||
int resolution = xRes;
|
||||
int segments = xRes;
|
||||
std::vector<glm::vec3> normals;
|
||||
normals.reserve(numVertices(resolution));
|
||||
normals.reserve(numVertices(segments));
|
||||
|
||||
for (int y = -1; y < resolution + 2; y++) {
|
||||
for (int x = -1; x < resolution + 2; x++) {
|
||||
for (int y = -1; y < segments + 2; y++) {
|
||||
for (int x = -1; x < segments + 2; x++) {
|
||||
normals.push_back(glm::vec3(0, 0, 1));
|
||||
}
|
||||
}
|
||||
@@ -320,16 +320,16 @@ std::vector<glm::vec3> OuterClipMapGrid::CreateNormals(int xRes, int yRes) {
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
InnerClipMapGrid::InnerClipMapGrid(unsigned int resolution)
|
||||
: ClipMapGrid(resolution)
|
||||
InnerClipMapGrid::InnerClipMapGrid(unsigned int segments)
|
||||
: ClipMapGrid(segments)
|
||||
{
|
||||
_geometry = std::unique_ptr<Geometry>(new Geometry(
|
||||
CreateElements(resolution, resolution),
|
||||
CreateElements(segments, segments),
|
||||
Geometry::Positions::No,
|
||||
Geometry::TextureCoordinates::Yes,
|
||||
Geometry::Normals::No));
|
||||
|
||||
_geometry->setVertexTextureCoordinates(CreateTextureCoordinates(resolution, resolution));
|
||||
_geometry->setVertexTextureCoordinates(CreateTextureCoordinates(segments, segments));
|
||||
}
|
||||
|
||||
InnerClipMapGrid::~InnerClipMapGrid()
|
||||
@@ -337,30 +337,30 @@ InnerClipMapGrid::~InnerClipMapGrid()
|
||||
|
||||
}
|
||||
|
||||
size_t InnerClipMapGrid::numElements(int resolution)
|
||||
size_t InnerClipMapGrid::numElements(int segments)
|
||||
{
|
||||
return resolution * resolution * 6;
|
||||
return segments * segments * 6;
|
||||
}
|
||||
|
||||
size_t InnerClipMapGrid::numVertices(int resolution)
|
||||
size_t InnerClipMapGrid::numVertices(int segments)
|
||||
{
|
||||
return (resolution + 1) * (resolution + 1);
|
||||
return (segments + 1) * (segments + 1);
|
||||
}
|
||||
|
||||
void InnerClipMapGrid::validate(int xRes, int yRes) {
|
||||
|
||||
ghoul_assert(xRes == yRes,
|
||||
"Resolution must be equal in x and in y. ");
|
||||
int resolution = xRes;
|
||||
ghoul_assert(resolution >= 1,
|
||||
"Resolution must be at least 1. (" << resolution << ")");
|
||||
"segments must be equal in x and in y. ");
|
||||
int segments = xRes;
|
||||
ghoul_assert(segments >= 1,
|
||||
"segments must be at least 1. (" << segments << ")");
|
||||
}
|
||||
|
||||
std::vector<GLuint> InnerClipMapGrid::CreateElements(int xRes, int yRes) {
|
||||
validate(xRes, yRes);
|
||||
int resolution = xRes;
|
||||
int segments = xRes;
|
||||
std::vector<GLuint> elements;
|
||||
elements.reserve(numElements(resolution));
|
||||
elements.reserve(numElements(segments));
|
||||
|
||||
// x v01---v11 x ..
|
||||
// | / |
|
||||
@@ -369,12 +369,12 @@ std::vector<GLuint> InnerClipMapGrid::CreateElements(int xRes, int yRes) {
|
||||
// x x x x ..
|
||||
// : : : :
|
||||
|
||||
for (unsigned int y = 0; y < resolution + 2; y++) {
|
||||
for (unsigned int x = 0; x < resolution + 2; x++) {
|
||||
GLuint v00 = (y + 0) * (resolution + 3) + x + 0;
|
||||
GLuint v10 = (y + 0) * (resolution + 3) + x + 1;
|
||||
GLuint v01 = (y + 1) * (resolution + 3) + x + 0;
|
||||
GLuint v11 = (y + 1) * (resolution + 3) + x + 1;
|
||||
for (unsigned int y = 0; y < segments + 2; y++) {
|
||||
for (unsigned int x = 0; x < segments + 2; x++) {
|
||||
GLuint v00 = (y + 0) * (segments + 3) + x + 0;
|
||||
GLuint v10 = (y + 0) * (segments + 3) + x + 1;
|
||||
GLuint v01 = (y + 1) * (segments + 3) + x + 0;
|
||||
GLuint v11 = (y + 1) * (segments + 3) + x + 1;
|
||||
|
||||
elements.push_back(v00);
|
||||
elements.push_back(v10);
|
||||
@@ -392,9 +392,9 @@ std::vector<GLuint> InnerClipMapGrid::CreateElements(int xRes, int yRes) {
|
||||
std::vector<glm::vec4> InnerClipMapGrid::CreatePositions(int xRes, int yRes)
|
||||
{
|
||||
validate(xRes, yRes);
|
||||
int resolution = xRes;
|
||||
int segments = xRes;
|
||||
std::vector<glm::vec4> positions;
|
||||
positions.reserve(numVertices(resolution));
|
||||
positions.reserve(numVertices(segments));
|
||||
std::vector<glm::vec2> templateTextureCoords = CreateTextureCoordinates(xRes, yRes);
|
||||
|
||||
// Copy from 2d texture coordinates and use as template to create positions
|
||||
@@ -413,16 +413,16 @@ std::vector<glm::vec4> InnerClipMapGrid::CreatePositions(int xRes, int yRes)
|
||||
|
||||
std::vector<glm::vec2> InnerClipMapGrid::CreateTextureCoordinates(int xRes, int yRes) {
|
||||
validate(xRes, yRes);
|
||||
int resolution = xRes;
|
||||
int segments = xRes;
|
||||
std::vector<glm::vec2> textureCoordinates;
|
||||
textureCoordinates.reserve(numVertices(resolution));
|
||||
textureCoordinates.reserve(numVertices(segments));
|
||||
|
||||
// Build the bottom part of the clipmap geometry
|
||||
for (int y = -1; y < resolution + 2; y++) {
|
||||
for (int x = -1; x < resolution + 2; x++) {
|
||||
for (int y = -1; y < segments + 2; y++) {
|
||||
for (int x = -1; x < segments + 2; x++) {
|
||||
textureCoordinates.push_back(glm::vec2(
|
||||
static_cast<float>(x) / resolution,
|
||||
static_cast<float>(y) / resolution));
|
||||
static_cast<float>(x) / segments,
|
||||
static_cast<float>(y) / segments));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,12 +431,12 @@ std::vector<glm::vec2> InnerClipMapGrid::CreateTextureCoordinates(int xRes, int
|
||||
|
||||
std::vector<glm::vec3> InnerClipMapGrid::CreateNormals(int xRes, int yRes) {
|
||||
validate(xRes, yRes);
|
||||
int resolution = xRes;
|
||||
int segments = xRes;
|
||||
std::vector<glm::vec3> normals;
|
||||
normals.reserve(numVertices(resolution));
|
||||
normals.reserve(numVertices(segments));
|
||||
|
||||
for (int y = -1; y < resolution + 2; y++) {
|
||||
for (int x = -1; x < resolution + 2; x++) {
|
||||
for (int y = -1; y < segments + 2; y++) {
|
||||
for (int x = -1; x < segments + 2; x++) {
|
||||
normals.push_back(glm::vec3(0, 0, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,19 +48,19 @@ snap to the outer layers grid cells.
|
||||
class ClipMapGrid : public Grid
|
||||
{
|
||||
public:
|
||||
ClipMapGrid(unsigned int resolution);
|
||||
ClipMapGrid(unsigned int segments);
|
||||
|
||||
~ClipMapGrid();
|
||||
|
||||
virtual int xResolution() const;
|
||||
virtual int yResolution() const;
|
||||
virtual int xSegments() const;
|
||||
virtual int ySegments() 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().
|
||||
Returns the segments of the grid. A ClipMapGrid must have the segments in x and
|
||||
y direction equal so this function works as a wrapper for xSegments() and
|
||||
ySegments().
|
||||
*/
|
||||
int resolution() const;
|
||||
int segments() const;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -75,26 +75,26 @@ a smaller ClipMapGrid of half the size can fit.
|
||||
class OuterClipMapGrid : public ClipMapGrid
|
||||
{
|
||||
public:
|
||||
OuterClipMapGrid(unsigned int resolution);
|
||||
OuterClipMapGrid(unsigned int segments);
|
||||
|
||||
~OuterClipMapGrid();
|
||||
|
||||
protected:
|
||||
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);
|
||||
virtual std::vector<GLuint> CreateElements(int xSegments, int ySegments);
|
||||
virtual std::vector<glm::vec4> CreatePositions(int xSegments, int ySegments);
|
||||
virtual std::vector<glm::vec2> CreateTextureCoordinates(int xSegments, int ySegments);
|
||||
virtual std::vector<glm::vec3> CreateNormals(int xSegments, int ySegments);
|
||||
|
||||
private:
|
||||
void validate(int xRes, int yRes);
|
||||
void validate(int xSegments, int ySegments);
|
||||
|
||||
static size_t numVerticesBottom(int resolution);
|
||||
static size_t numVerticesLeft(int resolution);
|
||||
static size_t numVerticesRight(int resolution);
|
||||
static size_t numVerticesTop(int resolution);
|
||||
static size_t numVerticesBottom(int segments);
|
||||
static size_t numVerticesLeft(int segments);
|
||||
static size_t numVerticesRight(int segments);
|
||||
static size_t numVerticesTop(int segments);
|
||||
|
||||
static size_t numElements(int resolution);
|
||||
static size_t numVertices(int resolution);
|
||||
static size_t numElements(int segments);
|
||||
static size_t numVertices(int segments);
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -109,20 +109,20 @@ a whole where a smaller ClipMapGrid can be positioned.
|
||||
class InnerClipMapGrid : public ClipMapGrid
|
||||
{
|
||||
public:
|
||||
InnerClipMapGrid(unsigned int resolution);
|
||||
InnerClipMapGrid(unsigned int segments);
|
||||
|
||||
~InnerClipMapGrid();
|
||||
|
||||
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);
|
||||
virtual std::vector<GLuint> CreateElements( int xSegments, int ySegments);
|
||||
virtual std::vector<glm::vec4> CreatePositions(int xSegments, int ySegments);
|
||||
virtual std::vector<glm::vec2> CreateTextureCoordinates(int xSegments, int ySegments);
|
||||
virtual std::vector<glm::vec3> CreateNormals(int xSegments, int ySegments);
|
||||
|
||||
void validate(int xRes, int yRes);
|
||||
void validate(int xSegments, int ySegments);
|
||||
|
||||
static size_t numElements(int resolution);
|
||||
static size_t numVertices(int resolution);
|
||||
static size_t numElements(int segments);
|
||||
static size_t numVertices(int segments);
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -31,13 +31,13 @@ namespace {
|
||||
namespace openspace {
|
||||
|
||||
Grid::Grid(
|
||||
int xRes,
|
||||
int yRes,
|
||||
int xSegments,
|
||||
int ySegments,
|
||||
Geometry::Positions usePositions,
|
||||
Geometry::TextureCoordinates useTextures,
|
||||
Geometry::Normals useNormals)
|
||||
: _xRes(xRes)
|
||||
, _yRes(yRes)
|
||||
: _xSegments(xSegments)
|
||||
, _ySegments(ySegments)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ class Grid
|
||||
{
|
||||
public:
|
||||
Grid(
|
||||
int xRes,
|
||||
int yRes,
|
||||
int xSegments,
|
||||
int ySegments,
|
||||
Geometry::Positions usePositions = Geometry::Positions::No,
|
||||
Geometry::TextureCoordinates useTextures = Geometry::TextureCoordinates::No,
|
||||
Geometry::Normals useNormals = Geometry::Normals::No);
|
||||
@@ -47,19 +47,28 @@ public:
|
||||
|
||||
Geometry& geometry();
|
||||
|
||||
virtual int xResolution() const = 0;
|
||||
virtual int yResolution() const = 0;
|
||||
/**
|
||||
Returns the number of grid cells in the x direction. Hence the number of vertices
|
||||
in the x direction is xResolution + 1.
|
||||
*/
|
||||
virtual int xSegments() const = 0;
|
||||
|
||||
/**
|
||||
Returns the number of grid cells in the y direction. Hence the number of vertices
|
||||
in the y direction is xResolution + 1.
|
||||
*/
|
||||
virtual int ySegments() const = 0;
|
||||
|
||||
protected:
|
||||
virtual std::vector<GLuint> CreateElements( int xRes, int yRes) = 0;
|
||||
virtual std::vector<glm::vec4> CreatePositions( int xRes, int yRes) = 0;
|
||||
virtual std::vector<glm::vec2> CreateTextureCoordinates( int xRes, int yRes) = 0;
|
||||
virtual std::vector<glm::vec3> CreateNormals( int xRes, int yRes) = 0;
|
||||
virtual std::vector<GLuint> CreateElements( int xSegments, int ySegments) = 0;
|
||||
virtual std::vector<glm::vec4> CreatePositions( int xSegments, int ySegments) = 0;
|
||||
virtual std::vector<glm::vec2> CreateTextureCoordinates( int xSegments, int ySegments) = 0;
|
||||
virtual std::vector<glm::vec3> CreateNormals( int xSegments, int ySegments) = 0;
|
||||
|
||||
std::unique_ptr<Geometry> _geometry;
|
||||
|
||||
const int _xRes;
|
||||
const int _yRes;
|
||||
const int _xSegments;
|
||||
const int _ySegments;
|
||||
};
|
||||
} // namespace openspace
|
||||
#endif // __GRIDGEOMETRY_H__
|
||||
@@ -183,7 +183,7 @@ namespace openspace {
|
||||
mat4 modelTransform = translate(mat4(1), data.position.vec3());
|
||||
|
||||
// Snap patch position
|
||||
int segmentsPerPatch = _grid->resolution();
|
||||
int segmentsPerPatch = _grid->segments();
|
||||
LatLon stepSize = LatLon(
|
||||
patchSize.lat / segmentsPerPatch,
|
||||
patchSize.lon / segmentsPerPatch);
|
||||
|
||||
Reference in New Issue
Block a user