Skip to content

Commit

Permalink
Finished building generation. Some minor fixes in the double accuracy…
Browse files Browse the repository at this point in the history
… department as well. Added polygon triangulation.
  • Loading branch information
pazdera committed May 4, 2011
1 parent e2811ac commit 806eb4f
Show file tree
Hide file tree
Showing 31 changed files with 932 additions and 114 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ TEST_UNITS=test/testPoint.o \
test/testBlock.o \
test/testLot.o \
test/testZone.o \
test/testSubRegion.o
test/testSubRegion.o \
test/testShape.o

TEST_MAIN=test/main.o
TEST_OBJECTS=$(TEST_UNITS) $(TEST_MAIN)
Expand Down
5 changes: 4 additions & 1 deletion include/libcity.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "../src/geometry/vector.h"
#include "../src/geometry/polygon.h"
#include "../src/geometry/ray.h"
#include "../src/geometry/shape.h"

#include "../src/streetgraph/road.h"
#include "../src/streetgraph/path.h"
Expand All @@ -54,11 +55,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "../src/area/lot.h"
#include "../src/area/subregion.h"


#include "../src/lsystem/lsystem.h"
#include "../src/lsystem/graphiclsystem.h"
#include "../src/lsystem/roadlsystem.h"

#include "../src/entities/urbanentity.h"
#include "../src/entities/building.h"

#include "../src/random.h"
#include "../src/city.h"
#include "../src/debug.h"
Expand Down
36 changes: 31 additions & 5 deletions plan.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,48 @@ Plan:
- DONE Create Lot class
- DONE Eliminate 5 and more way intersections in roadGenerators
- Refactor subdivision into lots to Region class
- http://cg.tutsplus.com/articles/where-to-get-your-textures-19-free-photo-source-sites-for-cg-artists/
- DONE Create special data structure for storing edges while creating lots
- DONE Remove lots that are not planar or that are out of their cycle
- DONE Make lot subdivision constants alterable
- DONE Design UrbanEntity class
- DONE Create Building class
- DONE Modify Road type system to be Building-like
- DONE Implement polygon scale and rotation
- Create Shape class for representing shapes
- DONE Create Shape class for representing shapes
- DONE Write tests for polygon rotations and Shape class interface
- DONE Implement substraction from polygon
- DONE Write test for polygon substraction
- DONE Create ShapeLSystem from GraphicalLSystem
- DONE Implement substract edge into polygon class
- DONE Test substract edge
- DONE Create class SkyScraper
- DONE Implement is inside bounding box
- DONE Bounding box test test
- Create some materials for skyscrapers
- DONE Write ispolygonnonintersecting predicate
- DONE Test isPolygonNonIntersecting
- DONE Create struct Renderer::MaterialDefinition
- DONE Implement MaterialDefinition struct into SkyScraper
- Add probability parameter to stochastic rules in LSystems
- DONE Implement texture tilling into skyscraper add plane
- DONE Texture tiling in SkyScraper
- Research Static geometry and batching for buildings, zones
- Cite polygon triangulation
- http://amazingtextures.com/textures/cat-buildings-28.htm
- http://cg.tutsplus.com/articles/where-to-get-your-textures-19-free-photo-source-sites-for-cg-artists/
- Ogre3D static geometry http://www.ogre3d.org/tikiwiki/Intermediate+Tutorial+5&structure=Tutorials
- Flatten terrain under roads
- Another buildings
- Documentation
- Github
- Store road information into lots (which edge has road access?)
- Modify lot generation to keep non-road lots
- Modify road class grammar
- Refactor Random generator
- Configuration into separate file?
- Configuration into separate file? NAH
- Minimal distance between two intersections
- Think about separating intersections into a different module
- Clean-up textures and material scripts
- DONE Clean-up textures and material scripts
- Refactor OgreCity
- Clean debug messages
- flattenTerrain() under buildings and roads
Expand All @@ -187,7 +213,7 @@ Plan:

- FIX area and centroid computation in Polygon!!! will not work in 3D


