rotating cogs in java - java

First of all my english is rubbish, so please understand.
I have been asked to do a little simulation/animation in java.
I have a few cog on board one of the cogs rotates all the time on its axis. when I move any other cog close to the rotating one it has to start rotating and teeth can not overlap each other.
I think this link describes it quite well
http://www.csharphelper.com/howto_animate_gear.gif
I don't know how to make this cogs interact together, i will be really happy if some can show some code example
Many thanks for any help

If you know how to rotate the kog, you could cheat a bit, and hard-code the timing so that they rotate at the right time :P

This is a classic LCM (Least Common Multiple) problem: try to formulate a solution from the dimensions (radius or diameter or circumference) of the cogs.

Related

Android - Pathfinding on map.png

Good morning,
I'm working currently on a pathfinding project. Basically, I got this map on my application :
And so I just want to determine the shortest way to go from A to B (of course, I can't go through the blue and gray part which are basically walls...)
Is A* algorithm a good way to start ?
Well if you have any ideas, any suggestions about this problems, tell me ^^
Thank's for your help !
Yes, A* is a good start, assuming you mean to allow movement on the grid only. I mean an agent on a pixel would only travel North, East, South, West and never diagonally. Be warn you will obtain rather un-natural looking paths with 90° and 45° angles everywhere, but this can be mitigated later using some appropriate tie-breaker.
I propose you start using Dijkstra, and once you got that working modify it to implement A* - both algorithms are very close.
If instead you intend to allow your agents to travel diagonally from any pixel to any other pixel which has direct visibility, then no, an other algorithm is needed.

Agar.io-like cell physics

I wanted to make a circle that has a ripple-effect on the edges, kind of like in the game agar.io. I am kind of lost on how to implement it. Obviously I can't just g.fillOval() because that would draw a solid circle with no movement on the edges.
I'm not asking anyone to write any code for me (but if you really want to, I don't mind :D), but if you could point me in the right direction with some methods I should use. I am using Slick-2D library for java, if that helps.
I also tried analyzing the javascript source from the agar.io website to try to understand how they implemented it in javascript, but I was unsuccessful because the code was obfuscated; all the methods and variables were just single letters.
The only way I can imagine doing this currently is to have each circle be composed of a number of points, and let each point have it's own physics, and it can be affected by other points. If anyone who has insight into this problem, I would greatly appreciate some help. Thank you!
I'm not sure you can do this with Slick2D. It is quite high level and gives a lot built-in classes. What you want to do is really specific. As Slick development has stopped you will not get new features. You should probably look at lwjgl which is the base of Slick. It is more low-level but can be more precise with the form you need.
You can look at this project to have some drawing cool stuff. And for another example of manipulating circle you have this one

How to make an existing polygon move in java?

