Rotational Circle in JavaFX - animation

I'm creating an application which consists a simulation for uniformly rotational circle with decreasing acceleration. But it does not have to be exactly like in Physics. And I'm using JavaFX. I'm using Animation and Timeline in JavaFX. However, as far as I know, they just create animation in a fixed duration. However, my application requires that the circle decreases its speed to zero and then stops.
Any idea or clue on how should I do that. I really appreaciate your help!
Edit: If I need to rotate the circle according to the initial mouse speed. How shoudl I do that?

Use a RotateTransition and specify a custom interpolator.

I don't use JavaFX, but there should be something like a 'rotate(degrees)' method somewhere. If so, just rotate it a little less every frame until it stops. Here are some psuedo-code:
float degrees = 60;
JavaFXThing thing;
//Every frame
while (true){
thing.rotate(degrees);
thing.draw();
degrees -= 0.05;
}
Hope it helped!

Related

P5.JS: Collisions?

I have an idea of getting a circle grow in size if anywhere in the circle's area there is this object called "food". Though I have no idea how to implement it on my code. I have tried but of course the whole concept of my idea was off in trying to pull this off.
this.touch = function(){
if (x > this.x && y > this.y){
this.radius += 0.5;
}
}
This is one of my functions in a constructor, the variable x and y is referencing the "food"'s position. The this.(variables) are referring to the object reacting to the food.
The code snippet on top does not work simply for the fact that I am asking the object to increase in size based on x and y positions, and that just doesn't work for my concept.
Can anyone give me some tips or send a link to something which could help.
Thanks in advance!
I'd start by googling something like collision detection for a ton of results.
You can also narrow your search by adding the type of shapes you're talking about. For example, if your food is shown as a point, you might google (point circle collision detection". If your food is shown as a circle, you might google "circle circle collision detection".
If you're dealing with circles, you basically want to check the distance from the center of the circle. If that distance is less than the radius of the circle, then you have a collision. The dist() function will come in handy here.
Shameless self-promotion: here is a tutorial on collision detection. It's written for Processing, but all of the concepts apply to P5.js as well.

ThreeJS translate scene position

I've been working at a game which is set in space meaning that the player can move through the solar system.
The issue comes when the player travels further away, and gets Float32 precision issues.
I've been searching for a few hours to find a fix for this, but nothing helped so far.
What I also tried was to rescale all the meshes to be tiny.. about 100 times smaller than their initial scale, but that behaves the same when reaching larger coordinates.
Another solution would be to translate the world position, not the player, which will do the job.. but I honestly have no clue how to achieve this without changing each mesh position.
I've also set the renderer to use { logarithmicDepthBuffer: true} but that still wont help me.. the player model starts jumping, flickering.
I spent alot of time by trying to find a solution to help me with this issue, so I appreciate any kind of advice.
To move your scene you can use:
scene.translateX(i);
scene.translateY(i);
scene.translateZ(i);
Where i is the increment from the existing position offset. This can give you the illusion of an first person movement.
This is a common solution to very large scenes.

How can I render my 2D background under the water with opengles

I am rendering my 2D background under the water with opengles. How can I distort my textures over time? I just know to achive this with sin(time) or cos(time). But I'm poor in glsl.I have no idea how to do it. Shoud I changed the x,y coordination over time? How can I avoid move the whole texture repeatedly?
Any help thanks.
You may distort the texture coordinates in hope of achieving this but you will need a few parameters.
For instance you can use a sin or cos function (not much of a difference between them) to distort horizontally by moving the X texture coordinate by a small amount. So you insert for instance an uniform (strength) which should be relative to the texture for instance .1 will distort for a maximum of 10%. Then the idea would be to set X=sin(Y)*strength. Since the Y is in range from 0 to 1 you will need to add another parameter such as density to get "more waves" which should be in range like 20 for instance to get a few waves (change this as you please to test for a nice effect). So then the equation becomes X=sin(Y*density)*strength. Still this will produce a static distorted image but what you want is to move over time so you need some vertical time factor delta which should be changed over time and range between .0 and 2*PI and then the equation is X=sin(Y*density + delta)*strength. On every frame you should increase the delta and if it is larger then 2*PI simply decrease it by 2*PI to get a smooth animation. The value you increase the delta by will control the speed of the effect.
So now you have 3 uniform parameters which you should try to play around to get the desired effect. I hope you find it.

How to properly flip 2D character with new Unity4.3 2D framework? (Rotation of gameobjects during animation)

i'm already checked official Unity 4.3 example project, and there they use
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
This works pretty well, but. But i'm encountered an trouble, not sure this trouble with this Flip or with something else.
I'm use Animator to animate my characters, i have Attack animation, which in addition to the sprite animation also move character's Hand, which can carry the Weapon. Problem is when i flip the character to opposite direction Hand will move wrong (not as planned), which is wrong. (video below will be more descriptive)
I discovered that this problem occure only if i modify the Hand's rotation in animation, so if i works only with .position this works well, but i need the rotation!
What is best way to get this work?
Here the youtube video: http://youtu.be/qpMK2gRgDz8
At video i show animation without rotation uses, hand moves correct. But next i show it with rotation, as you can see when character turned right this works well, but when left, its completely wrong.
What you want to do cannot be done with scaling cause scaling does not change the rotation of the object and so the forward vector remains the same. You must create double sided objects and just rorate them 180 degrees or you can ue a shader that draws a polygon even when its normal vector is against the camera.

libGDX: How to let the camera point to moving sprite?

I'm new to libGDX and android game dev. And I want to achieve this:
I have a Screen and within it, a ball sprite that is moving along the X axis. Now I want to center the viewport to the sprite when it moves. Just like in Angry birds, where the camera follows the bird flying across the sky.
How can I implement that within my game using OrthographicCamera?
This took me a while of Googling and testing, but I just found something and I think others may appreciate it.
To move the camera (and if you are using a spriteBatch), make sure to call setProjectionMatrix.
Ex:
camera.position.y += 5; // or whatever you want to change y by...
camera.position.x += 5;
camera.update();
spriteBatch.setProjectionMatrix(camera.combined);
Hope this helps someone!
In case you haven't figured this out yet, you need to convert the ball position to the camera position using
camera.unproject(ballPosition)
This converts the screen coordinates into world coordinates. Then call
camera.position(ballPosition)
to set the camera position to your ball's location in the world.
The
camera.translate(...);
function translates all of the involved attributes the camera by the given data. After the operation you need to call
camera.update();
to calculate the new matrices of the camera. This will push the camera to the direction you want.

Resources