- http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml

Úvod
Související práce
Expand Down
14 changes: 12 additions & 2 deletions src/area/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,23 @@ void Block::createLots(double lotWidth, double lotHeight, double deviance)
}
}
}


Polygon newRegionPolygon;
debug("Block::createLots() numberOfRegions " << outputRegions.size());
for (std::list<SubRegion*>::iterator newRegion = outputRegions.begin();
newRegion != outputRegions.end();
newRegion++)
{
lots.push_back(new Lot(this, (*newRegion)->toPolygon()));
newRegionPolygon = (*newRegion)->toPolygon();
if (newRegionPolygon.isNonSelfIntersecting())
{
lots.push_back(new Lot(this, newRegionPolygon));
}
else
{
assert(false);
}

delete *newRegion;
}
}
Expand Down
73 changes: 67 additions & 6 deletions src/entities/building.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
#include "../geometry/point.h"
#include "../geometry/polygon.h"
#include "../geometry/vector.h"
#include "../geometry/shape.h"
#include "../area/lot.h"
#include "../entities/urbanentity.h"


const Building::Type Building::SKY_SCRAPER = UrbanEntity::defineNewEntityType();

Building::Building()
{
initialize();
Expand All @@ -34,25 +33,87 @@ Building::Building(Lot* parentAlottment)
}

void Building::initialize()
{}
{
Polygon area = parentLot->areaConstraints();
boundingBox = new Shape();
boundingBox->setBase(area);
boundingBox->setHeight(0);

addToAlphabet("{}");

setInitialPosition(area.centroid());
setInitialDirection(Vector(0,0,1));
}

void Building::interpretSymbol(char symbol)
{
switch (symbol)
{
case '{':
pushBoundingBox();
break;
case '}':
popBoundingBox();
break;
default:
/* Try to interpret symbols defined in parent. */
GraphicLSystem::interpretSymbol(symbol);
break;
}
}

Building::~Building()
{
freeMemory();
}

void Building::freeMemory()
{
delete boundingBox;
}

Building::Building(Building const& source)
: UrbanEntity(source)
{

initialize();
*boundingBox = *(source.boundingBox);
}

Building& Building::operator=(Building const& source)
{
UrbanEntity::operator=(source);

*boundingBox = *(source.boundingBox);

return *this;
}

void Building::generate()
/*
void Building::draw()
{
}*/

double Building::maxHeight()
{
return boundingBox->height();
}

void Building::setMaxHeight(double maxHeight)
{
boundingBox->setHeight(maxHeight);
}

void Building::pushBoundingBox()
{
boundingBoxStack.push_back(boundingBox);
}

void Building::popBoundingBox()
{
assert(boundingBoxStack.size() > 0);

// FIXME produces leaks
boundingBox = boundingBoxStack.back();
//delete boundingBoxStack.back();
boundingBoxStack.pop_back();
}
28 changes: 21 additions & 7 deletions src/entities/building.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

/* STL */
#include <string>
#include <list>

/* libcity */
#include "urbanentity.h"
Expand All @@ -26,28 +27,41 @@ class Polygon;
class Zone;
class Block;
class Lot;
class Shape;

class Building : public UrbanEntity, public GraphicLSystem
{
public:
/* Available built-in types. */
/* These must be initialized to UNIQUE values. */
/* Initialization moved to cpp file */
const static Type SKY_SCRAPER;

private:
Building();

public:
Building(Lot* parentAlottment);
virtual ~Building();

Building(Building const& source);
Building& operator=(Building const& source);

virtual void generate();
double maxHeight();
void setMaxHeight(double maxHeight);

void pushBoundingBox();
void popBoundingBox();

virtual void interpretSymbol(char symbol);

//virtual void draw() = 0;

protected:
/**
Maximum height together with the lot in which this
building resides defines bounding box. */
Shape* boundingBox;

std::list<Shape*> boundingBoxStack;

private:
void initialize();
void freeMemory();
};

