////////////////////////////////////////////////////////////////////////// // getScreenPosition MaVec2d ScnViewComponent::getScreenPosition( const MaVec3d& WorldPosition ) const { MaVec4d ScreenSpace = MaVec4d( WorldPosition, 1.0f ) * ViewUniformBlock_.ClipTransform_; MaVec2d ScreenPosition = MaVec2d( ScreenSpace.x() / ScreenSpace.w(), -ScreenSpace.y() / ScreenSpace.w() ); BcF32 HalfW = BcF32( Viewport_.width() ) * 0.5f; BcF32 HalfH = BcF32( Viewport_.height() ) * 0.5f; return MaVec2d( ( ScreenPosition.x() * HalfW ), ( ScreenPosition.y() * HalfH ) ); }
////////////////////////////////////////////////////////////////////////// // getDepth BcU32 ScnViewComponent::getDepth( const MaVec3d& WorldPos ) const { MaVec4d ScreenSpace = MaVec4d( WorldPos, 1.0f ) * ViewUniformBlock_.ClipTransform_; BcF32 Depth = 1.0f - BcClamp( ScreenSpace.z() / ScreenSpace.w(), 0.0f, 1.0f ); return BcU32( Depth * BcF32( 0xffffff ) ); }
////////////////////////////////////////////////////////////////////////// // drawEllipsoid void ScnDebugRenderComponent::drawEllipsoid( const MaVec3d& Position, const MaVec3d& Size, const RsColour& Colour, BcU32 Layer ) { // Draw outer circles for all axis. BcU32 LOD = 16; BcF32 Angle = 0.0f; BcF32 AngleInc = ( BcPI * 2.0f ) / BcF32( LOD ); // Draw axis lines. for( BcU32 i = 0; i < LOD; ++i ) { MaVec2d PosA( BcCos( Angle ), -BcSin( Angle ) ); MaVec2d PosB( BcCos( Angle + AngleInc ), -BcSin( Angle + AngleInc ) ); MaVec3d XAxisA = MaVec3d( 0.0f, PosA.x() * Size.y(), PosA.y() * Size.z() ); MaVec3d YAxisA = MaVec3d( PosA.x() * Size.x(), 0.0f, PosA.y() * Size.z() ); MaVec3d ZAxisA = MaVec3d( PosA.x() * Size.x(), PosA.y() * Size.y(), 0.0f ); MaVec3d XAxisB = MaVec3d( 0.0f, PosB.x() * Size.y(), PosB.y() * Size.z() ); MaVec3d YAxisB = MaVec3d( PosB.x() * Size.x(), 0.0f, PosB.y() * Size.z() ); MaVec3d ZAxisB = MaVec3d( PosB.x() * Size.x(), PosB.y() * Size.y(), 0.0f ); drawLine( XAxisA + Position, XAxisB + Position, Colour, 0 ); drawLine( YAxisA + Position, YAxisB + Position, Colour, 0 ); drawLine( ZAxisA + Position, ZAxisB + Position, Colour, 0 ); Angle += AngleInc; } // Draw a cross down centre. MaVec3d XAxis = MaVec3d( Size.x(), 0.0f, 0.0f ); MaVec3d YAxis = MaVec3d( 0.0f, Size.y(), 0.0f ); MaVec3d ZAxis = MaVec3d( 0.0f, 0.0f, Size.z() ); drawLine( Position - XAxis, Position + XAxis, Colour, Layer ); drawLine( Position - YAxis, Position + YAxis, Colour, Layer ); drawLine( Position - ZAxis, Position + ZAxis, Colour, Layer ); }
////////////////////////////////////////////////////////////////////////// // initialise void GaSpeechBubbleComponent::initialise( const Json::Value& Object ) { GaSpeechBubbleComponent::initialise(); if ( Object[ "requiredSize" ].type() != Json::nullValue ) RequiredSize_ = BcF32( Object[ "requiredsize" ].asDouble() ); if ( Object[ "visibletime" ].type() != Json::nullValue ) VisibleTime_ = BcF32( Object[ "visibletime" ].asDouble() ); if ( Object[ "visible" ].type() != Json::nullValue ) Visible_ = ( Object[ "visible" ].asBool() ); if ( Object[ "spriteoffset" ].type() != Json::nullValue ) SpriteOffset_ = MaVec2d( Object[ "spriteoffset" ].asCString() ); if ( Object[ "text" ].type() != Json::nullValue ) { std::string text = Object[ "text" ].asString(); setText(text); } }
////////////////////////////////////////////////////////////////////////// // update //virtual void GaRobotComponent::update( BcF32 Tick ) { if( Health_ <= 0.0f ) { return; } CurrentOpTimer_ -= Tick; if( CurrentOpTimer_ < 0.0f ) { CurrentOpTimer_ += CurrentOpTime_; // Handle robot program. BcBool ExecutedCode = BcFalse; if( Program_.size() > 0 ) { CurrentOp_ = NextOp_; const auto& Op = Program_[ CurrentOp_ ]; if( Op.State_ == CurrentState_ ) { auto Condition = ProgramFunctionMap_[ Op.Condition_ ]; if( Condition != nullptr ) { if( Condition( this, Op.ConditionVar_ ) ) { auto Operation = ProgramFunctionMap_[ Op.Operation_ ]; if( Operation == nullptr ) { BcPrintf( "No operation \"%s\"\n", Op.Operation_.c_str() ); } else { auto RetVal = Operation( this, Op.OperationVar_ ); if( RetVal != BcErrorCode ) { CurrentState_ = RetVal; } } } } ExecutedCode = BcTrue; } // Advance to next valid op. if( ExecutedCode ) { for( BcU32 Idx = 0; Idx < Program_.size(); ++Idx ) { NextOp_ = ( NextOp_ + 1 ) % Program_.size(); if( Program_[ NextOp_ ].State_ == CurrentState_ ) { break; } } } // Did we fail to run code? If so, reset to op 0 and the state of op 0. if( ExecutedCode == BcFalse ) { NextOp_ = 0; CurrentState_ = Program_[ NextOp_ ].State_; } } } // Grab entity + position. auto Entity = getParentEntity(); auto LocalPosition = Entity->getLocalPosition(); // Move if we need to move towards our target position. if( ( TargetPosition_ - LocalPosition ).magnitudeSquared() > ( TargetDistance_ * TargetDistance_ ) ) { if( MoveTimer_ <= 0.0f ) { Velocity_ += ( TargetPosition_ - LocalPosition ).normal() * MaxVelocity_; } } else { BcF32 SlowDownTick = BcClamp( Tick * 50.0f, 0.0f, 1.0f ); Velocity_ -= ( Velocity_ * SlowDownTick ); } // TODO LATER: Do rotation. if( Velocity_.magnitudeSquared() > 0.1f ) { auto Angle = std::atan2( Velocity_.z(), Velocity_.x() ) + BcPIDIV2; MaMat4d RotMat; RotMat.rotation( MaVec3d( 0.0f, Angle, 0.0f ) ); Base_->setLocalMatrix( RotMat ); } // TODO LATER: Do rotation. auto Robots = getRobots( 1 - Team_ ); if( Robots.size() > 0 ) { auto Robot = Robots[ 0 ]; auto RobotPosition = Robot->getParentEntity()->getLocalPosition(); auto VectorTo = RobotPosition - LocalPosition; // Push out of away. if( VectorTo.magnitude() < 3.0f ) { BcF32 Factor = ( 3.0f - VectorTo.magnitude() ) / 3.0f; BcF32 InvFactor = 1.0f - Factor; Velocity_ = ( -( VectorTo.normal() * MaxVelocity_ ) * Factor * 3.0f ) + ( Velocity_ * InvFactor ); } // Face turret. auto Angle = std::atan2( VectorTo.z(), VectorTo.x() ) + BcPIDIV2; MaMat4d RotMat; RotMat.rotation( MaVec3d( 0.0f, Angle, 0.0f ) ); Turret_->setLocalMatrix( RotMat ); } LocalPosition += Velocity_ * Tick; // Slow down velocity. BcF32 SlowDownTick = BcClamp( Tick * 10.0f, 0.0f, 1.0f ); Velocity_ -= ( Velocity_ * SlowDownTick ); if( Velocity_.magnitude() > MaxVelocity_ ) { Velocity_ = Velocity_.normal() * MaxVelocity_; } // Set local position. Entity->setLocalPosition( LocalPosition ); // Handle health + energy. Health_ = BcClamp( Health_, 0.0f, 100.0f ); Energy_ = BcClamp( Energy_ + ( EnergyChargeRate_ * Tick ), 0.0f, 100.0f ); // Weapon timers. WeaponATimer_ = BcMax( WeaponATimer_ - Tick, -1.0f ); WeaponBTimer_ = BcMax( WeaponBTimer_ - Tick, -1.0f ); MoveTimer_ = BcMax( MoveTimer_ - Tick, -1.0f ); // Health/energy bars. OsClient* Client = OsCore::pImpl()->getClient( 0 ); BcF32 Width = BcF32( Client->getWidth() ) * 0.5f; BcF32 Height = BcF32( Client->getHeight() ) * 0.5f; MaMat4d Projection; Projection.orthoProjection( -Width, Width, Height, -Height, -1.0f, 1.0f ); Canvas_->pushMatrix( Projection ); Canvas_->setMaterialComponent( Material_ ); auto ScreenPos = View_->getScreenPosition( getParentEntity()->getWorldPosition() ); ScreenPos -= MaVec2d( 0.0f, Height / 8.0f ); auto TLPos = ScreenPos - MaVec2d( Width / 16.0f, Height / 64.0f ); auto BRPos = ScreenPos + MaVec2d( Width / 16.0f, Height / 64.0f ); // Draw background. Canvas_->drawBox( TLPos, BRPos, RsColour::BLACK, 0 ); // Draw inner bars. TLPos += MaVec2d( 1.0f, 1.0f ); BRPos -= MaVec2d( 1.0f, 1.0f ); auto HealthTL = MaVec2d( TLPos.x(), TLPos.y() ); auto HealthBR = MaVec2d( TLPos.x() + ( BRPos.x() - TLPos.x() ) * ( Health_ / 100.0f ), ( TLPos.y() + BRPos.y() ) * 0.5f ); auto EnergyTL = MaVec2d( TLPos.x(), ( TLPos.y() + BRPos.y() ) * 0.5f ); auto EnergyBR = MaVec2d( TLPos.x() + ( BRPos.x() - TLPos.x() ) * ( Energy_ / 100.0f ), BRPos.y() ); Canvas_->drawBox( HealthTL, HealthBR, RsColour::GREEN, 0 ); Canvas_->drawBox( EnergyTL, EnergyBR, RsColour::BLUE, 0 ); Canvas_->popMatrix( ); ScnDebugRenderComponent::pImpl()->drawLine( LocalPosition, TargetPosition_, RsColour::WHITE, 0 ); Super::update( Tick ); }
* Condition Near: Are we near an enemy? * @param Distance to check against. ( < Distance ) * @return If we are this near to any enemy. */ { "cond_near_enemy", []( GaRobotComponent* ThisRobot, BcU32 Distance )->BcU32 { auto Robots = ThisRobot->getRobots( 1 - ThisRobot->Team_ ); auto LocalPosition = ThisRobot->getParentEntity()->getLocalPosition(); BcBool RetVal = BcFalse; for( auto Robot : Robots ) { auto RobotPosition = Robot->getParentEntity()->getLocalPosition(); if( ( RobotPosition - LocalPosition ).magnitudeSquared() < BcF32( Distance * Distance ) ) { RetVal = BcTrue; } } return RetVal; } }, /** * Condition Far: Are we far from an enemy? * @param Distance to check against. ( > Distance ) * @return If we are farther away from all enenmies than specified distance. */ {
////////////////////////////////////////////////////////////////////////// // handleMouseEvent void OsClientHTML5::handleMouseEvent( const SDL_Event& SDLEvent ) { OsEventInputMouse Event; Event.DeviceID_ = 0; switch( SDLEvent.type ) { case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { Event.MouseX_ = SDLEvent.button.x; Event.MouseY_ = SDLEvent.button.y; Event.MouseDX_ = (BcF32)(Event.MouseX_ - PrevMouseX_); Event.MouseDY_ = (BcF32)(Event.MouseY_ - PrevMouseY_); Event.NormalisedX_ = ( BcF32( Event.MouseX_ ) - BcF32( getWidth() ) * 0.5f ) / BcF32( getWidth() * 0.5f ); Event.NormalisedY_ = ( BcF32( Event.MouseY_ ) - BcF32( getHeight() ) * 0.5f ) / BcF32( getHeight() * 0.5f ); switch( SDLEvent.button.button ) { case SDL_BUTTON_LEFT: Event.ButtonCode_ = 0; break; case SDL_BUTTON_RIGHT: Event.ButtonCode_ = 1; break; case SDL_BUTTON_MIDDLE: Event.ButtonCode_ = 2; break; case SDL_BUTTON_X1: Event.ButtonCode_ = 3; break; case SDL_BUTTON_X2: Event.ButtonCode_ = 4; break; } PrevMouseX_ = Event.MouseX_; PrevMouseY_ = Event.MouseY_; if( SDLEvent.type == SDL_MOUSEBUTTONDOWN ) { OsCore::pImpl()->publish( osEVT_INPUT_MOUSEDOWN, Event ); // TODO: REMOVE OLD! EvtPublisher::publish( osEVT_INPUT_MOUSEDOWN, Event ); } else if( SDLEvent.type == SDL_MOUSEBUTTONUP ) { OsCore::pImpl()->publish( osEVT_INPUT_MOUSEUP, Event ); // TODO: REMOVE OLD! EvtPublisher::publish( osEVT_INPUT_MOUSEUP, Event ); } } break; case SDL_MOUSEMOTION: { Event.MouseX_ = SDLEvent.motion.x; Event.MouseY_ = SDLEvent.motion.y; Event.MouseDX_ = (BcF32)(Event.MouseX_ - PrevMouseX_); Event.MouseDY_ = (BcF32)(Event.MouseY_ - PrevMouseY_); Event.NormalisedX_ = ( BcF32( Event.MouseX_ ) - BcF32( getWidth() ) * 0.5f ) / BcF32( getWidth() * 0.5f ); Event.NormalisedY_ = ( BcF32( Event.MouseY_ ) - BcF32( getHeight() ) * 0.5f ) / BcF32( getHeight() * 0.5f ); Event.ButtonCode_ = 0; PrevMouseX_ = Event.MouseX_; PrevMouseY_ = Event.MouseY_; OsCore::pImpl()->publish( osEVT_INPUT_MOUSEMOVE, Event ); // TODO: REMOVE OLD! EvtPublisher::publish( osEVT_INPUT_MOUSEMOVE, Event ); } break; } }
////////////////////////////////////////////////////////////////////////// // wndProcInternal LRESULT OsClientWindows::wndProcInternal( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { // Handle messages switch (uMsg) { case WM_SYSCOMMAND: { switch ( wParam ) { // Disable the screensaver and monitor power off events. case SC_SCREENSAVE: case SC_MONITORPOWER: return 0; break; case SC_MINIMIZE: { // Get new window rect. ::GetWindowRect( hWnd, &WindowSize_ ); ::GetClientRect( hWnd_, &ClientSize_ ); // Send event. OsEventClient Event; Event.pClient_ = this; EvtPublisher::publish( osEVT_CLIENT_MINIMIZE, Event ); } break; case SC_MAXIMIZE: { // Get new window rect. ::GetWindowRect( hWnd, &WindowSize_ ); ::GetClientRect( hWnd_, &ClientSize_ ); // Send event. OsEventClient Event; Event.pClient_ = this; EvtPublisher::publish( osEVT_CLIENT_MAXIMIZE, Event ); } break; } } break; case WM_SIZE: { // Get new window rect. ::GetWindowRect( hWnd, &WindowSize_ ); ::GetClientRect( hWnd_, &ClientSize_ ); // Send resize event. OsEventClientResize Event; Event.pClient_ = this; Event.Width_ = getWidth(); Event.Height_ = getHeight(); EvtPublisher::publish( osEVT_CLIENT_RESIZE, Event ); } break; case WM_KEYDOWN: { OsEventInputKeyboard Event; Event.DeviceID_ = 0; mapKeyEvent( Event, wParam ); OsCore::pImpl()->publish( osEVT_INPUT_KEYDOWN, Event ); // TODO: REMOVE OLD! EvtPublisher::publish( osEVT_INPUT_KEYDOWN, Event ); return 0; } break; case WM_KEYUP: { OsEventInputKeyboard Event; Event.DeviceID_ = 0; mapKeyEvent( Event, wParam ); OsCore::pImpl()->publish( osEVT_INPUT_KEYUP, Event ); // TODO: REMOVE OLD! EvtPublisher::publish( osEVT_INPUT_KEYUP, Event ); return 0; } break; case WM_MOUSEMOVE: { /* if( MouseLocked_ == BcFalse ) { OsEventInputMouse Event; Event.DeviceID_ = 0; Event.MouseX_ = lParam & 0xffff; Event.MouseY_ = lParam >> 16 & 0xffff; Event.MouseDX_ = Event.MouseX_ - PrevMouseX_; Event.MouseDY_ = Event.MouseY_ - PrevMouseY_; Event.NormalisedX_ = BcF32( Event.MouseX_ - getWidth() / 2 ) / BcF32( getWidth() ); Event.NormalisedY_ = BcF32( Event.MouseY_ - getHeight() / 2 ) / BcF32( getHeight() ); PrevMouseX_ = Event.MouseX_; PrevMouseY_ = Event.MouseY_; Event.ButtonCode_ = 0; OsCore::pImpl()->publish( osEVT_INPUT_MOUSEMOVE, Event ); // TODO: REMOVE OLD! EvtPublisher::publish( osEVT_INPUT_MOUSEMOVE, Event ); } */ return 0; } break; case WM_LBUTTONDOWN: { SetCapture( hWnd ); OsEventInputMouse Event; Event.DeviceID_ = 0; Event.MouseX_ = lParam & 0xffff; Event.MouseY_ = lParam >> 16 & 0xffff; Event.MouseDX_ = (BcF32)(Event.MouseX_ - PrevMouseX_); Event.MouseDY_ = (BcF32)(Event.MouseY_ - PrevMouseY_); Event.NormalisedX_ = BcF32( Event.MouseX_ - getWidth() / 2 ) / BcF32( getWidth() ); Event.NormalisedY_ = BcF32( Event.MouseY_ - getHeight() / 2 ) / BcF32( getHeight() ); //if( MouseLocked_ == BcFalse ) { PrevMouseX_ = Event.MouseX_; PrevMouseY_ = Event.MouseY_; } Event.ButtonCode_ = 0; OsCore::pImpl()->publish( osEVT_INPUT_MOUSEDOWN, Event ); // TODO: REMOVE OLD! EvtPublisher::publish( osEVT_INPUT_MOUSEDOWN, Event ); return 0; } break; case WM_LBUTTONUP: { ReleaseCapture(); OsEventInputMouse Event; Event.DeviceID_ = 0; Event.MouseX_ = lParam & 0xffff; Event.MouseY_ = lParam >> 16 & 0xffff; Event.MouseDX_ = (BcF32)(Event.MouseX_ - PrevMouseX_); Event.MouseDY_ = (BcF32)(Event.MouseY_ - PrevMouseY_); Event.NormalisedX_ = BcF32( Event.MouseX_ - getWidth() / 2 ) / BcF32( getWidth() ); Event.NormalisedY_ = BcF32( Event.MouseY_ - getHeight() / 2 ) / BcF32( getHeight() ); //if( MouseLocked_ == BcFalse ) { PrevMouseX_ = Event.MouseX_; PrevMouseY_ = Event.MouseY_; } Event.ButtonCode_ = 0; OsCore::pImpl()->publish( osEVT_INPUT_MOUSEUP, Event ); // TODO: REMOVE OLD! EvtPublisher::publish( osEVT_INPUT_MOUSEUP, Event ); return 0; } break; case WM_RBUTTONDOWN: { SetCapture( hWnd ); OsEventInputMouse Event; Event.DeviceID_ = 0; Event.MouseX_ = lParam & 0xffff; Event.MouseY_ = lParam >> 16 & 0xffff; Event.MouseDX_ = (BcF32)(Event.MouseX_ - PrevMouseX_); Event.MouseDY_ = (BcF32)(Event.MouseY_ - PrevMouseY_); Event.NormalisedX_ = BcF32( Event.MouseX_ - getWidth() / 2 ) / BcF32( getWidth() ); Event.NormalisedY_ = BcF32( Event.MouseY_ - getHeight() / 2 ) / BcF32( getHeight() ); //if( MouseLocked_ == BcFalse ) { PrevMouseX_ = Event.MouseX_; PrevMouseY_ = Event.MouseY_; } Event.ButtonCode_ = 1; OsCore::pImpl()->publish( osEVT_INPUT_MOUSEDOWN, Event ); // TODO: REMOVE OLD! EvtPublisher::publish( osEVT_INPUT_MOUSEDOWN, Event ); return 0; } break; case WM_RBUTTONUP: { ReleaseCapture(); OsEventInputMouse Event; Event.DeviceID_ = 0; Event.MouseX_ = lParam & 0xffff; Event.MouseY_ = lParam >> 16 & 0xffff; Event.MouseDX_ = (BcF32)(Event.MouseX_ - PrevMouseX_); Event.MouseDY_ = (BcF32)(Event.MouseY_ - PrevMouseY_); Event.NormalisedX_ = BcF32( Event.MouseX_ - getWidth() / 2 ) / BcF32( getWidth() ); Event.NormalisedY_ = BcF32( Event.MouseY_ - getHeight() / 2 ) / BcF32( getHeight() ); //if( MouseLocked_ == BcFalse ) { PrevMouseX_ = Event.MouseX_; PrevMouseY_ = Event.MouseY_; } Event.ButtonCode_ = 1; OsCore::pImpl()->publish( osEVT_INPUT_MOUSEUP, Event ); // TODO: REMOVE OLD! EvtPublisher::publish( osEVT_INPUT_MOUSEUP, Event ); return 0; } break; case WM_MBUTTONDOWN: { SetCapture( hWnd ); OsEventInputMouse Event; Event.DeviceID_ = 0; Event.MouseX_ = lParam & 0xffff; Event.MouseY_ = lParam >> 16 & 0xffff; Event.MouseDX_ = (BcF32)(Event.MouseX_ - PrevMouseX_); Event.MouseDY_ = (BcF32)(Event.MouseY_ - PrevMouseY_); Event.NormalisedX_ = BcF32( Event.MouseX_ - getWidth() / 2 ) / BcF32( getWidth() ); Event.NormalisedY_ = BcF32( Event.MouseY_ - getHeight() / 2 ) / BcF32( getHeight() ); //if( MouseLocked_ == BcFalse ) { PrevMouseX_ = Event.MouseX_; PrevMouseY_ = Event.MouseY_; } Event.ButtonCode_ = 2; OsCore::pImpl()->publish( osEVT_INPUT_MOUSEDOWN, Event ); // TODO: REMOVE OLD! EvtPublisher::publish( osEVT_INPUT_MOUSEDOWN, Event ); return 0; } break; case WM_MBUTTONUP: { ReleaseCapture(); OsEventInputMouse Event; Event.DeviceID_ = 0; Event.MouseX_ = lParam & 0xffff; Event.MouseY_ = lParam >> 16 & 0xffff; Event.MouseDX_ = (BcF32)(Event.MouseX_ - PrevMouseX_); Event.MouseDY_ = (BcF32)(Event.MouseY_ - PrevMouseY_); Event.NormalisedX_ = BcF32( Event.MouseX_ - getWidth() / 2 ) / BcF32( getWidth() ); Event.NormalisedY_ = BcF32( Event.MouseY_ - getHeight() / 2 ) / BcF32( getHeight() ); //if( MouseLocked_ == BcFalse ) { PrevMouseX_ = Event.MouseX_; PrevMouseY_ = Event.MouseY_; } Event.ButtonCode_ = 2; OsCore::pImpl()->publish( osEVT_INPUT_MOUSEUP, Event ); // TODO: REMOVE OLD! EvtPublisher::publish( osEVT_INPUT_MOUSEUP, Event ); return 0; } break; case WM_MOUSEWHEEL: { OsEventInputMouse Event; Event.DeviceID_ = 0; Event.MouseX_ = lParam & 0xffff; Event.MouseY_ = lParam >> 16 & 0xffff; Event.MouseDX_ = (BcF32)(Event.MouseX_ - PrevMouseX_); Event.MouseDY_ = (BcF32)(Event.MouseY_ - PrevMouseY_); Event.NormalisedX_ = BcF32( Event.MouseX_ - getWidth() / 2 ) / BcF32( getWidth() ); Event.NormalisedY_ = BcF32( Event.MouseY_ - getHeight() / 2 ) / BcF32( getHeight() ); //if( MouseLocked_ == BcFalse ) { PrevMouseX_ = Event.MouseX_; PrevMouseY_ = Event.MouseY_; } BcS16 WheelDirection = wParam >> 16 & 0xffff; Event.ButtonCode_ = WheelDirection > 0 ? 3 : 4; OsCore::pImpl()->publish( osEVT_INPUT_MOUSEWHEEL, Event ); // TODO: REMOVE OLD! EvtPublisher::publish( osEVT_INPUT_MOUSEWHEEL, Event ); return 0; } break; case WM_DESTROY: case WM_CLOSE: { // Send the close event. OsEventClient Event; Event.pClient_ = this; EvtPublisher::publish( osEVT_CLIENT_CLOSE, Event ); // Post windows quit message. ::PostQuitMessage( 0 ); return 0; } break; } return ::DefWindowProc( hWnd, uMsg, wParam, lParam ); }
////////////////////////////////////////////////////////////////////////// // update void OsClientWindows::update() { // Update mouse if we're in focus. if( ::GetActiveWindow() == hWnd_ ) { POINT MousePosition; POINT WindowPosition; RECT Rect; // Get window rect in screen space. ::GetWindowRect( hWnd_, &Rect ); // Screen space cood of the client area. WindowPosition.x = 0; WindowPosition.y = 0; ::ClientToScreen( hWnd_, &WindowPosition ); // Get the cursor position ::GetCursorPos( &MousePosition ); const BcS32 WX = ( Rect.right - Rect.left ); const BcS32 WY = ( Rect.bottom - Rect.top ); MouseDelta_.x( BcF32( MousePosition.x - ( Rect.left + ( WX / 2 ) ) ) ); MouseDelta_.y( BcF32( MousePosition.y - ( Rect.top + ( WY / 2 ) ) ) ); MousePos_ += MouseDelta_; MousePos_.x( BcClamp( MousePos_.x(), 0.0f, BcF32( WX ) ) ); MousePos_.y( BcClamp( MousePos_.y(), 0.0f, BcF32( WY ) ) ); // Smooth out delta const MaVec2d TempOld = MouseDelta_; MouseDelta_ = ( MousePrevDelta_ + MouseDelta_ ) * 0.5f; MousePrevDelta_ = TempOld; // Lock to centre of screen if we're in focus. if( MouseLocked_ ) { ::SetCursorPos( Rect.left + ( WX / 2 ), Rect.top + ( WY / 2 ) ); } // Send event if moved. if( MouseDelta_.magnitude() > 0.5f ) { OsEventInputMouse Event; Event.DeviceID_ = 0; Event.MouseX_ = (BcS16)MousePosition.x - (BcS16)WindowPosition.x; Event.MouseY_ = (BcS16)MousePosition.y - (BcS16)WindowPosition.y; Event.MouseDX_ = MouseDelta_.x(); Event.MouseDY_ = MouseDelta_.y(); Event.NormalisedX_ = BcF32( (BcS32)Event.MouseX_ - ( (BcS32)getWidth() / 2 ) ) / BcF32( (BcS32)getWidth() / 2 ); Event.NormalisedY_ = BcF32( (BcS32)Event.MouseY_ - ( (BcS32)getHeight() / 2 ) ) / BcF32( (BcS32)getHeight() / 2 ); // Legacy... PrevMouseX_ = Event.MouseX_; PrevMouseY_ = Event.MouseY_; Event.ButtonCode_ = 0; OsCore::pImpl()->publish( osEVT_INPUT_MOUSEMOVE, Event ); // TODO: REMOVE OLD! EvtPublisher::publish( osEVT_INPUT_MOUSEMOVE, Event ); } } }
////////////////////////////////////////////////////////////////////////// // randReal BcF32 BcRandom::randReal() { return BcF32( randRange( (BcS32)-4096.0f, (BcS32)4096.0f ) ) / 4096.0f; }