Examples:
- Velocity
components:
- A-Button: to shoot the ball
- X-Button: to pause everything
- Left Thumb-Stick-Y: Speed of ball
- Right Thumb-Stick: direction for the ball
- Right Trigger: rotate the blocker
- Shoots the ball towards the blocker and shows velocity decomposition at
collision
- Form Vectors at collision:
- Red: The velocity
- UDir -LightBlue : Normal
- VDir - LightGreen: Tangent
- White: Reflected direction
- black dot: Point on Tangent
-
Notice: All the interesting code is in MySoccer::Update() function.
-
This solution works for circle/rectangle intersection.
-
Difference between FrontDirection and VelocityDirection:
- FrontDirection: the front of the primitive.
- VelocityDireciton: the direction the primitive velocity.
-
Gradual Turning:
Almost identical to Example-4 from week1, except, at the last stage of the
road, if user change the road-end-point, the car moves/rotates gradually
towards the endpoint rather than rotate to face the end point
immediately.
- Left Thumb-Stick-Y: Change current road segment length
- Right Thumb-Stick: Change current road segment direction
- A-Button: Add in new road segment
- Car rotates and follows current segment of road it is on
- MyCar class: UpdateCarDirAndSpeed()!!
- Plotting and Following a Sine Function:
- Left-Thumb-Stick Up/Down: to change number per periods that
will be fitted in the entire WorldDimension.X,
- Left-Thumb-Stick-Left/Right to change the Amplitude
- Only point interesting is to recognized we need to fit (2*PI*mPeriod)
into WorldDimension.X:
- Use mFrequeicyScale to help in converting x coordinate position into
angular value.
- Note: x-displacement is constant, speed is NOT constant.
- Now to make speed a constant? (Type the A-Button)
- Notice: use of PrimitiveSet for showing/hiding entire set (plotted out
sine curves)
- Boxed Sine Function:
- Left-Thumb-Stick Up/Down: to change number per periods that
will be fitted in the box-Width
- Left-Thumb-Stick-Left/Right to change the Amplitude
- Right-Thumb-Stick: to move the location of the box to contain the
Sine plot
- Left-Trigger/Left-Button: to increase/decrease the width of box
- Right-Trigger/Right-Button: to increase/decrease the height box
- Class to check out: PlotBox:
- Is a Rectangle: must set Center/Width/Height to be seen!
- ComputePosition: uses the center position and width to compute LeftCenterPos.
- Update(): changes box position (Center), and Width/Height. Triggers the
ComputePosition to recompute leftCenterPos.
- GetBoxPosition(): with this class, function computation
can assume beginning from x=0, and evaluate the Y-value. When (x,y)
values are computed, we can now call "GetBoxPosition()" to compute
the relative position with respect to the leftCenterPos.
- Interestingly: now, we do not need to factor in sine offsets wrt to the
plotting area (taken care of by the PlotBox::GetBoxPosition()) function. So,
- useX =
currentX - mPlotBox.PlotOriginX is not needed anymore!
- GetYValue(x): do not need to worry about: the mPolotBox Y-offset
Constant Velocity: Notice the much more elaborate steps in computing
constant velocity, where we convert into boxPlot position only in the very
last steps. This clear separation of Function Position [mTheta,
GetYValue(mTheta)] from the plotBox position is important in general when
e.g., if we want to rotate the plotBox!
- The FunctionPath class:
- Identical to the above, except the new FunctionPlot class
- except: B-Button: hide the plot area and plot positions
- Class to check out: FunctionPlot:
- Abstract the area upon which to plot the function as: PlotBox
- Abstract x/y coverage of function to plot (mFunctionXCoverage
and mFunctionYCoverage).
- Notice: we can implement PlotFunction() even though we have no
idea what is the function!!
- GetYValue(x): is a virtual function,
subclass can implement any function!
- Check out the SineFunctionPath: implements a sine function.
- So, we have a identical behavior system as the above example!
- Boxed Parabola Function:
- Identical to the above, except the new ParabolaFunctionPath class
- ButtonX/Y: to change the control between the sine and the
parabola plots
- Class to check out: ParabolaFunctionPath:
- GetUseX(x):
- must translate x by PlotBox.Width/2 (to see the
negative side of the x values)
- Scale the x values to cover
the entire width of the PlotBox.
- Notice that in UI, when you change the xCoverage, the
plot does not change! (because we compensate the by the
above scale).
- This is done to show the curve stretching/squeezing with
the PlotBox scale.
- GetYValue(x):
- Must call GetUseX(x) to offset and properly scale the x
value
- Scale the y-value such that, yCoverage value touches the
upper corners of the plot area.
- This means, when yCoverage is larger than plotBox.height,
the traveling circle will go outside of bounds.
- General Boxed Function:
- Almost identical to above, except, now, we separate out the PlotBox x/y
directions into Front/Normal directions!
- DPad Up/Down: Rotates the plotting area
- Class to check out: FunctionPath:
- the update function now accepts a rotDelta (delta rotate)
parameter.
- causes the PlotBox to rotate.
- Class to check out: PlotBox
- New instance variable: NormalDir: this variable is always
90-degrees of FrontDirection
- With FrontDirection and NormalDir, we have the x (FrontDirection)
and y (NormalDir) directions.
- In GetBoxPosition(x, y): we compute the actual position in the
box by offsets to the x-direction vector (FrontDirectoin) and
y-direction vector (NormalDir).
- Many Function Plots:
- With proper abstraction, it is trivial to support large instances
- XButton: cycles through all the plots
- Try cycle through the plots and press-B button to see the PlotBox.
- Bunch of random plots, interesting? May be yes? no? looks interestingly
complex/chaotic, and yet we have absolute control!!
- Cool?