Hey dudes and dudettes.
High-school Comp Sci student reporting in.
Right now we're doing some work with plotting and polygons, and one of the challenges is to make it move across the screen in a variety of ways. (left to right, etc.) See, this would be no issue if I knew the language or had the means to study it at a basic level. But our teacher just hands us some environment and some code to copy and paste and look off of, none of which really helps in the long run, except for the most basic stuff.
So, my friends, I can make a polygon through plotting points as shown here:
int xPoints[]={ xP*684/1000,xP*706/1000, xP*661/1000, xP*687/1000,
xP*735/1000,xP*760/1000, xP*723/1000, xP*713/1000,
xP*698/1000,xP*686/1000, xP*669/1000, xP*653/1000,
xP*639/1000,xP*639/1000, xP*641/1000, xP*648/1000};
int yPoints[]={ yP*354/1000, yP*354/1000, yP*472/1000, yP*472/1000,
yP*354/1000, yP*354/1000, yP*452/1000, yP*471/1000,
yP*487/1000, yP*498/1000, yP*503/1000, yP*504/1000,
yP*492/1000, yP*473/1000, yP*455/1000, yP*440/1000};
int numPoints=16;
But I cannot figure out for the life of me what kind of specific input or code is required to make it move. (by that I mean translate across the the screen)
Any hints to get me on the right track would be greatly appreciated. I don't exactly have the means of figuring this out on my own.
Edit: Whoops, yep it's Java.
Welcome to SO! You need to break this down into small parts that you need to figure out how to do. Some that come to mind are
Create a window to draw in.
Draw a line in that window.
Draw a polygon in the window.
Move a point from (x, y) in a given direction.
Each of these can likely be broken down even further. Often solving a programming problem starts with this kind of thinking. As you try to do each of these, and any others that you come up with, please feel free to come back and ask more questions.
I don't know IBM VisualAge but if you have any draw method/loop, you should increase xP to move to right, decrease it to move left etc. with a for loop, for example.
Maybe a for loop?
for(int i=0;i<xPoints.length;i++)
xPoints[i]+=1;// shift 1 unit
for(int i=0;i<yPoints.length;i++)
yPoints[i]+=1;// shift 1 unit
Assuming that it's a java.awt.Polygon, have you looked at
Polygon.translate(int dx, int dy); ???
If it is some other kind of Polygon, check to see if it has a similar method.

Basic game logic/ai design

I'm currently working on my 2D game project (Java), but so far any kind of game logic or AI has been crudely implemented. For instance, say I need to randomly position a bunch of sprites a long the top of the screen, I'd be using the Random class to do this. I'd simply use Random.nextInt( size of x axis on which to spawn ); Although this does work I'd be interested to hear how I should really be going about this kind of thing.
As a second scenario (this is why I put AI in the title, although it's not really AI), say I want to have my characters randomly blink in a life-like fashion. What I'd do here is use the Random class to calculate a % (say 20% chance) of blinking and call it every second.
Any suggestions on how I should really be going about this would be greatly appreciated.
Google for a paper titled "Steering Behaviors" by Craig Reynolds. It address just this and you'll find great ideas to start with specifically some nice ideas for giving groups of sprites the appearance of 'intelligent' movement. The key for him in his different behaviors, i.e. flocking, etc. is making properties of any given sprite dependent on those of some other sprite. You could even go so far as to say, like -- any given sprite will blink only if it's two neighbors just have blinked. Something or other along those lines.
Hope this helps!
Are you using an OOP (Object-Oriented approach)? If not, you should definitely look into it. It's really simple with java and can speed up your development time and neaten your code.
I would make a sprite class, and give them a function, say actionSpawn, or actionMove (I like to start my "action" functions with the word action so they are easily identifiable). In this function you would encapsulate the Random.nextInt function, to set the sprite's x and/or y position.
You could use the same approach to make them blink.

How to rotate "Earth" by touching with GLES20 (Android)?

Yesterday I tried to solve a Problem I had the entire Day and it is still unsolved. I searched for every combinations of words I could imagine to find solutions on Google etc. But without success. :(
The Problem consists of following idea:
I started programming GLES20 (Not GLES10!) on Android. There are many other ways how to compute matrixes and objects. So there aren't any methods like "Pop" or "push" Matrix.
I want to rotate a globe/sphere only by touching and moving my fingers. Touching functions etc works fine but the rotation itself never does. Everytime I first rotate by x-axis and then rotating by y-axis the rotation is still computed by local space axis of the object and Not two global axis. This happens whatever I do... :/
There are some people searching the solution for the Same Problem, but mostly GLES10 or completly different programming languages, never GLES20 and Java.
I will also post some Code parts later, when I get access to a Computer.
perhaps someone already understands what my Problem is.
Thank you so much! :)
Chrise
In OpenGL ES 2.0 there aren't any of the matrix functions and you're supposed to take care of your own matrices. So, for pushing and popping matrices what you need to do is when you're drawing you copy your matrix to a temporary one, do whatever transformation on it and pass the temporary matrix to the vertex shader.

Categories

Resources