Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9084 for code/branches/pCuts


Ignore:
Timestamp:
Apr 12, 2012, 7:05:57 PM (13 years ago)
Author:
jo
Message:

Rotating bricks works. Next step: repairing the collision detection.

Location:
code/branches/pCuts
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pCuts/data/levels/tetris.oxw

    r9083 r9084  
    2727      <Model position="0,0,0" mesh="crate.mesh" scale=1 />
    2828    </attached>
     29    <!--collisionShapes>
     30      <BoxCollisionShape position="0,0,0" halfExtents="5,5,5" />
     31    </collisionShapes-->
    2932  </TetrisStone>
    3033</Template>
     
    7780            <Model position="111,76,0" mesh="cube.mesh" scale3D="1,76,1" />
    7881        </attached>
     82        <!--collisionShapes>
     83            <BoxCollisionShape position="55,-1,0"  halfExtents="57,1,11" />
     84            <BoxCollisionShape position="-1,76,0"  halfExtents="1,76,1" />
     85            <BoxCollisionShape position="111,76,0" halfExtents="1,76,1" />
     86        </collisionShapes-->
    7987    </TetrisCenterpoint>
    8088
  • code/branches/pCuts/src/modules/tetris/Tetris.cc

    r9082 r9084  
    130130    /**
    131131    @brief
    132         Check for each stone in a brick wether it is moved the right way.
    133     */
    134     bool Tetris::isValidMove(TetrisBrick* brick, const Vector3& position)
     132        Check for each stone in a brick if it is moved the right way.
     133    */
     134    bool Tetris::isValidMove(TetrisBrick* brick, const Vector3& position, bool isRotation = false)
    135135    {
    136136        assert(brick);
     
    139139        {
    140140            TetrisStone* stone = brick->getStone(i);
    141             if(! this->isValidMove(stone, position + stone->getPosition())) // wrong position??
     141            Vector3 stonePosition;
     142            if(isRotation)
     143                stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount()+1);
     144            else
     145                stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount());
     146
     147            /*orxout()<< "stoneRelativePoistion: " << stonePosition << endl;
     148            orxout()<< "stoneTotalPoistion   : " << position + stonePosition << endl;*/
     149
     150            if(! this->isValidMove(stone, position + stonePosition )) // wrong position??
     151            {
    142152                return false;
    143             orxout()<< "stoneRelativePoistion: " << stone->getPosition() << endl;
    144             orxout()<< "stoneTotalPoistion: " << position + stone->getPosition() << endl;
     153            }
    145154        }
    146155        return true;
     
    159168            if(this->activeBrick_->contains(*it))
    160169                continue;
    161 
    162             const Vector3& currentStonePosition = (*it)->getPosition(); //!< Saves the position of the currentStone
     170//TODO: is this rotation correct ??
     171            Vector3 currentStonePosition = rotateVector((*it)->getPosition(), this->activeBrick_->getRotationCount());
     172            //!< Saves the position of the currentStone
    163173
    164174            if((position.x == currentStonePosition.x) && (position.y < currentStonePosition.y + this->center_->getStoneSize()))
    165             {
     175            {//TODO: Why are such events not detected ??
     176                orxout()<< "YEAY !!"<<endl;
    166177                this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, currentStonePosition.y+this->center_->getStoneSize(), this->activeBrick_->getPosition().z));
    167178                return false;
     
    171182        // after we checked for collision with all stones, we also check for collision with the bottom
    172183        if(position.y < this->center_->getStoneSize()/2.0f) //!< If the stone has reached the bottom of the level
    173         {//TODO: correct positioning !!
    174                 this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, this->center_->getStoneSize()/2.0f, this->activeBrick_->getPosition().z));
     184        {
     185                int yOffset = stone->getPosition().y;//calculate offset
     186                this->activeBrick_->setPosition(Vector3(this->activeBrick_->getPosition().x, this->center_->getStoneSize()/2.0f+yOffset, this->activeBrick_->getPosition().z));
    175187            return false;
    176188        }
     
    186198        {
    187199            TetrisStone* stone = brick->getStone(i);
    188             if(! this->isValidStonePosition(stone, position + stone->getPosition()) ) // wrong position??
     200            Vector3 stonePosition = rotateVector(stone->getPosition(), brick->getRotationCount());
     201            if(! this->isValidStonePosition(stone, position + stonePosition) )
    189202                return false;
    190203        }
    191204        return true;
    192 
     205    }
     206
     207    /**
     208    @brief
     209        Nasty function that allocates memory!! it rolls a vector 90° * amount
     210    */
     211    Vector3 Tetris::rotateVector(Vector3 position, unsigned int amount)
     212    {
     213
     214        int temp = 0;
     215        for(unsigned int i = 0; i < amount; i++)
     216        {
     217            temp = position.x;
     218            position.x = -position.y;
     219            position.y = temp;
     220        }
     221        return position;
    193222    }
    194223
  • code/branches/pCuts/src/modules/tetris/Tetris.h

    r9082 r9084  
    7272
    7373            bool isValidMove(TetrisStone* stone, const Vector3& position);
    74             bool isValidMove(TetrisBrick* brick, const Vector3& position);
     74            bool isValidMove(TetrisBrick* brick, const Vector3& position, bool isRotation);
    7575
    7676        protected:
    7777            virtual void spawnPlayersIfRequested(); //!< Spawns player.
     78
    7879
    7980        private:
     
    8384            bool isValidStonePosition(TetrisStone* stone, const Vector3& position);
    8485            bool isValidBrickPosition(TetrisBrick* brick, const Vector3& position);
     86            Vector3 rotateVector(Vector3 position, unsigned int amount);
    8587           
    8688            PlayerInfo* player_;
  • code/branches/pCuts/src/modules/tetris/TetrisBrick.cc

    r9083 r9084  
    5353        RegisterObject(TetrisBrick);
    5454
    55         this->shapeIndex_ = 3; //<! TODO: random number between 0 and 7
     55        this->shapeIndex_ = 1; //<! TODO: random number between 0 and 7
    5656        this->stonesPerBrick_ = 4; //<! most tetris bricks is formed by 4 stones
    5757        this->delay_ = false;
     
    6060        this->tetris_ = this->getTetris();
    6161        this->size_ = 10.0f; //TODO: fix this via this->tetris_->center_->getStoneSize();
    62 
    63 
     62        this->rotationCount_ = 0;
    6463        this->createBrick(); //<! create a whole new Brick;
    6564    }
     
    7978            // Create a new stone and add it to the brick.
    8079            TetrisStone* stone = new TetrisStone(this);
    81             stone->setHealth(1.0f); //TODO: is this value low enough ?
     80            stone->setHealth(1.0f);
    8281            this->brickStones_.push_back(stone);
    8382            this->attach(stone);
     
    156155    }
    157156
    158     bool TetrisBrick::isValidMove(Vector3& position)
    159     {
    160 
    161         for(unsigned int i = 0; i < this->stonesPerBrick_ ; i++)
    162         {//TODO: check if isValidMove works with this function,
    163             if(this->tetris_->isValidMove(this->brickStones_[i], position))
    164                 continue;
    165             else
    166                 return false;
    167         }
    168         return true;
     157    bool TetrisBrick::isValidMove(const Vector3& position, bool isRotation = false)
     158    {
     159        return this->tetris_->isValidMove(this,position, isRotation);
    169160    }
    170161
     
    211202        else if(!this->lockRotation_) //rotate when key up is pressed
    212203        {
    213             orxout() << "The object should be rolled soon." << endl;
     204                if(!isValidMove(this->getPosition(), true)) //catch illegal rotations
     205                    return;
    214206            this->lockRotation_ = true; // multiple calls of this function have to be filtered out.
    215207            this->rotationTimer_.setTimer(0.1f, false, createExecutor(createFunctor(&TetrisBrick::unlockRotation, this)));
    216208            Quaternion q(Degree(90), Vector3::UNIT_Z);
    217209            this->setOrientation(this->getOrientation()*q); //rotation: roll 90°
    218 
     210            this->rotationCount_ = (this->rotationCount_ + 1) % 4;
    219211        }
    220212    }
  • code/branches/pCuts/src/modules/tetris/TetrisBrick.h

    r9082 r9084  
    6161            virtual void changedPlayer(); //!< Is called when the player changed.
    6262
    63             bool isValidMove(Vector3& position);
     63            bool isValidMove(const Vector3& position, bool isRotation);
    6464            unsigned int getNumberOfStones(void) const
    6565                { return this->brickStones_.size(); }
     
    6969            void setGame(Tetris* tetris)
    7070                { assert(tetris); tetris_ = tetris; }
     71            unsigned int getRotationCount(void)
     72                { return this->rotationCount_;}
    7173
    7274        protected:
     
    9395            bool lockRotation_;
    9496
     97            unsigned int rotationCount_; //!< Stores the bricks orientation
    9598            Timer delayTimer_;
    9699            Timer rotationTimer_; ///!< This timer is used to filter out multiple rotation inputs.
  • code/branches/pCuts/src/orxonox/worldentities/ControllableEntity.cc

    r9083 r9084  
    177177    {
    178178        if (this->cameraPositions_.size() <= 0)
    179             {orxout()<< "camareapositions_size == 0"<<endl ; return 0;}
     179            return 0;
    180180
    181181        unsigned int counter = 0;
     
    196196        if(this->camera_ != NULL && this->cameraPositions_.size() > 0)
    197197        {
    198         orxout()<< "Cameraposition is set."<<endl;
    199198            if(index >= this->cameraPositions_.size())
    200199                index = 0;
Note: See TracChangeset for help on using the changeset viewer.