#include "PlayerKam.h" #include "Globals.h" PlayerKam::PlayerKam( Framework::Bildschirm3D* zScreen ) : Kam3D() { kameraControll = 0; setBildschirmPosition( 0, 0 ); setBildschirmSize( zScreen->getBackBufferSize() ); setStyle( Kam3D::Style::Tick | Kam3D::Style::Movable | Kam3D::Style::Rotatable ); setRotation( { (float)PI / 2.f, 0, 0 } ); } void PlayerKam::setDirection( Framework::Vec3 direction ) { if( direction.getLengthSq() > 0 ) { float rotZ = std::atan2( direction.y, direction.x ) + (float)PI / 2; setRotation( { getRotation().x, getRotation().y, rotZ } ); } } void PlayerKam::doTastaturEreignis( Framework::TastaturEreignis& te ) { char action[ 2 ]; if( te.id == TE_Press ) { action[ 0 ] = 1; if( te.taste == 'w' || te.taste == 'W' ) { action[ 1 ] = 0; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( te.taste == 'a' || te.taste == 'A' ) { action[ 1 ] = 1; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( te.taste == 's' || te.taste == 'S' ) { action[ 1 ] = 2; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( te.taste == 'd' || te.taste == 'D' ) { action[ 1 ] = 3; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( te.taste == T_Shift ) { action[ 1 ] = 4; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( te.taste == 'q' || te.taste == 'Q' ) { action[ 1 ] = 5; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( te.taste == 'e' || te.taste == 'E' ) { action[ 1 ] = 6; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( te.taste == T_Space ) { action[ 1 ] = 7; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( te.taste >= '0' && te.taste <= '9' ) { char action[ 5 ]; action[ 0 ] = 3; *(int*)(action + 1) = te.taste - '1'; if( *(int*)(action + 1) < 0 ) *(int*)(action + 1) = 9; network->zFactoryClient()->sendPlayerAction( &action, 5 ); } } if( te.id == TE_Release ) { action[ 0 ] = 0; if( te.taste == 'w' || te.taste == 'W' ) { action[ 1 ] = 0; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( te.taste == 'a' || te.taste == 'A' ) { action[ 1 ] = 1; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( te.taste == 's' || te.taste == 'S' ) { action[ 1 ] = 2; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( te.taste == 'd' || te.taste == 'D' ) { action[ 1 ] = 3; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( te.taste == T_Shift ) { action[ 1 ] = 4; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( te.taste == 'q' || te.taste == 'Q' ) { action[ 1 ] = 5; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( te.taste == 'e' || te.taste == 'E' ) { action[ 1 ] = 6; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( te.taste == T_Space ) { action[ 1 ] = 7; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( te.taste == T_Esc ) { kameraControll = 0; ShowCursor( true ); } } } void PlayerKam::doMausEreignis( Framework::MausEreignis& me ) { if( me.verarbeitet ) { kameraControll = 0; ShowCursor( true ); } else { if( !kameraControll ) { if( me.id == ME_PLinks ) { lastMousePos = { me.originalX, me.originalY }; kameraControll = 1; } } else { if( kameraControll ) { if( me.id == ME_Bewegung ) { int yDir = lastMousePos.y - me.originalY; int xDir = lastMousePos.x - me.originalX; setRotation( { min( max( getRotation().x - yDir * 0.005f, 0.1f ), 2.5f ), getRotation().y, getRotation().z - xDir * 0.005f } ); if( getRotation().z > 2 * PI ) setRotation( { getRotation().x, getRotation().y, getRotation().z - 2.f * (float)PI } ); if( getRotation().z < -2 * PI ) setRotation( { getRotation().x, getRotation().y, getRotation().z + 2.f * (float)PI } ); Vec3 direction = getWorldDirection( getScreenPos() + getScreenSize() / 2 ); char action[ 13 ]; action[ 0 ] = 2; *(float*)(action + 1) = direction.x; *(float*)(action + 5) = direction.y; *(float*)(action + 9) = direction.z; network->zFactoryClient()->sendPlayerAction( action, 13 ); SetCursorPos( lastMousePos.x + window->getPosition().x, lastMousePos.y + window->getPosition().y ); ShowCursor( false ); } if( me.id == ME_PLinks ) { char action[ 2 ] = { 1, 8 }; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( me.id == ME_RLinks ) { char action[ 2 ] = { 0, 8 }; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( me.id == ME_PRechts ) { char action[ 2 ] = { 1, 9 }; network->zFactoryClient()->sendPlayerAction( action, 2 ); } if( me.id == ME_RRechts ) { char action[ 2 ] = { 0, 9 }; network->zFactoryClient()->sendPlayerAction( action, 2 ); } } } me.verarbeitet = 1; } } bool PlayerKam::tick( double time ) { __int64 style = 0; if( hatStyle( Style::Movable ) ) style |= Style::Movable; if( hatStyle( Style::Rotatable ) ) style |= Style::Rotatable; if( hatStyle( Style::Zoomable ) ) style |= Style::Zoomable; removeStyle( Style::Movable | Style::Rotatable | Style::Zoomable ); bool result = Kam3D::tick( time ); addStyle( style ); return result; }