Sign in to follow this  
cdxrd

Rotation and calculating firing angle troubles..

Recommended Posts

Ok, hopefully someone can help. Ive been playing with this for a while. I have a circular object rotating around its center. This diagram should help explain my troubles. rotation diagram The entire object circles around the center clockwise, in radians. I then have several groups of objects labeled B that rotate with the main object, also around that center point. Each smaller B object is stored in relation to the main circles position using a vector3.. so x&y being the x&y, and im using Z as the angle (in radians).. which I want to be in the direction of the arrows.. ALWAYS.. so as the whole thing rotates, the direction of the arrows rotates with it.. Trouble is, Im geting a sprinkler effect. Sometimes it will keep up for a few seconds, then start going backwards, then just stayput, then suddenly swing around the other way.. doh... Heres what I have been using:

// to set up
Positions[0] = new Vector3(value.X + 325, value.Y + 194, 5.35f);
Positions[1] = new Vector3(value.X + 337, value.Y + 211, 5.35f);
Positions[2] = new Vector3(value.X + 349, value.Y + 230, 5.35f);


// angle is figured here
rotation += elapsed / divider;
float circle = MathHelper.Pi * 2;
rotation = rotation % circle;
float angle = rotation - prevRotation;
prevRotation = rotation;

// object positions / angles are figured out here
for (int zz = 0; zz < 18; zz++)
{
    Vector2 Aim = Vector2.Zero;
    Positions[zz].Z += angle;
    

    Vector3 temp = RotateSphere(new Vector3(Positions[zz].X, 0, Positions[zz].Y), position, angle);
    Positions[zz].X = temp.X + dist.X;
    Positions[zz].Y = temp.Z + dist.Y;
}

//Rotatesphere

public Vector3 RotateSphere(Vector3 oldPos, Vector2 centre, float angle)
{
    Matrix rotationMatrix = Matrix.CreateRotationZ(angle); //angle is in radians 
    Vector2 distance;
    Vector2 newVertex;

    Vector2 temp = new Vector2(oldPos.X, oldPos.Z);
    distance = temp - centre;
    newVertex = Vector2.Transform(distance, rotationMatrix);
    newVertex += centre;
    return (new Vector3(newVertex.X, 0, newVertex.Y));

}

//aiming and drawing here
double tmpAngle = (double)Positions[zz].Z;
Vector2 tmpVector = new Vector2(Positions[zz].X - (spotlight.Width / 2), Positions[zz].Y - (spotlight.Height / 2));
Aim.Y = tmpVector.Y + (int)Math.Round(1200 * Math.Sin(tmpAngle));
Aim.X = tmpVector.X + (int)Math.Round(1200 * Math.Cos(tmpAngle));
draw(start, end)



So all Im really trying to do is figure out why Im getting a sprinkler effect, I would have thought that I could just add the amount of rotation of the main object (in radians) to each of the hole positions and have them aim in the right direction. I cant just add an arbitrary value, like 0.0041675 to the angle, since its based on the elapsed time nd could get out of sync.. Any Ideas here??

Share this post


Link to post
Share on other sites
Quote:
Original post by cdxrd
Trouble is, Im geting a sprinkler effect.


Just to clarify. You're getting a "sprinkler effect" for ...... what, exactly?


The position of your "B" objects? If so, it sounds like this would be handled far easier by storing the position of the B objects as a radius/angle pair, and then just transforming to x,y as necessary.



Also, you mentioned firing angles. What is firing? And what should they be hitting?

[Edited by - HostileExpanse on July 24, 2009 12:02:43 PM]

Share this post


Link to post
Share on other sites
Well, the b objects are positions attached to the main object. Firing, meaning I want to move a sprite from its origin, b, whereever it happens to be on the main object (since its rotating) at the correct angle to its destination.. and I want that angle to properly calculate itself, where right now I can't get it to.

So per the diagram, the B objects should be always fire in that particular angle as they circle around. So right now, the green arrows are facing radian, oh 5.35.. So as the large circle rotates, taking B with it, say it rotates 2.5 radians.

The sprinkler effect is best demonstrated by video I think.. and it gets the point across a LOT better... The angle doesnt properly update to match the direction it should be facing.. THe video is on youtube and will be available as soon as they finish processing.

I know theres probably something really simple im missing or miscalculating here..

Click for video of it not working properly and to give a clear idea what im after

Share this post


Link to post
Share on other sites
Overcomplicated things.. doh.. just take the initial angle the objects should be firing at, track the amount of rotation and increment that each frame.. add the tracked rotation + intial firing angle, and boom. works.. doh...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this