|
@@ -13,6 +13,7 @@ Kamera2D::Kamera2D()
|
|
|
rotation = 0;
|
|
|
matrix = Mat3< float >::identity();
|
|
|
zoom = 1;
|
|
|
+ tickWelt = 0;
|
|
|
ref = 1;
|
|
|
}
|
|
|
|
|
@@ -22,59 +23,36 @@ Kamera2D::~Kamera2D()
|
|
|
welt->release();
|
|
|
}
|
|
|
|
|
|
+void Kamera2D::lookAtWorldPos( int x, int y )
|
|
|
+{
|
|
|
+ wPos.x = (float)x;
|
|
|
+ wPos.y = (float)y;
|
|
|
+}
|
|
|
+
|
|
|
+void Kamera2D::lookAtWorldArea( int width, int height )
|
|
|
+{
|
|
|
+ zoom = (float)getBreite() / (float)width;
|
|
|
+ // TODO have two scaling factors
|
|
|
+}
|
|
|
+
|
|
|
void Kamera2D::setZoom( float zoom )
|
|
|
{
|
|
|
this->zoom = zoom;
|
|
|
}
|
|
|
|
|
|
-void Kamera2D::setWelt( Welt2D *welt )
|
|
|
+void Kamera2D::setWelt( Welt2D *welt, bool tick )
|
|
|
{
|
|
|
if( this->welt )
|
|
|
this->welt->release();
|
|
|
this->welt = welt;
|
|
|
+ tickWelt = tick;
|
|
|
}
|
|
|
|
|
|
bool Kamera2D::tick( double time )
|
|
|
{
|
|
|
bool ret = rend;
|
|
|
rend = 0;
|
|
|
- if( getTastenStand( 'q' ) )
|
|
|
- {
|
|
|
- rotation += (float)( time * 0.5 );
|
|
|
- ret = 1;
|
|
|
- }
|
|
|
- if( getTastenStand( 'e' ) )
|
|
|
- {
|
|
|
- rotation -= (float)( time * 0.5 );
|
|
|
- ret = 1;
|
|
|
- }
|
|
|
- Vertex move;
|
|
|
- if( getTastenStand( 'w' ) )
|
|
|
- move = Vertex( 0, -100 * (float)time );
|
|
|
- if( getTastenStand( 'a' ) )
|
|
|
- move = Vertex( -100 * (float)time, 0 );
|
|
|
- if( getTastenStand( 'd' ) )
|
|
|
- move = Vertex( 100 * (float)time, 0 );
|
|
|
- if( getTastenStand( 's' ) )
|
|
|
- move = Vertex( 0, +100 * (float)time );
|
|
|
- if( move != Vertex( 0, 0 ) )
|
|
|
- {
|
|
|
- wPos += move.rotation( -rotation ) * ( 1 / zoom );
|
|
|
- ret = 1;
|
|
|
- }
|
|
|
- if( getTastenStand( '+' ) )
|
|
|
- {
|
|
|
- zoom += ( zoom ) * (float)time;
|
|
|
- ret = 1;
|
|
|
- }
|
|
|
- if( getTastenStand( '-' ) )
|
|
|
- {
|
|
|
- zoom -= ( zoom ) * (float)time;
|
|
|
- if( zoom <= 0 )
|
|
|
- zoom = 1;
|
|
|
- ret = 1;
|
|
|
- }
|
|
|
- if( welt )
|
|
|
+ if( welt && tickWelt )
|
|
|
ret |= welt->tick( time );
|
|
|
return ret | ZeichnungHintergrund::tick( time );
|
|
|
}
|
|
@@ -104,13 +82,13 @@ Vertex Kamera2D::getWorldCoordinates( Punkt screenPos )
|
|
|
if( welt->getWorldInfo().circular && welt->getWorldInfo().hasSize && welt->getWorldInfo().size.x && welt->getWorldInfo().size.y )
|
|
|
{
|
|
|
while( wKoord.x < 0 )
|
|
|
- wKoord.x += welt->getWorldInfo().size.x;
|
|
|
+ wKoord.x += (float)welt->getWorldInfo().size.x;
|
|
|
while( wKoord.x > welt->getWorldInfo().size.x )
|
|
|
- wKoord.x -= welt->getWorldInfo().size.x;
|
|
|
+ wKoord.x -= (float)welt->getWorldInfo().size.x;
|
|
|
while( wKoord.y < 0 )
|
|
|
- wKoord.y += welt->getWorldInfo().size.y;
|
|
|
+ wKoord.y += (float)welt->getWorldInfo().size.y;
|
|
|
while( wKoord.y > welt->getWorldInfo().size.y )
|
|
|
- wKoord.y -= welt->getWorldInfo().size.y;
|
|
|
+ wKoord.y -= (float)welt->getWorldInfo().size.y;
|
|
|
}
|
|
|
return wKoord;
|
|
|
}
|
|
@@ -131,4 +109,47 @@ Kamera2D *Kamera2D::release()
|
|
|
if( !--ref )
|
|
|
delete this;
|
|
|
return 0;
|
|
|
+}
|
|
|
+
|
|
|
+bool TestKamera2D::tick( double time )
|
|
|
+{
|
|
|
+ bool ret = rend;
|
|
|
+ rend = Kamera2D::tick( time );
|
|
|
+ if( getTastenStand( 'q' ) )
|
|
|
+ {
|
|
|
+ rotation += (float)( time * 0.5 );
|
|
|
+ ret = 1;
|
|
|
+ }
|
|
|
+ if( getTastenStand( 'e' ) )
|
|
|
+ {
|
|
|
+ rotation -= (float)( time * 0.5 );
|
|
|
+ ret = 1;
|
|
|
+ }
|
|
|
+ Vertex move;
|
|
|
+ if( getTastenStand( 'w' ) )
|
|
|
+ move = Vertex( 0, -100 * (float)time );
|
|
|
+ if( getTastenStand( 'a' ) )
|
|
|
+ move = Vertex( -100 * (float)time, 0 );
|
|
|
+ if( getTastenStand( 'd' ) )
|
|
|
+ move = Vertex( 100 * (float)time, 0 );
|
|
|
+ if( getTastenStand( 's' ) )
|
|
|
+ move = Vertex( 0, +100 * (float)time );
|
|
|
+ if( move != Vertex( 0, 0 ) )
|
|
|
+ {
|
|
|
+ wPos += move.rotation( -rotation ) * ( 1 / zoom );
|
|
|
+ ret = 1;
|
|
|
+ }
|
|
|
+ if( getTastenStand( '+' ) )
|
|
|
+ {
|
|
|
+ zoom += ( zoom ) * (float)time;
|
|
|
+ ret = 1;
|
|
|
+ }
|
|
|
+ if( getTastenStand( '-' ) )
|
|
|
+ {
|
|
|
+ zoom -= ( zoom ) * (float)time;
|
|
|
+ if( zoom <= 0 )
|
|
|
+ zoom = 1;
|
|
|
+ ret = 1;
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
}
|