|
@@ -422,28 +422,17 @@ bool Model2DData::calcHitPoint( Vertex pos, Vertex dir, const char *polygonName,
|
|
Vertex point = a + ( b * offset );
|
|
Vertex point = a + ( b * offset );
|
|
if( offset >= 0 && offset <= 1 )
|
|
if( offset >= 0 && offset <= 1 )
|
|
{
|
|
{
|
|
- if( !ret || ( hitpoint - pos ).getLengthSq() > ( point - pos ).getLengthSq() )
|
|
|
|
|
|
+ float f = ( point.x - pos.x ) / dir.x;
|
|
|
|
+ if( !dir.x )
|
|
|
|
+ f = ( point.y - pos.y ) / dir.y;
|
|
|
|
+ if( !ret || ( hitpoint - pos ).getLengthSq() > ( point - pos ).getLengthSq() && f > 0 )
|
|
{
|
|
{
|
|
Vertex normal = b.CW90().normalize();
|
|
Vertex normal = b.CW90().normalize();
|
|
Vertex kNorm = Vertex( dir ).normalize();
|
|
Vertex kNorm = Vertex( dir ).normalize();
|
|
moveSpeed = normal * ( normal * kNorm ) * dir.getLengthSq();
|
|
moveSpeed = normal * ( normal * kNorm ) * dir.getLengthSq();
|
|
normal = ( point - *polygon->var.schwerpunkt ).CW90().normalize();
|
|
normal = ( point - *polygon->var.schwerpunkt ).CW90().normalize();
|
|
Vertex rotKraft = normal * ( normal * kNorm ) * dir.getLength();
|
|
Vertex rotKraft = normal * ( normal * kNorm ) * dir.getLength();
|
|
- rotSpeed = ( ( rotKraft.getLength() * ( point - *polygon->var.schwerpunkt ).getLength() ) / 180.f ) * 3.14f;
|
|
|
|
- if( point.x >= polygon->var.schwerpunkt->x )
|
|
|
|
- {
|
|
|
|
- if( point.y >= polygon->var.schwerpunkt->y && rotKraft.x > 0 && rotKraft.y < 0 )
|
|
|
|
- rotSpeed = -rotSpeed;
|
|
|
|
- if( point.y < polygon->var.schwerpunkt->y && rotKraft.x < 0 && rotKraft.y < 0 )
|
|
|
|
- rotSpeed = -rotSpeed;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- if( point.y >= polygon->var.schwerpunkt->y && rotKraft.x > 0 && rotKraft.y > 0 )
|
|
|
|
- rotSpeed = -rotSpeed;
|
|
|
|
- if( point.y < polygon->var.schwerpunkt->y && rotKraft.x < 0 && rotKraft.y > 0 )
|
|
|
|
- rotSpeed = -rotSpeed;
|
|
|
|
- }
|
|
|
|
|
|
+ rotSpeed = ( ( rotKraft.getLength() * ( point - *polygon->var.schwerpunkt ).getLength() ) / 180.f ) * 3.14f * ( normal * kNorm );
|
|
hitpoint = point;
|
|
hitpoint = point;
|
|
}
|
|
}
|
|
ret = 1;
|
|
ret = 1;
|
|
@@ -699,15 +688,36 @@ void Model2DObject::setTextur( Textur2D *t )
|
|
|
|
|
|
void Model2DObject::impuls( Vertex start, Vertex speed )
|
|
void Model2DObject::impuls( Vertex start, Vertex speed )
|
|
{
|
|
{
|
|
|
|
+ start = getObjectPos( start );
|
|
|
|
+ speed = getObjectDir( speed );
|
|
if( rData )
|
|
if( rData )
|
|
{
|
|
{
|
|
|
|
+ Vertex resSpeed;
|
|
|
|
+ float resRotSpeed;
|
|
Vertex hp;
|
|
Vertex hp;
|
|
Vertex mSpeed;
|
|
Vertex mSpeed;
|
|
float rSpeed;
|
|
float rSpeed;
|
|
- if( rData->calcHitPoint( start, speed, "", hp, mSpeed, rSpeed ) )
|
|
|
|
|
|
+ float dist = INFINITY;
|
|
|
|
+ for( auto p = rData->polygons->getArray(); p.set; p++ )
|
|
{
|
|
{
|
|
- this->speed += mSpeed;
|
|
|
|
- this->rSpeed += rSpeed;
|
|
|
|
|
|
+ if( rData->calcHitPoint( start, speed, p.var.name->getText(), hp, mSpeed, rSpeed ) )
|
|
|
|
+ {
|
|
|
|
+ float f = ( hp.x - start.x ) / speed.x;
|
|
|
|
+ if( !speed.x )
|
|
|
|
+ f = ( hp.y - start.y ) / speed.y;
|
|
|
|
+ if( ( hp - start ).getLengthSq() < dist && f > 0 )
|
|
|
|
+ {
|
|
|
|
+ resSpeed = mSpeed.rotation( rotation );
|
|
|
|
+ resRotSpeed = rSpeed;
|
|
|
|
+ dist = ( hp - start ).getLengthSq();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // TODO schleife über alle polygone und translation von start und speed in Object koordinaten
|
|
|
|
+ if( dist < INFINITY )
|
|
|
|
+ {
|
|
|
|
+ this->speed += resSpeed;
|
|
|
|
+ this->rSpeed += resRotSpeed;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -862,6 +872,36 @@ Rect< float > Model2DObject::getBoundingBox() const
|
|
return Rect< float >();
|
|
return Rect< float >();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+bool Model2DObject::calcHitPoint( Vertex pos, Vertex dir, Vertex &hitpoint ) const
|
|
|
|
+{
|
|
|
|
+ pos = getObjectPos( pos );
|
|
|
|
+ dir = getObjectDir( dir );
|
|
|
|
+ Vertex ms;
|
|
|
|
+ Vertex hp;
|
|
|
|
+ float rs;
|
|
|
|
+ float dist = INFINITY;
|
|
|
|
+ if( rData )
|
|
|
|
+ {
|
|
|
|
+ for( auto p = rData->polygons->getArray(); p.set; p++ )
|
|
|
|
+ {
|
|
|
|
+ if( rData->calcHitPoint( pos, dir, p.var.name->getText(), hp, ms, rs ) )
|
|
|
|
+ {
|
|
|
|
+ float f = ( hp.x - pos.x ) / dir.x;
|
|
|
|
+ if( !speed.x )
|
|
|
|
+ f = ( hp.y - pos.y ) / dir.y;
|
|
|
|
+ if( ( hp - pos ).getLengthSq() < dist && f > 0 )
|
|
|
|
+ {
|
|
|
|
+ hitpoint = getObjectMatrix() * hp;
|
|
|
|
+ dist = ( hp - pos ).getLengthSq();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if( dist < INFINITY )
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
Model2DData *Model2DObject::getModel() const
|
|
Model2DData *Model2DObject::getModel() const
|
|
{
|
|
{
|
|
return rData ? rData->getThis() : 0;
|
|
return rData ? rData->getThis() : 0;
|