#endif
2 changes: 1 addition & 1 deletion src/entities/urbanentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class UrbanEntity
UrbanEntity(Lot* parentAlottment);
virtual ~UrbanEntity();

virtual void generate() = 0;
//virtual void draw() = 0;

protected:
Lot* parentLot;
Expand Down
2 changes: 1 addition & 1 deletion src/geometry/line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ double Line::distance(Point const& point) const
bool Line::operator==(Line const& another) const
{
return (begining() == another.begining() && end() == another.end()) ||
(begining() == another.end() && begining() == another.end());
(begining() == another.end() && end() == another.begining());
}

std::string Line::toString()
Expand Down
25 changes: 15 additions & 10 deletions src/geometry/linesegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,29 @@ bool LineSegment::hasPoint2D(Point const& point) const
{
double lineTest = (point.x() - first->x()) * (second->y() - first->y()) -
(point.y() - first->y()) * (second->x() - first->x());
if (std::abs(lineTest) < libcity::EPSILON)
// debug(std::abs(lineTest));
// debug(toString());
// debug(point.toString());
if (std::abs(lineTest) < libcity::COORDINATES_EPSILON)
/* Point is on the line */
{
double t = 0.0;
if (first->x() != second->x())
if (std::abs(first->x() - second->x()) > libcity::COORDINATES_EPSILON) //(first->x() != second->x())
{
t = (point.x() - first->x()) / (second->x() - first->x());
//debug(t);
return t >= 0 && t <= 1;
}
else if (first->y() != second->y())
else if (std::abs(first->y() - second->y()) > libcity::COORDINATES_EPSILON) //(first->y() != second->y())
{
t = (point.y() - first->y()) / (second->y() - first->y());
//debug(t);
return t >= 0 && t <= 1;
}
else
{
return (*first) == point;
}
return t >= 0 && t <= 1;
}

return false;
Expand All @@ -80,18 +86,17 @@ LineSegment::Intersection LineSegment::intersection2D(LineSegment const& another
secondNumerator = ((end().x() - begining().x())*(begining().y() - another.begining().y())) -
((end().y() - begining().y())*(begining().x() - another.begining().x()));

if (std::abs(denominator) < libcity::EPSILON)
if (std::abs(denominator) < libcity::COORDINATES_EPSILON)
/* If the denominator is 0, both lines have same direction vector */
{
if (std::abs(firstNumerator) < libcity::EPSILON &&
std::abs(secondNumerator) < libcity::EPSILON)
if (std::abs(firstNumerator) < libcity::COORDINATES_EPSILON &&
std::abs(secondNumerator) < libcity::COORDINATES_EPSILON)
/* Lines are coincident. */
{

/* WARNING
* Order of following checks is important
* for the right functionality. */

if (*this == another)
/* Line segments are identical */
{
Expand Down Expand Up @@ -237,7 +242,7 @@ double LineSegment::length() const
bool LineSegment::operator==(LineSegment const& another) const
{
return (begining() == another.begining() && end() == another.end()) ||
(begining() == another.end() && begining() == another.end());
(begining() == another.end() && end() == another.begining());
}

Vector LineSegment::normal() const
Expand All @@ -248,7 +253,7 @@ Vector LineSegment::normal() const
}


std::string LineSegment::toString()
std::string LineSegment::toString() const
{
return "LineSegment(" + first->toString() + ", " + second->toString() + ")";
}
2 changes: 1 addition & 1 deletion src/geometry/linesegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class LineSegment : public Line
double distance(Point const& point) const;
Point nearestPoint(Point const& point) const;

std::string toString();
std::string toString() const;

bool operator==(LineSegment const& another) const;
};
Expand Down
2 changes: 1 addition & 1 deletion src/geometry/point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Vector Point::operator-(Point const& second)
return Vector(second, *this);
}

std::string Point::toString()
std::string Point::toString() const
{
std::stringstream convertor;
convertor << "Point(" << xPosition << ", " << yPosition << ", " << zPosition << ")";
Expand Down
Loading

0 comments on commit 806eb4f

Please sign in to comment.