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/
Triangle.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 "Triangle.h" |
adelino | 1:a74e42cf52b2 | 2 | |
adelino | 1:a74e42cf52b2 | 3 | Triangle::Triangle(Screen* mScreen,UINT16 _x1,UINT16 _y1, |
adelino | 1:a74e42cf52b2 | 4 | UINT16 _x2,UINT16 _y2, |
adelino | 1:a74e42cf52b2 | 5 | UINT16 _x3,UINT16 _y3,Color _color): |
adelino | 1:a74e42cf52b2 | 6 | Sprite(mScreen,0,_x2,_y1,_x3-_x2,_y3-_y1,_color) |
adelino | 1:a74e42cf52b2 | 7 | { |
adelino | 1:a74e42cf52b2 | 8 | myX1=_x1; |
adelino | 1:a74e42cf52b2 | 9 | myY1=_y1; |
adelino | 1:a74e42cf52b2 | 10 | myX2=_x2; |
adelino | 1:a74e42cf52b2 | 11 | myY2=_y2; |
adelino | 1:a74e42cf52b2 | 12 | myX3=_x3; |
adelino | 1:a74e42cf52b2 | 13 | myY3=_y3; |
adelino | 1:a74e42cf52b2 | 14 | myU=_x1-_x2; |
adelino | 1:a74e42cf52b2 | 15 | myV=_y2-_y1; |
adelino | 1:a74e42cf52b2 | 16 | |
adelino | 1:a74e42cf52b2 | 17 | myType=OBJ_TRIANGLE; |
adelino | 1:a74e42cf52b2 | 18 | |
adelino | 1:a74e42cf52b2 | 19 | myScreen->addWidget((Widget*) this); |
adelino | 1:a74e42cf52b2 | 20 | } |
adelino | 1:a74e42cf52b2 | 21 | //----------------------------------------------- |
adelino | 1:a74e42cf52b2 | 22 | Triangle::~Triangle(void) |
adelino | 1:a74e42cf52b2 | 23 | { |
adelino | 1:a74e42cf52b2 | 24 | } |
adelino | 1:a74e42cf52b2 | 25 | //----------------------------------------------- |
adelino | 1:a74e42cf52b2 | 26 | void Triangle::draw(void) |
adelino | 1:a74e42cf52b2 | 27 | { |
adelino | 1:a74e42cf52b2 | 28 | // isVisible ? |
adelino | 1:a74e42cf52b2 | 29 | if(myIsVisible==false) { |
adelino | 1:a74e42cf52b2 | 30 | return; |
adelino | 1:a74e42cf52b2 | 31 | } |
adelino | 1:a74e42cf52b2 | 32 | // |
adelino | 1:a74e42cf52b2 | 33 | PicasoSerial* ps=0; |
adelino | 1:a74e42cf52b2 | 34 | ps=myScreen->getPicasoSerial(); |
adelino | 1:a74e42cf52b2 | 35 | |
adelino | 1:a74e42cf52b2 | 36 | if(ps!=0) { |
adelino | 1:a74e42cf52b2 | 37 | ps->draw_filled_triangle(myX1,myY1,myX2,myY2,myX3,myY3,myColor); |
adelino | 1:a74e42cf52b2 | 38 | } |
adelino | 1:a74e42cf52b2 | 39 | ps=0; |
adelino | 1:a74e42cf52b2 | 40 | } |
adelino | 1:a74e42cf52b2 | 41 | //------------------------------------------------ |
adelino | 1:a74e42cf52b2 | 42 | void Triangle::setInvisible(bool _state) |
adelino | 1:a74e42cf52b2 | 43 | { |
adelino | 1:a74e42cf52b2 | 44 | // element devient invisible |
adelino | 1:a74e42cf52b2 | 45 | if(_state==true) { |
adelino | 1:a74e42cf52b2 | 46 | if(myIsVisible==false) |
adelino | 1:a74e42cf52b2 | 47 | return; |
adelino | 1:a74e42cf52b2 | 48 | |
adelino | 1:a74e42cf52b2 | 49 | myIsVisible=false; |
adelino | 1:a74e42cf52b2 | 50 | |
adelino | 1:a74e42cf52b2 | 51 | Color c= myScreen->getColorBkg(); |
adelino | 1:a74e42cf52b2 | 52 | |
adelino | 1:a74e42cf52b2 | 53 | PicasoSerial* ps=0; |
adelino | 1:a74e42cf52b2 | 54 | ps=myScreen->getPicasoSerial(); |
adelino | 1:a74e42cf52b2 | 55 | |
adelino | 1:a74e42cf52b2 | 56 | if(ps!=0) { |
adelino | 1:a74e42cf52b2 | 57 | ps->draw_filled_triangle(myX1,myY1,myX2,myY2,myX3,myY3,c); |
adelino | 1:a74e42cf52b2 | 58 | } |
adelino | 1:a74e42cf52b2 | 59 | ps=0; |
adelino | 1:a74e42cf52b2 | 60 | } |
adelino | 1:a74e42cf52b2 | 61 | |
adelino | 1:a74e42cf52b2 | 62 | // element devient visible |
adelino | 1:a74e42cf52b2 | 63 | else { |
adelino | 1:a74e42cf52b2 | 64 | myIsVisible=true; |
adelino | 1:a74e42cf52b2 | 65 | |
adelino | 1:a74e42cf52b2 | 66 | this->draw(); |
adelino | 1:a74e42cf52b2 | 67 | } |
adelino | 1:a74e42cf52b2 | 68 | } |
adelino | 1:a74e42cf52b2 | 69 | //------------------------------------------------ |
adelino | 1:a74e42cf52b2 | 70 | void Triangle::setNewPosition(INT16 _xnew,INT16 _ynew) |
adelino | 1:a74e42cf52b2 | 71 | { |
adelino | 1:a74e42cf52b2 | 72 | setNewPosition(_xnew,_ynew,true); |
adelino | 1:a74e42cf52b2 | 73 | } |
adelino | 1:a74e42cf52b2 | 74 | //------------------------------------------------ |
adelino | 1:a74e42cf52b2 | 75 | void Triangle::setNewPosition(INT16 _xnew,INT16 _ynew,bool isScreenLimits) |
adelino | 1:a74e42cf52b2 | 76 | { |
adelino | 1:a74e42cf52b2 | 77 | if(myIsVisible==false) |
adelino | 1:a74e42cf52b2 | 78 | return; |
adelino | 1:a74e42cf52b2 | 79 | // |
adelino | 1:a74e42cf52b2 | 80 | if(myX==_xnew && myY==_ynew) |
adelino | 1:a74e42cf52b2 | 81 | return; |
adelino | 1:a74e42cf52b2 | 82 | setInvisible(true); // colorie le tri avec couleur de la screen |
adelino | 1:a74e42cf52b2 | 83 | |
adelino | 1:a74e42cf52b2 | 84 | myIsVisible=true; |
adelino | 1:a74e42cf52b2 | 85 | if(isScreenLimits) { |
adelino | 1:a74e42cf52b2 | 86 | //test Xmax |
adelino | 1:a74e42cf52b2 | 87 | if(_xnew+myWidth >= myXMoveMax) { |
adelino | 1:a74e42cf52b2 | 88 | _xnew=myXMoveMax-myWidth; |
adelino | 1:a74e42cf52b2 | 89 | |
adelino | 1:a74e42cf52b2 | 90 | if(myState==STATE_ON) |
adelino | 1:a74e42cf52b2 | 91 | myState=BUMP_RIGHT; |
adelino | 1:a74e42cf52b2 | 92 | } |
adelino | 1:a74e42cf52b2 | 93 | // |
adelino | 1:a74e42cf52b2 | 94 | //test Xmin |
adelino | 1:a74e42cf52b2 | 95 | if(_xnew <= myXMoveMin) { |
adelino | 1:a74e42cf52b2 | 96 | _xnew=myXMoveMin; |
adelino | 1:a74e42cf52b2 | 97 | |
adelino | 1:a74e42cf52b2 | 98 | if(myState==STATE_ON) |
adelino | 1:a74e42cf52b2 | 99 | myState=BUMP_LEFT; |
adelino | 1:a74e42cf52b2 | 100 | } |
adelino | 1:a74e42cf52b2 | 101 | //test Ymax |
adelino | 1:a74e42cf52b2 | 102 | if(_ynew +myHeight >= myYMoveMax && _ynew >0) { |
adelino | 1:a74e42cf52b2 | 103 | _ynew = myYMoveMax- myHeight; |
adelino | 1:a74e42cf52b2 | 104 | |
adelino | 1:a74e42cf52b2 | 105 | if(myState==STATE_ON) |
adelino | 1:a74e42cf52b2 | 106 | myState=BUMP_DOWN; |
adelino | 1:a74e42cf52b2 | 107 | } |
adelino | 1:a74e42cf52b2 | 108 | //test yminMin; |
adelino | 1:a74e42cf52b2 | 109 | if(_ynew <= myYMoveMin) { |
adelino | 1:a74e42cf52b2 | 110 | _ynew=myYMoveMin; |
adelino | 1:a74e42cf52b2 | 111 | |
adelino | 1:a74e42cf52b2 | 112 | if(myState==STATE_ON) |
adelino | 1:a74e42cf52b2 | 113 | myState=BUMP_UP; |
adelino | 1:a74e42cf52b2 | 114 | } |
adelino | 1:a74e42cf52b2 | 115 | } |
adelino | 1:a74e42cf52b2 | 116 | // |
adelino | 1:a74e42cf52b2 | 117 | myX=_xnew; |
adelino | 1:a74e42cf52b2 | 118 | myY=_ynew; |
adelino | 1:a74e42cf52b2 | 119 | |
adelino | 1:a74e42cf52b2 | 120 | myX1=_xnew+myU; |
adelino | 1:a74e42cf52b2 | 121 | myY1=_ynew; |
adelino | 1:a74e42cf52b2 | 122 | |
adelino | 1:a74e42cf52b2 | 123 | myX2=_xnew; |
adelino | 1:a74e42cf52b2 | 124 | myY2=_ynew+myV; |
adelino | 1:a74e42cf52b2 | 125 | |
adelino | 1:a74e42cf52b2 | 126 | myX3=_xnew+myWidth; |
adelino | 1:a74e42cf52b2 | 127 | myY3=_ynew+myHeight; |
adelino | 1:a74e42cf52b2 | 128 | |
adelino | 1:a74e42cf52b2 | 129 | this->draw(); |
adelino | 1:a74e42cf52b2 | 130 | } |
adelino | 1:a74e42cf52b2 | 131 | //------------------------------------------------ |
adelino | 1:a74e42cf52b2 | 132 | void Triangle::update(float delta) |
adelino | 1:a74e42cf52b2 | 133 | { |
adelino | 1:a74e42cf52b2 | 134 | if(myIsUpdateAutomatic) |
adelino | 1:a74e42cf52b2 | 135 | elementUpdate(); |
adelino | 1:a74e42cf52b2 | 136 | // |
adelino | 1:a74e42cf52b2 | 137 | float xnew=myX+mySpeedX*delta; |
adelino | 1:a74e42cf52b2 | 138 | float ynew=myY+mySpeedY*delta; |
adelino | 1:a74e42cf52b2 | 139 | |
adelino | 1:a74e42cf52b2 | 140 | this->setNewPosition((INT16)xnew,(INT16)ynew,true); |
adelino | 1:a74e42cf52b2 | 141 | |
adelino | 1:a74e42cf52b2 | 142 | } |