Flutter Engine
The Flutter Engine
Public Member Functions | Protected Attributes | List of all members
BouncingParticle Class Reference
Inheritance diagram for BouncingParticle:
MMObject BouncingTaggedImage

Public Member Functions

 BouncingParticle (SkRandom *random, SkSize stageSize, SkSize particleSize, float maxVelocity)
 
void animate (double deltaNanos) override
 
- Public Member Functions inherited from MMObject
virtual ~MMObject ()=default
 
virtual void draw (SkCanvas *canvas)=0
 
virtual void animate (double)=0
 

Protected Attributes

SkSize fStageSize
 
SkSize fSize
 
SkPoint fPosition
 
float fAngle
 
float fVelocity
 
Rotater fRotater
 

Detailed Description

Definition at line 664 of file MotionMarkSlide.cpp.

Constructor & Destructor Documentation

◆ BouncingParticle()

BouncingParticle::BouncingParticle ( SkRandom random,
SkSize  stageSize,
SkSize  particleSize,
float  maxVelocity 
)
inline

Definition at line 666 of file MotionMarkSlide.cpp.

667 : fStageSize(stageSize)
668 , fSize(particleSize)
669 , fPosition(random_position(random,
670 {stageSize.fWidth - particleSize.fWidth,
671 stageSize.fHeight - particleSize.fHeight}))
672 , fAngle(random_angle(random))
673 , fVelocity(random_velocity(random, maxVelocity))
674 , fRotater(random_rotater(random)) {
675 }
SkPoint random_position(SkRandom *random, SkSize maxPosition)
Rotater random_rotater(SkRandom *random)
float random_angle(SkRandom *random)
float random_velocity(SkRandom *random, float maxVelocity)
SkScalar fHeight
Definition: SkSize.h:54
SkScalar fWidth
Definition: SkSize.h:53

Member Function Documentation

◆ animate()

void BouncingParticle::animate ( double  deltaNanos)
inlineoverridevirtual

Implements MMObject.

Reimplemented in BouncingTaggedImage.

Definition at line 677 of file MotionMarkSlide.cpp.

677 {
678 // TODO: consolidate and pass in millis to the Stages
679 constexpr double kMillisPerNano = 0.0000001;
680 fPosition += point_on_circle(fAngle, fVelocity * (deltaNanos * kMillisPerNano));
681 fRotater.next(deltaNanos * kMillisPerNano);
682
683 // If particle is going to move off right side
684 if (fPosition.fX + fSize.width() > fStageSize.width()) {
685 // If direction is East-South, go West-South.
686 if (fAngle >= 0 && fAngle < SK_FloatPI / 2)
688 // If angle is East-North, go West-North.
689 else if (fAngle > SK_FloatPI / 2 * 3)
690 fAngle = fAngle - (fAngle - SK_FloatPI / 2 * 3) * 2;
691 // Make sure the particle does not go outside the stage boundaries.
693 }
694
695 // If particle is going to move off left side
696 if (fPosition.fX < 0) {
697 // If angle is West-South, go East-South.
698 if (fAngle > SK_FloatPI / 2 && fAngle < SK_FloatPI)
700 // If angle is West-North, go East-North.
701 else if (fAngle > SK_FloatPI && fAngle < SK_FloatPI / 2 * 3)
702 fAngle = fAngle + (SK_FloatPI / 2 * 3 - fAngle) * 2;
703 // Make sure the particle does not go outside the stage boundaries.
704 fPosition.fX = 0;
705 }
706
707 // If particle is going to move off bottom side
709 // If direction is South, go North.
710 if (fAngle > 0 && fAngle < SK_FloatPI)
711 fAngle = SK_FloatPI * 2 - fAngle;
712 // Make sure the particle does not go outside the stage boundaries.
714 }
715
716 // If particle is going to move off top side
717 if (fPosition.fY < 0) {
718 // If direction is North, go South.
719 if (fAngle > SK_FloatPI && fAngle < SK_FloatPI * 2)
720 fAngle = fAngle - (fAngle - SK_FloatPI) * 2;
721 // Make sure the particle does not go outside the stage boundaries.
722 fPosition.fY = 0;
723 }
724 }
SkPoint point_on_circle(float angle, float radius)
constexpr float SK_FloatPI
void next(float timeDelta)
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165
SkScalar width() const
Definition: SkSize.h:76
SkScalar height() const
Definition: SkSize.h:77

Member Data Documentation

◆ fAngle

float BouncingParticle::fAngle
protected

Definition at line 730 of file MotionMarkSlide.cpp.

◆ fPosition

SkPoint BouncingParticle::fPosition
protected

Definition at line 729 of file MotionMarkSlide.cpp.

◆ fRotater

Rotater BouncingParticle::fRotater
protected

Definition at line 732 of file MotionMarkSlide.cpp.

◆ fSize

SkSize BouncingParticle::fSize
protected

Definition at line 728 of file MotionMarkSlide.cpp.

◆ fStageSize

SkSize BouncingParticle::fStageSize
protected

Definition at line 727 of file MotionMarkSlide.cpp.

◆ fVelocity

float BouncingParticle::fVelocity
protected

Definition at line 731 of file MotionMarkSlide.cpp.


The documentation for this class was generated from the following file: