So far in my game, I have been rotating by rendering w/ slick2d. I was working, and realized that I needed the coords of a point on an object when it is rotated. So that, say I rotate it 78 degrees: the object should rotate and I should be able to get the coords of (6, 1) on the image, while rotating.Sorry if it is unclear what I am asking!

EDIT:I realize that that is incredibly unclear, let me elaborate:I have a gun that rotates, and I need to shoot from the tip of the gun. The gun's sprite is 8x8, and the tip is at (1, 6). When I rotate, I want to make the bullets instantiate at the tip, so how would I do that? I tried this post, but it did not work at the last post. Just looped around in circles around the x and y... Useless. So what would I do?

ANOTHER EDIT:Okay, here is my problem in excruciating detail:I have a player that I render. Then I have a gun that I render. See the two sprites:

I have the gun take the player's rotation, and fire from a point, 1, 6 on the gun. I want to rotate it. So I do this formula:

But instead of the line starting at 1,6 on the gun, and ending on the mouse, I get this:NOTE: Mouse is not visible, but the mouse is in all pictures at the farthest point on the line away from the player.

I'll guess you know your rotation angle that was applied to rotate the gun. What you need to do is to calculate the angle of the vector from (x,y) to (1,6) (using atan2). The angle of that vector to the vector of the bullet that will launch from the tip is your "base rotation". You just add your gun rotation to that and use sin() and cos() to calculate the new location of your original (1,6). This way you know the location where the bullet launches. Your gun rotation without the "base rotation" gives you the flying vector of the bullet.

A simple solution would be to have the projectile movement vector angle match that of the rotating shooter, and then just "teleport" the bullet upon instantiation a distance equal to the barrel length.

That way you save on calculating the position of the barrel's tip.

But you do need to have a decent vector class to handle the projectile's motion in any case.

I'll guess you know your rotation angle that was applied to rotate the gun. What you need to do is to calculate the angle of the vector from (x,y) to (1,6) (using atan2). The angle of that vector to the vector of the bullet that will launch from the tip is your "base rotation". You just add your gun rotation to that and use sin() and cos() to calculate the new location of your original (1,6). This way you know the location where the bullet launches. Your gun rotation without the "base rotation" gives you the flying vector of the bullet.

Is that in anyway a help? ^^

Nitram

Okay, I see what you are getting at, but I don't know how to translate that to code. Could you give a small example?

Quick demo of the maths highlighted there for you. Give it a quick run. Its a bit messy with keeping track of separate x and y values instead of nice Vector2's, but alas. You need to make sure you keep track of the local frame of reference when calculating coordinates for parts of the sprite.

Okay A little trouble not with the code itself, but the terminology. I cannot get what 'muzzle,' or 'grip.' Can you explain more about what those mean? I am having trouble implementing this into my code.

"Grip" is the handle of the gun, basically where Player is holding it (the point rotating around the player's location, in your case (1,6)).The "muzzle" in my example is the end of the gun's barrel, but looking at your post, you are using mousex and mousey, so you can likely ignore that.

Mainly the gunPosX and gunPosY are what you were looking for and I hope I showed how to calculate them. (Although if I spent more than 5 mins I could put together a better way)

Okay the problem either lies in the angles I am feeding the code, or what offset means. I am assuming it means the point on the gun's sprite I want to find (1, 6)? Also, here is my result:So the point where 1, 6 is supposed to be is really just stuck on the circumphfrance of a circle with a center point on the top left corner of the gun sprite, and a radius defined by the offset. It's weird.

Based on that pic, it looks like the rotation is working correctly, but your player x and y are already offset from where it is being rendered. (I hope that makes sense) It looks like the circle is centered out in front of his head, when it's supposed to be centered on the top of his head.

Try making offx and offy smaller, especially the offy, that should (should) bring it back toward the player sprite.

Does the circle stay out in front of his head, even when you face a different direction? Or does it stay to to the above left of him, no matter where he faces? I'm pretty sure I know what it is if it is the latter.

It will now exhibit your same problem.This is due to the fact that drawOval(x,y,w,h) draws the oval's top left corner at the given (x,y), instead of it's center.I suspect this is what is happening to you, as I know that Slick is supposed to act like J2D.

So were ever you render the sprite, subtract width/2 from x and height/2 from y, or add them to the tipx,tipy if that interferes with your collision detection, etc.

No prob, was bored tonight, figured I help out the first person I saw here. I suspect that maybe the offsets could be divided by an equal factor, possibly related to the '8' earlier. Try some nums between 2 and 8 and see. Or just calculate how far off you are and find the exact constant.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org