Library for 3.2'' uLcd Picaso Display4D system Picaso Serial Environment Command Set web: http://www.4dsystems.com.au/product/20/67/Processors_Graphics/PICASO/
Isocele.cpp@1:a74e42cf52b2, 2015-04-05 (annotated)
- Committer:
- adelino
- Date:
- Sun Apr 05 13:54:48 2015 +0000
- Revision:
- 1:a74e42cf52b2
PicasoLib version 2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
adelino | 1:a74e42cf52b2 | 1 | #include "Isocele.h" |
adelino | 1:a74e42cf52b2 | 2 | |
adelino | 1:a74e42cf52b2 | 3 | void Isocele::updateOrientation(void) |
adelino | 1:a74e42cf52b2 | 4 | { |
adelino | 1:a74e42cf52b2 | 5 | switch(myOrientation) { |
adelino | 1:a74e42cf52b2 | 6 | // |
adelino | 1:a74e42cf52b2 | 7 | case Isocele::ORIENTATION_UP: |
adelino | 1:a74e42cf52b2 | 8 | mySpeedX=0.0; |
adelino | 1:a74e42cf52b2 | 9 | mySpeedY=-mySpeed; |
adelino | 1:a74e42cf52b2 | 10 | |
adelino | 1:a74e42cf52b2 | 11 | myX=myXcenter-myRadius; |
adelino | 1:a74e42cf52b2 | 12 | myY=myYcenter-myRadius; |
adelino | 1:a74e42cf52b2 | 13 | myWidth=myRadius+myRadius; |
adelino | 1:a74e42cf52b2 | 14 | myHeight=myRadius; |
adelino | 1:a74e42cf52b2 | 15 | |
adelino | 1:a74e42cf52b2 | 16 | myX1=myXcenter; |
adelino | 1:a74e42cf52b2 | 17 | myY1=myYcenter-myRadius; |
adelino | 1:a74e42cf52b2 | 18 | |
adelino | 1:a74e42cf52b2 | 19 | myX2=myXcenter-myRadius; |
adelino | 1:a74e42cf52b2 | 20 | myY2=myYcenter; |
adelino | 1:a74e42cf52b2 | 21 | |
adelino | 1:a74e42cf52b2 | 22 | myX3=myXcenter+myRadius; |
adelino | 1:a74e42cf52b2 | 23 | myY3=myYcenter; |
adelino | 1:a74e42cf52b2 | 24 | break; |
adelino | 1:a74e42cf52b2 | 25 | |
adelino | 1:a74e42cf52b2 | 26 | // |
adelino | 1:a74e42cf52b2 | 27 | case Isocele::ORIENTATION_RIGHT: |
adelino | 1:a74e42cf52b2 | 28 | mySpeedX=mySpeed; |
adelino | 1:a74e42cf52b2 | 29 | mySpeedY=0.0; |
adelino | 1:a74e42cf52b2 | 30 | |
adelino | 1:a74e42cf52b2 | 31 | myX=myXcenter; |
adelino | 1:a74e42cf52b2 | 32 | myY=myYcenter-myRadius; |
adelino | 1:a74e42cf52b2 | 33 | myWidth=myRadius; |
adelino | 1:a74e42cf52b2 | 34 | myHeight=myRadius+myRadius; |
adelino | 1:a74e42cf52b2 | 35 | |
adelino | 1:a74e42cf52b2 | 36 | myX1=myXcenter; |
adelino | 1:a74e42cf52b2 | 37 | myY1=myYcenter-myRadius; |
adelino | 1:a74e42cf52b2 | 38 | |
adelino | 1:a74e42cf52b2 | 39 | myX2=myXcenter; |
adelino | 1:a74e42cf52b2 | 40 | myY2=myYcenter+myRadius; |
adelino | 1:a74e42cf52b2 | 41 | |
adelino | 1:a74e42cf52b2 | 42 | myX3=myXcenter+myRadius; |
adelino | 1:a74e42cf52b2 | 43 | myY3=myYcenter; |
adelino | 1:a74e42cf52b2 | 44 | break; |
adelino | 1:a74e42cf52b2 | 45 | |
adelino | 1:a74e42cf52b2 | 46 | // |
adelino | 1:a74e42cf52b2 | 47 | case Isocele::ORIENTATION_DOWN: |
adelino | 1:a74e42cf52b2 | 48 | mySpeedX=0.0; |
adelino | 1:a74e42cf52b2 | 49 | mySpeedY=mySpeed; |
adelino | 1:a74e42cf52b2 | 50 | |
adelino | 1:a74e42cf52b2 | 51 | myX=myXcenter-myRadius; |
adelino | 1:a74e42cf52b2 | 52 | myY=myYcenter; |
adelino | 1:a74e42cf52b2 | 53 | myWidth=myRadius+myRadius; |
adelino | 1:a74e42cf52b2 | 54 | myHeight=myRadius; |
adelino | 1:a74e42cf52b2 | 55 | |
adelino | 1:a74e42cf52b2 | 56 | myX1=myXcenter-myRadius; |
adelino | 1:a74e42cf52b2 | 57 | myY1=myYcenter; |
adelino | 1:a74e42cf52b2 | 58 | |
adelino | 1:a74e42cf52b2 | 59 | myX2=myXcenter; |
adelino | 1:a74e42cf52b2 | 60 | myY2=myYcenter+myRadius; |
adelino | 1:a74e42cf52b2 | 61 | |
adelino | 1:a74e42cf52b2 | 62 | myX3=myXcenter+myRadius; |
adelino | 1:a74e42cf52b2 | 63 | myY3=myYcenter; |
adelino | 1:a74e42cf52b2 | 64 | break; |
adelino | 1:a74e42cf52b2 | 65 | |
adelino | 1:a74e42cf52b2 | 66 | // |
adelino | 1:a74e42cf52b2 | 67 | case Isocele::ORIENTATION_LEFT: |
adelino | 1:a74e42cf52b2 | 68 | mySpeedX=-mySpeed; |
adelino | 1:a74e42cf52b2 | 69 | mySpeedY=0.0; |
adelino | 1:a74e42cf52b2 | 70 | |
adelino | 1:a74e42cf52b2 | 71 | myX=myXcenter-myRadius; |
adelino | 1:a74e42cf52b2 | 72 | myY=myYcenter-myRadius; |
adelino | 1:a74e42cf52b2 | 73 | myWidth=myRadius; |
adelino | 1:a74e42cf52b2 | 74 | myHeight=myRadius+myRadius; |
adelino | 1:a74e42cf52b2 | 75 | |
adelino | 1:a74e42cf52b2 | 76 | myX1=myXcenter-myRadius; |
adelino | 1:a74e42cf52b2 | 77 | myY1=myYcenter; |
adelino | 1:a74e42cf52b2 | 78 | |
adelino | 1:a74e42cf52b2 | 79 | myX2=myXcenter; |
adelino | 1:a74e42cf52b2 | 80 | myY2=myYcenter+myRadius; |
adelino | 1:a74e42cf52b2 | 81 | |
adelino | 1:a74e42cf52b2 | 82 | myX3=myXcenter; |
adelino | 1:a74e42cf52b2 | 83 | myY3=myYcenter-myRadius; |
adelino | 1:a74e42cf52b2 | 84 | break; |
adelino | 1:a74e42cf52b2 | 85 | |
adelino | 1:a74e42cf52b2 | 86 | // |
adelino | 1:a74e42cf52b2 | 87 | default: |
adelino | 1:a74e42cf52b2 | 88 | break; |
adelino | 1:a74e42cf52b2 | 89 | |
adelino | 1:a74e42cf52b2 | 90 | } |
adelino | 1:a74e42cf52b2 | 91 | |
adelino | 1:a74e42cf52b2 | 92 | } |
adelino | 1:a74e42cf52b2 | 93 | //-------------------------------------------- |
adelino | 1:a74e42cf52b2 | 94 | Isocele::Isocele(Screen* mScreen,UINT16 xc,UINT16 yc,UINT16 radius,int orientation,float _speed, |
adelino | 1:a74e42cf52b2 | 95 | Color color): |
adelino | 1:a74e42cf52b2 | 96 | Sprite(mScreen,0,xc-radius,yc-radius,radius+radius,radius,color) |
adelino | 1:a74e42cf52b2 | 97 | { |
adelino | 1:a74e42cf52b2 | 98 | myXcenter=xc; |
adelino | 1:a74e42cf52b2 | 99 | myYcenter=yc; |
adelino | 1:a74e42cf52b2 | 100 | myRadius=radius; |
adelino | 1:a74e42cf52b2 | 101 | myOrientation=orientation; |
adelino | 1:a74e42cf52b2 | 102 | mySpeed=_speed; |
adelino | 1:a74e42cf52b2 | 103 | |
adelino | 1:a74e42cf52b2 | 104 | updateOrientation(); |
adelino | 1:a74e42cf52b2 | 105 | |
adelino | 1:a74e42cf52b2 | 106 | myIsUpdateAutomatic=false; |
adelino | 1:a74e42cf52b2 | 107 | |
adelino | 1:a74e42cf52b2 | 108 | myType=OBJ_ISOCELE; |
adelino | 1:a74e42cf52b2 | 109 | |
adelino | 1:a74e42cf52b2 | 110 | myScreen->addWidget((Widget*) this); |
adelino | 1:a74e42cf52b2 | 111 | } |
adelino | 1:a74e42cf52b2 | 112 | //-------------------------------------------- |
adelino | 1:a74e42cf52b2 | 113 | void Isocele::draw(void) |
adelino | 1:a74e42cf52b2 | 114 | { |
adelino | 1:a74e42cf52b2 | 115 | // isVisible ? |
adelino | 1:a74e42cf52b2 | 116 | if(myIsVisible==false) { |
adelino | 1:a74e42cf52b2 | 117 | return; |
adelino | 1:a74e42cf52b2 | 118 | } |
adelino | 1:a74e42cf52b2 | 119 | // |
adelino | 1:a74e42cf52b2 | 120 | PicasoSerial* ps=0; |
adelino | 1:a74e42cf52b2 | 121 | ps=myScreen->getPicasoSerial(); |
adelino | 1:a74e42cf52b2 | 122 | |
adelino | 1:a74e42cf52b2 | 123 | if(ps!=0) { |
adelino | 1:a74e42cf52b2 | 124 | ps->draw_filled_triangle(myX1,myY1,myX2,myY2,myX3,myY3,myColor); |
adelino | 1:a74e42cf52b2 | 125 | // |
adelino | 1:a74e42cf52b2 | 126 | //ps->draw_rectangle(myX,myY,myX+myWidth,myY+myHeight,BLACK); |
adelino | 1:a74e42cf52b2 | 127 | } |
adelino | 1:a74e42cf52b2 | 128 | ps=0; |
adelino | 1:a74e42cf52b2 | 129 | } |
adelino | 1:a74e42cf52b2 | 130 | //--------------------------------------------- |
adelino | 1:a74e42cf52b2 | 131 | Isocele::~Isocele(void) |
adelino | 1:a74e42cf52b2 | 132 | { |
adelino | 1:a74e42cf52b2 | 133 | } |
adelino | 1:a74e42cf52b2 | 134 | //-------------------------------------------- |
adelino | 1:a74e42cf52b2 | 135 | void Isocele:: setInvisible(bool _state) |
adelino | 1:a74e42cf52b2 | 136 | { |
adelino | 1:a74e42cf52b2 | 137 | // element devient invisible |
adelino | 1:a74e42cf52b2 | 138 | if(_state==true) { |
adelino | 1:a74e42cf52b2 | 139 | if(myIsVisible==false) |
adelino | 1:a74e42cf52b2 | 140 | return; |
adelino | 1:a74e42cf52b2 | 141 | |
adelino | 1:a74e42cf52b2 | 142 | myIsVisible=false; |
adelino | 1:a74e42cf52b2 | 143 | |
adelino | 1:a74e42cf52b2 | 144 | Color c= myScreen->getColorBkg(); |
adelino | 1:a74e42cf52b2 | 145 | |
adelino | 1:a74e42cf52b2 | 146 | PicasoSerial* ps=0; |
adelino | 1:a74e42cf52b2 | 147 | ps=myScreen->getPicasoSerial(); |
adelino | 1:a74e42cf52b2 | 148 | |
adelino | 1:a74e42cf52b2 | 149 | if(ps!=0) { |
adelino | 1:a74e42cf52b2 | 150 | ps->draw_filled_triangle(myX1,myY1,myX2,myY2,myX3,myY3,c); |
adelino | 1:a74e42cf52b2 | 151 | //ps->draw_rectangle(myX,myY,myX+myWidth,myY+myHeight,c); |
adelino | 1:a74e42cf52b2 | 152 | } |
adelino | 1:a74e42cf52b2 | 153 | ps=0; |
adelino | 1:a74e42cf52b2 | 154 | } |
adelino | 1:a74e42cf52b2 | 155 | |
adelino | 1:a74e42cf52b2 | 156 | // element devient visible |
adelino | 1:a74e42cf52b2 | 157 | else { |
adelino | 1:a74e42cf52b2 | 158 | myIsVisible=true; |
adelino | 1:a74e42cf52b2 | 159 | |
adelino | 1:a74e42cf52b2 | 160 | this->draw(); |
adelino | 1:a74e42cf52b2 | 161 | } |
adelino | 1:a74e42cf52b2 | 162 | } |
adelino | 1:a74e42cf52b2 | 163 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 164 | void Isocele::setNewPosition(INT16 _xcnew,INT16 _ycnew) |
adelino | 1:a74e42cf52b2 | 165 | { |
adelino | 1:a74e42cf52b2 | 166 | setNewPosition(_xcnew,_ycnew,true); |
adelino | 1:a74e42cf52b2 | 167 | } |
adelino | 1:a74e42cf52b2 | 168 | //------------------------------------------- |
adelino | 1:a74e42cf52b2 | 169 | void Isocele::setNewPosition(INT16 _xcnew,INT16 _ycnew,bool isScreenLimits) |
adelino | 1:a74e42cf52b2 | 170 | { |
adelino | 1:a74e42cf52b2 | 171 | if(myIsVisible==false) |
adelino | 1:a74e42cf52b2 | 172 | return; |
adelino | 1:a74e42cf52b2 | 173 | // |
adelino | 1:a74e42cf52b2 | 174 | if(myXcenter==_xcnew && myYcenter==_ycnew) |
adelino | 1:a74e42cf52b2 | 175 | return; |
adelino | 1:a74e42cf52b2 | 176 | // |
adelino | 1:a74e42cf52b2 | 177 | this->setInvisible(true); |
adelino | 1:a74e42cf52b2 | 178 | |
adelino | 1:a74e42cf52b2 | 179 | myIsVisible=true; |
adelino | 1:a74e42cf52b2 | 180 | if(isScreenLimits) |
adelino | 1:a74e42cf52b2 | 181 | { |
adelino | 1:a74e42cf52b2 | 182 | |
adelino | 1:a74e42cf52b2 | 183 | //test Xmax |
adelino | 1:a74e42cf52b2 | 184 | if(_xcnew+myRadius >= myXMoveMax) { |
adelino | 1:a74e42cf52b2 | 185 | _xcnew=myXMoveMax-myRadius; |
adelino | 1:a74e42cf52b2 | 186 | |
adelino | 1:a74e42cf52b2 | 187 | if(myState==STATE_ON) |
adelino | 1:a74e42cf52b2 | 188 | myState=BUMP_RIGHT; |
adelino | 1:a74e42cf52b2 | 189 | } |
adelino | 1:a74e42cf52b2 | 190 | |
adelino | 1:a74e42cf52b2 | 191 | //test Xmin |
adelino | 1:a74e42cf52b2 | 192 | if(_xcnew <= myRadius) { |
adelino | 1:a74e42cf52b2 | 193 | _xcnew=myXMoveMin+myRadius; |
adelino | 1:a74e42cf52b2 | 194 | |
adelino | 1:a74e42cf52b2 | 195 | if(myState==STATE_ON) |
adelino | 1:a74e42cf52b2 | 196 | myState=BUMP_LEFT; |
adelino | 1:a74e42cf52b2 | 197 | } |
adelino | 1:a74e42cf52b2 | 198 | //test Ymax |
adelino | 1:a74e42cf52b2 | 199 | if(_ycnew +myRadius >= myYMoveMax && _ycnew >0) { |
adelino | 1:a74e42cf52b2 | 200 | _ycnew = myYMoveMax- myRadius; |
adelino | 1:a74e42cf52b2 | 201 | |
adelino | 1:a74e42cf52b2 | 202 | if(myState==STATE_ON) |
adelino | 1:a74e42cf52b2 | 203 | myState=BUMP_DOWN; |
adelino | 1:a74e42cf52b2 | 204 | } |
adelino | 1:a74e42cf52b2 | 205 | //test yminMin; |
adelino | 1:a74e42cf52b2 | 206 | if(_ycnew <= myRadius) { |
adelino | 1:a74e42cf52b2 | 207 | _ycnew=myYMoveMin+myRadius; |
adelino | 1:a74e42cf52b2 | 208 | |
adelino | 1:a74e42cf52b2 | 209 | if(myState==STATE_ON) |
adelino | 1:a74e42cf52b2 | 210 | myState=BUMP_UP; |
adelino | 1:a74e42cf52b2 | 211 | } |
adelino | 1:a74e42cf52b2 | 212 | } |
adelino | 1:a74e42cf52b2 | 213 | // |
adelino | 1:a74e42cf52b2 | 214 | myXcenter=_xcnew; |
adelino | 1:a74e42cf52b2 | 215 | myYcenter=_ycnew; |
adelino | 1:a74e42cf52b2 | 216 | |
adelino | 1:a74e42cf52b2 | 217 | updateOrientation(); |
adelino | 1:a74e42cf52b2 | 218 | |
adelino | 1:a74e42cf52b2 | 219 | this->draw(); |
adelino | 1:a74e42cf52b2 | 220 | } |
adelino | 1:a74e42cf52b2 | 221 | //-------------------------------------------- |
adelino | 1:a74e42cf52b2 | 222 | void Isocele::myElementUpdate(void) |
adelino | 1:a74e42cf52b2 | 223 | { |
adelino | 1:a74e42cf52b2 | 224 | switch(myState) { |
adelino | 1:a74e42cf52b2 | 225 | // |
adelino | 1:a74e42cf52b2 | 226 | case BUMP_DOWN: |
adelino | 1:a74e42cf52b2 | 227 | setInvertSpeedY(); |
adelino | 1:a74e42cf52b2 | 228 | myState=STATE_ON; |
adelino | 1:a74e42cf52b2 | 229 | myOrientation=Isocele::ORIENTATION_UP; |
adelino | 1:a74e42cf52b2 | 230 | break; |
adelino | 1:a74e42cf52b2 | 231 | // |
adelino | 1:a74e42cf52b2 | 232 | case BUMP_LEFT: |
adelino | 1:a74e42cf52b2 | 233 | setInvertSpeedX(); |
adelino | 1:a74e42cf52b2 | 234 | myState=STATE_ON; |
adelino | 1:a74e42cf52b2 | 235 | myOrientation=Isocele::ORIENTATION_RIGHT; |
adelino | 1:a74e42cf52b2 | 236 | break; |
adelino | 1:a74e42cf52b2 | 237 | // |
adelino | 1:a74e42cf52b2 | 238 | case BUMP_RIGHT: |
adelino | 1:a74e42cf52b2 | 239 | setInvertSpeedX(); |
adelino | 1:a74e42cf52b2 | 240 | myState=STATE_ON; |
adelino | 1:a74e42cf52b2 | 241 | myOrientation=Isocele::ORIENTATION_LEFT; |
adelino | 1:a74e42cf52b2 | 242 | break; |
adelino | 1:a74e42cf52b2 | 243 | // |
adelino | 1:a74e42cf52b2 | 244 | case BUMP_UP: |
adelino | 1:a74e42cf52b2 | 245 | setInvertSpeedY(); |
adelino | 1:a74e42cf52b2 | 246 | myState=STATE_ON; |
adelino | 1:a74e42cf52b2 | 247 | myOrientation=Isocele::ORIENTATION_DOWN; |
adelino | 1:a74e42cf52b2 | 248 | break; |
adelino | 1:a74e42cf52b2 | 249 | // |
adelino | 1:a74e42cf52b2 | 250 | case STATE_OFF: |
adelino | 1:a74e42cf52b2 | 251 | break; |
adelino | 1:a74e42cf52b2 | 252 | // |
adelino | 1:a74e42cf52b2 | 253 | default: |
adelino | 1:a74e42cf52b2 | 254 | break; |
adelino | 1:a74e42cf52b2 | 255 | } |
adelino | 1:a74e42cf52b2 | 256 | } |
adelino | 1:a74e42cf52b2 | 257 | //-------------------------------------------- |
adelino | 1:a74e42cf52b2 | 258 | void Isocele::update(float delta) |
adelino | 1:a74e42cf52b2 | 259 | { |
adelino | 1:a74e42cf52b2 | 260 | if(myIsUpdateAutomatic) |
adelino | 1:a74e42cf52b2 | 261 | myElementUpdate(); |
adelino | 1:a74e42cf52b2 | 262 | // |
adelino | 1:a74e42cf52b2 | 263 | float xnew=myXcenter+mySpeedX*delta; |
adelino | 1:a74e42cf52b2 | 264 | float ynew=myYcenter+mySpeedY*delta; |
adelino | 1:a74e42cf52b2 | 265 | |
adelino | 1:a74e42cf52b2 | 266 | this->setNewPosition((INT16)xnew,(INT16)ynew,true); |
adelino | 1:a74e42cf52b2 | 267 | |
adelino | 1:a74e42cf52b2 | 268 | } |
adelino | 1:a74e42cf52b2 | 269 | //-------------------------------------------- |
adelino | 1:a74e42cf52b2 | 270 | void Isocele::setOrientation(int _orientation) |
adelino | 1:a74e42cf52b2 | 271 | { |
adelino | 1:a74e42cf52b2 | 272 | myOrientation=_orientation; |
adelino | 1:a74e42cf52b2 | 273 | |
adelino | 1:a74e42cf52b2 | 274 | } |
adelino | 1:a74e42cf52b2 | 275 | //-------------------------------------------- |
adelino | 1:a74e42cf52b2 | 276 | int Isocele::getOrientation(void) const |
adelino | 1:a74e42cf52b2 | 277 | { |
adelino | 1:a74e42cf52b2 | 278 | return this->myOrientation; |
adelino | 1:a74e42cf52b2 | 279 | } |
adelino | 1:a74e42cf52b2 | 280 | //-------------------------------------------- |
adelino | 1:a74e42cf52b2 | 281 | UINT16 Isocele::getXcenter(void) const |
adelino | 1:a74e42cf52b2 | 282 | { |
adelino | 1:a74e42cf52b2 | 283 | return this->myXcenter; |
adelino | 1:a74e42cf52b2 | 284 | } |
adelino | 1:a74e42cf52b2 | 285 | //-------------------------------------------- |
adelino | 1:a74e42cf52b2 | 286 | UINT16 Isocele::getYcenter(void) const |
adelino | 1:a74e42cf52b2 | 287 | { |
adelino | 1:a74e42cf52b2 | 288 | return this->myYcenter; |
adelino | 1:a74e42cf52b2 | 289 | } |
adelino | 1:a74e42cf52b2 | 290 | //-------------------------------------------- |
adelino | 1:a74e42cf52b2 | 291 | void Isocele::turnLeft(void) |
adelino | 1:a74e42cf52b2 | 292 | { |
adelino | 1:a74e42cf52b2 | 293 | myOrientation+=1; |
adelino | 1:a74e42cf52b2 | 294 | |
adelino | 1:a74e42cf52b2 | 295 | if(myOrientation >Isocele::ORIENTATION_RIGHT) |
adelino | 1:a74e42cf52b2 | 296 | myOrientation=ORIENTATION_UP; |
adelino | 1:a74e42cf52b2 | 297 | |
adelino | 1:a74e42cf52b2 | 298 | } |
adelino | 1:a74e42cf52b2 | 299 | //-------------------------------------------- |
adelino | 1:a74e42cf52b2 | 300 | void Isocele::turnRight(void) |
adelino | 1:a74e42cf52b2 | 301 | { |
adelino | 1:a74e42cf52b2 | 302 | myOrientation-=1; |
adelino | 1:a74e42cf52b2 | 303 | |
adelino | 1:a74e42cf52b2 | 304 | if(myOrientation <Isocele::ORIENTATION_UP) |
adelino | 1:a74e42cf52b2 | 305 | myOrientation=ORIENTATION_RIGHT; |
adelino | 1:a74e42cf52b2 | 306 | |
adelino | 1:a74e42cf52b2 | 307 | } |