This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

tombud999
tombud999 presents ...

2009/7/4

CircularMover

Click on empty space to add more flies.

This is a reusable actor class - CircularMover, that I will use in my DominoFall scenario,
which might be useful for your scenario.

This CircularMover class is adapted from SmoothMover class ver2.0
from Michael Kolling's Marbles scenario.
This CircularMover class is using Poul Henriksen & Michael Kolling's Vector class ver2.0

How to use:
(see the source code for more detail)
Create an actor as a subclass of (extends) CircularMover.
Set the radius of the circular path - setCR(double CIR_RAD).
Calculate the center of point of the circular path - calcCP().
Set the circular movement direction (clockwise/counterclockwise) - setCDir(boolean cWise).
Set the actor initial rotation - setRotation(int iRot).
Call moveCir() method from the actor act() method.
Set acceleration/deceleration - accelerate(double DECEL).
Apply a linear force - addForce(Vector vForce).
Start moving the actor - setMoving(boolean true).

7424 views / 16 in the last 7 days

1 vote | 0 in the last 7 days

Tags: simulation demo with-source vector actor circular reusable class circularmover

This scenario is a member of: Reusable actors & support classes


open in greenfoot
Your browser does not support the canvas tag.
A new version of this scenario was uploaded on Sun Jul 05 12:11:24 UTC 2009
tombud999tombud999

2009/7/5

I forgot the counter-clockwise circular movement, method setCDir(boolean cWise) added.
Hi. Great support class. I'm trying to implement it to make one object ("fly") move in a circular path at a fixed distance from the center of the World based on "left" or "right" arrow input. My modification works fine unless the "fly" crosses his initial set location to the "right" from the "left" of the initial location. When that happens the "fly" jumps all the way back to the initial location. Well, it's way easier to see than to explain. I was wondering if I could email the scenario to you and let you have a look at it. If you're on yahoo messenger, we could chat while you look at it (or Ventrillo). My email is freeman6332@yahoo.com. Thanks.
also, I've been wondering how to modify CircularMover so that it could be a superclass called ShapeMover, where a shape can be anything, i.e. Ellipse (a Circle is an Ellipse), polygon (the more sides to the polygon, the closer it-is-to-a circle), or even a spiral (say, if your circle radius constantly got smaller based on a gravitational constant -- call it PULL -- toward the center of rotation [ i.e. if PULL=0, then no spiral effect at all] ) I know, WTF???? Right? Lol. Well, if you're intereted in finding out what the hell I talking about, you have my email: freeman6332@yahoo.com
tombud999tombud999

2009/8/10

Hi, thanks, freeman. Well, I still don't really understand what is the problem, you're right, it is easier to see first. You could just export/publish your scenario in this gallery (with the source), so I can instantly see it running. Don't worry if it is not complete or not working properly, this is a playground to learn java, and by publishing it you got more people to discuss with. If you need it, my email is tombud999@gmail.com.
tombud999tombud999

2009/8/10

About other path shape, I don't think it can be a universal path shape chooser like you mention. I'll explain more about this CircularMover class. Actually I create this CircularMover class for my DominoFall scenario, to move the LightBulb to be exact (see the DominoFall scenario, click Run then click Clear button and create LightBulbs by holding L key and clicking on empty space). A lay-down lightbulb is basically a lay-down cone that can roll in a circular path. The center point of the circular path is always at a specific distance from the center axis of the cone [method setCR(double CIR_RAD)], so the location of the center point is depends on the rotation angle of the cone when initially put on the ground (compare the two flies above, the center point is always at one grid distance to the right hand (legs, actually :D) of the fly. Back to the LightBulb, to start roll it, I just apply a linear force - addForce(Vector vForce), the vForce vector can be from a toppled domino or a moving ball striking the LightBulb (btw, this interaction is not finish yet in my DominoFall scenario, I still working on the more accurate collision detection - see, my scenario is also not complete!). Whew! I wish I could draw something in this comment area, explaining this kind of things is though with words only :D

Want to leave a comment? You must first log in.

Who likes this?

SpacecityGamer