[Orxonox-commit 4413] r9084 - in code/branches/pCuts: data/levels src/modules/tetris src/orxonox/worldentities
jo at orxonox.net
jo at orxonox.net
Thu Apr 12 19:05:57 CEST 2012
Author: jo
Date: 2012-04-12 19:05:57 +0200 (Thu, 12 Apr 2012)
New Revision: 9084
Modified:
code/branches/pCuts/data/levels/tetris.oxw
code/branches/pCuts/src/modules/tetris/Tetris.cc
code/branches/pCuts/src/modules/tetris/Tetris.h
code/branches/pCuts/src/modules/tetris/TetrisBrick.cc
code/branches/pCuts/src/modules/tetris/TetrisBrick.h
code/branches/pCuts/src/orxonox/worldentities/ControllableEntity.cc
Log:
Rotating bricks works. Next step: repairing the collision detection.
Modified: code/branches/pCuts/data/levels/tetris.oxw
===================================================================
--- code/branches/pCuts/data/levels/tetris.oxw 2012-04-11 16:35:15 UTC (rev 9083)
+++ code/branches/pCuts/data/levels/tetris.oxw 2012-04-12 17:05:57 UTC (rev 9084)
@@ -26,6 +26,9 @@
<attached>
<Model position="0,0,0" mesh="crate.mesh" scale=1 />
</attached>
+ <!--collisionShapes>
+ <BoxCollisionShape position="0,0,0" halfExtents="5,5,5" />
+ </collisionShapes-->
</TetrisStone>
</Template>
@@ -76,6 +79,11 @@
<Model position="-1,76,0" mesh="cube.mesh" scale3D="1,76,1" />
<Model position="111,76,0" mesh="cube.mesh" scale3D="1,76,1" />
</attached>
+ <!--collisionShapes>
+ <BoxCollisionShape position="55,-1,0" halfExtents="57,1,11" />
+ <BoxCollisionShape position="-1,76,0" halfExtents="1,76,1" />
+ <BoxCollisionShape position="111,76,0" halfExtents="1,76,1" />
+ </collisionShapes-->
</TetrisCenterpoint>
</Scene>
Modified: code/branches/pCuts/src/modules/tetris/Tetris.cc
===================================================================
--- code/branches/pCuts/src/modules/tetris/Tetris.cc 2012-04-11 16:35:15 UTC (rev 9083)
+++ code/branches/pCuts/src/modules/tetris/Tetris.cc 2012-04-12 17:05:57 UTC (rev 9084)
@@ -129,19 +129,28 @@
/**
@brief
- Check for each stone in a brick wether it is moved the right way.
+ Check for each stone in a brick if it is moved the right way.
*/
- bool Tetris::isValidMove(TetrisBrick* brick, const Vector3& position)
+ bool Tetris::isValidMove(TetrisBrick* brick, const Vector3& position, bool isRotation = false)
{
assert(brick);
for (unsigned int i = 0; i < brick->getNumberOfStones(); i++ )
{
TetrisStone* stone = brick->getStone(i);
- if(! this->isValidMove(stone, position + stone->getPosition())) // wrong position??
+ Vector3 stonePosition;
+ if(isRotation)
+ stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount()+1);
+ else
+ stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount());
+
+ /*orxout()<< "stoneRelativePoistion: " << stonePosition << endl;
+ orxout()<< "stoneTotalPoistion : " << position + stonePosition << endl;*/
+
+ if(! this->isValidMove(stone, position + stonePosition )) // wrong position??
+ {
return false;
- orxout()<< "stoneRelativePoistion: " << stone->getPosition() << endl;
- orxout()<< "stoneTotalPoistion: " << position + stone->getPosition() << endl;
+ }
}
return true;
@@ -158,11 +167,13 @@
{
if(this->activeBrick_->contains(*it))
continue;
+//TODO: is this rotation correct ??
+ Vector3 currentStonePosition = rotateVector((*it)->getPosition(), this->activeBrick_->getRotationCount());
+ //!< Saves the position of the currentStone
- const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone
-
if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize()))
- {
+ {//TODO: Why are such events not detected ??
+ orxout()<< "YEAY !!"<<endl;
this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, currentStonePosition.y+this->center_->getStoneSize(), this->activeBrick_->getPosition().z));
return false;
}// This case applies if the stones overlap partially vertically
@@ -170,8 +181,9 @@
// after we checked for collision with all stones, we also check for collision with the bottom
if(position.y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level
- {//TODO: correct positioning !!
- this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, this->center_->getStoneSize()/2.0f, this->activeBrick_->getPosition().z));
+ {
+ int yOffset = stone->getPosition().y;//calculate offset
+ this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, this->center_->getStoneSize()/2.0f+yOffset, this->activeBrick_->getPosition().z));
return false;
}
@@ -185,11 +197,28 @@
for (unsigned int i = 0; i < brick->getNumberOfStones(); i++ )
{
TetrisStone* stone = brick->getStone(i);
- if(! this->isValidStonePosition(stone, position + stone->getPosition()) ) // wrong position??
+ Vector3 stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount());
+ if(! this->isValidStonePosition(stone, position + stonePosition) )
return false;
}
return true;
+ }
+ /**
+ @brief
+ Nasty function that allocates memory!! it rolls a vector 90° * amount
+ */
+ Vector3 Tetris::rotateVector(Vector3 position, unsigned int amount)
+ {
+
+ int temp = 0;
+ for(unsigned int i = 0; i < amount; i++)
+ {
+ temp = position.x;
+ position.x = -position.y;
+ position.y = temp;
+ }
+ return position;
}
/**
Modified: code/branches/pCuts/src/modules/tetris/Tetris.h
===================================================================
--- code/branches/pCuts/src/modules/tetris/Tetris.h 2012-04-11 16:35:15 UTC (rev 9083)
+++ code/branches/pCuts/src/modules/tetris/Tetris.h 2012-04-12 17:05:57 UTC (rev 9084)
@@ -71,17 +71,19 @@
{ return this->center_; }
bool isValidMove(TetrisStone* stone, const Vector3& position);
- bool isValidMove(TetrisBrick* brick, const Vector3& position);
+ bool isValidMove(TetrisBrick* brick, const Vector3& position, bool isRotation);
protected:
virtual void spawnPlayersIfRequested(); //!< Spawns player.
+
private:
void startBrick(void);
void createBrick(void);
void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats.
bool isValidStonePosition(TetrisStone* stone, const Vector3& position);
bool isValidBrickPosition(TetrisBrick* brick, const Vector3& position);
+ Vector3 rotateVector(Vector3 position, unsigned int amount);
PlayerInfo* player_;
Modified: code/branches/pCuts/src/modules/tetris/TetrisBrick.cc
===================================================================
--- code/branches/pCuts/src/modules/tetris/TetrisBrick.cc 2012-04-11 16:35:15 UTC (rev 9083)
+++ code/branches/pCuts/src/modules/tetris/TetrisBrick.cc 2012-04-12 17:05:57 UTC (rev 9084)
@@ -52,15 +52,14 @@
{
RegisterObject(TetrisBrick);
- this->shapeIndex_ = 3; //<! TODO: random number between 0 and 7
+ this->shapeIndex_ = 1; //<! TODO: random number between 0 and 7
this->stonesPerBrick_ = 4; //<! most tetris bricks is formed by 4 stones
this->delay_ = false;
this->delayTimer_.setTimer(0.2f, false, createExecutor(createFunctor(&TetrisBrick::enableMovement, this)));
this->lockRotation_ = false;
this->tetris_ = this->getTetris();
this->size_ = 10.0f; //TODO: fix this via this->tetris_->center_->getStoneSize();
-
-
+ this->rotationCount_ = 0;
this->createBrick(); //<! create a whole new Brick;
}
@@ -78,7 +77,7 @@
{
// Create a new stone and add it to the brick.
TetrisStone* stone = new TetrisStone(this);
- stone->setHealth(1.0f); //TODO: is this value low enough ?
+ stone->setHealth(1.0f);
this->brickStones_.push_back(stone);
this->attach(stone);
this->formBrick(stone, i);
@@ -155,17 +154,9 @@
}
}
- bool TetrisBrick::isValidMove(Vector3& position)
+ bool TetrisBrick::isValidMove(const Vector3& position, bool isRotation = false)
{
-
- for(unsigned int i = 0; i < this->stonesPerBrick_ ; i++)
- {//TODO: check if isValidMove works with this function,
- if(this->tetris_->isValidMove(this->brickStones_[i], position))
- continue;
- else
- return false;
- }
- return true;
+ return this->tetris_->isValidMove(this,position, isRotation);
}
TetrisStone* TetrisBrick::getStone(unsigned int i)
@@ -210,12 +201,13 @@
}
else if(!this->lockRotation_) //rotate when key up is pressed
{
- orxout() << "The object should be rolled soon." << endl;
+ if(!isValidMove(this->getPosition(), true)) //catch illegal rotations
+ return;
this->lockRotation_ = true; // multiple calls of this function have to be filtered out.
this->rotationTimer_.setTimer(0.1f, false, createExecutor(createFunctor(&TetrisBrick::unlockRotation, this)));
Quaternion q(Degree(90), Vector3::UNIT_Z);
this->setOrientation(this->getOrientation()*q); //rotation: roll 90°
-
+ this->rotationCount_ = (this->rotationCount_ + 1) % 4;
}
}
Modified: code/branches/pCuts/src/modules/tetris/TetrisBrick.h
===================================================================
--- code/branches/pCuts/src/modules/tetris/TetrisBrick.h 2012-04-11 16:35:15 UTC (rev 9083)
+++ code/branches/pCuts/src/modules/tetris/TetrisBrick.h 2012-04-12 17:05:57 UTC (rev 9084)
@@ -60,7 +60,7 @@
virtual void moveRightLeft(const Vector2& value); //!< Overloaded the function to steer the bat up and down.
virtual void changedPlayer(); //!< Is called when the player changed.
- bool isValidMove(Vector3& position);
+ bool isValidMove(const Vector3& position, bool isRotation);
unsigned int getNumberOfStones(void) const
{ return this->brickStones_.size(); }
TetrisStone* getStone(unsigned int i);
@@ -68,6 +68,8 @@
void setGame(Tetris* tetris)
{ assert(tetris); tetris_ = tetris; }
+ unsigned int getRotationCount(void)
+ { return this->rotationCount_;}
protected:
void createBrick(void); //!< Create a cluster of TetrisStones
@@ -92,6 +94,7 @@
bool delay_;
bool lockRotation_;
+ unsigned int rotationCount_; //!< Stores the bricks orientation
Timer delayTimer_;
Timer rotationTimer_; ///!< This timer is used to filter out multiple rotation inputs.
Tetris* tetris_; //<! The Tetris class is responsible to initialize this value.
Modified: code/branches/pCuts/src/orxonox/worldentities/ControllableEntity.cc
===================================================================
--- code/branches/pCuts/src/orxonox/worldentities/ControllableEntity.cc 2012-04-11 16:35:15 UTC (rev 9083)
+++ code/branches/pCuts/src/orxonox/worldentities/ControllableEntity.cc 2012-04-12 17:05:57 UTC (rev 9084)
@@ -176,7 +176,7 @@
unsigned int ControllableEntity::getCurrentCameraIndex() const
{
if (this->cameraPositions_.size() <= 0)
- {orxout()<< "camareapositions_size == 0"<<endl ; return 0;}
+ return 0;
unsigned int counter = 0;
for (std::list<SmartPtr<CameraPosition> >::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
@@ -195,7 +195,6 @@
{
if(this->camera_ != NULL && this->cameraPositions_.size() > 0)
{
- orxout()<< "Cameraposition is set."<<endl;
if(index >= this->cameraPositions_.size())
index = 0;
More information about the Orxonox-commit
mailing list