-
Midpoint Scrolling
How do you you use the midpoint formula to scroll in between (>amount here<) objects? I know that you use the midpoint formula to set the position of a "scroller" that scrolls the screen. What I don't know is how to loop through the actives (more than one type) and get the midpoint.
-
Re: Midpoint Scrolling
To get an average you get the sum of the X's and Y's and divide them by the amount of objects.
-
Re: Midpoint Scrolling
That's a straight average, though, and would pull the screen further over in one direction if more objects were on one side. To get the midpoint, you'd need to find the minimum X/Y out of the group, the maximum X/Y, and set the position to halfway between them. That's just a general outline, because I don't really know the best way to actually do that...
-
Re: Midpoint Scrolling
What I don't know is how to get the individual X's and Y's of each object.
-
Re: Midpoint Scrolling
To get the midpoint
1. Give all the objects you want to test the same qualifier (Group.Neutral)
2. Create several counters: MinX, MinY, MaxX, MaxY, MidX, MidY
3. Do the following code:
[events]
*Start of Frame
-(Group.Neutral) : Spread value 0 in Alterable Value A
*Always
-(Counter MinX) : Set Counter to X( "(Group.Neutral)" )
-(Counter MaxX) : Set Counter to X( "(Group.Neutral)" )
-(Counter MinY) : Set Counter to Y( "(Group.Neutral)" )
-(Counter MaxY) : Set Counter to Y( "(Group.Neutral)" )
-Start loop "midpoint" NObjects( "(Group.Neutral)" ) times
-(Counter MidX) : Set Counter to(value( "(Counter MinX)" )+value( "(Counter MaxX)" ))/2
-(Counter MidY) : Set Counter to(value( "(Counter MinY)" )+value( "(Counter MaxY)" ))/2
*On loop "midpoint"
+Alterable Value A of(Group.Neutral) = LoopIndex("midpoint")
+X position of(Group.Neutral) < value( "(Counter MinX)" )
-(Counter MinX) : Set Counter to X( "(Group.Neutral)" )
*On loop "midpoint"
+Alterable Value A of(Group.Neutral) = LoopIndex("midpoint")
+X position of(Group.Neutral) > value( "(Counter MaxX)" )
-(Counter MaxX) : Set Counter to X( "(Group.Neutral)" )
*On loop "midpoint"
+Alterable Value A of(Group.Neutral) = LoopIndex("midpoint")
+Y position of(Group.Neutral) > value( "(Counter MaxY)" )
-(Counter MaxY) : Set Counter to Y( "(Group.Neutral)" )
*On loop "midpoint"
+Alterable Value A of(Group.Neutral) = LoopIndex("midpoint")
+Y position of(Group.Neutral) < value( "(Counter MinY)" )
-(Counter MinY) : Set Counter to Y( "(Group.Neutral)" )
[/events]
-
Re: Midpoint Scrolling
I'm not quite sure what you mean. If you mean an object (or vertex) that hangs between two objects then this example might help:
http://raytrace.sitesled.com/Examples/example15.mfa
The formula is just a simple one dimentional Ecludeien distance formula with an addition to find the percentage that the marker should be along the line of interpolation.
For your question:
ScrollX = X("1")+(X("1")-X("2"))/2
ScrollY = Y("1")+(Y("1")-Y("2"))/2
-
Re: Midpoint Scrolling
If you drop me an email at pkb@iol.ie I'll send you a copy of my Camera Control tutorial which shows how to create mid point scrolling with up to four objects on screen. It is 480Kb in size.