hello,
I am working on Kev’s source code for T4XI. I wanna port it to J2ME but the Graphics does not have the rotate method only the translate. I am working on a method that draws a little red car.
g.translate(cars[i][0]*30,cars[i][1]*30);
g.rotate(cars[i][2]);
g.setColor(Color.black);
g.fillRect(-9,-7,14,5);
g.fillRect(-9,5,14,5);
g.setColor(carCols[(int) cars[i][7]].darker());
g.fillRect(-7,-11,10,23);
g.setColor(carCols[(int) cars[i][7]]);
g.fillRect(-7,-5,10,15);
g.rotate(-cars[i][2]);
g.translate(-cars[i][0]*30,-cars[i][1]*30);
So, the question is, how can I substitute the Graphics.rotate method with a manual made rotate method?
I’ve tried the following formula (I’m not sure right now, since I’m not with my source code here, but is something similar to this):
x’ = xMath.cos(cars[i][2]) - yMath.sin(cars[i][2])
y’ = yMath.cos(cars[i][2]) + xMath.sin(cars[i][2])
With this code, the car make a circle movement (all the car), which is not what I wanna. I wanna the car move like T4XI game (left and right arrow rotates the car around its axis, and up and down arrows move the car back and forth).
I hope that I made myself clear