Okay, so to recap, I have an ammo controller object attached to my player ship. When the ship fires, it adds ammo objects to the controller. The ship's render function includes calling the ammo controller's render function, which cycles through each ammo object's render function, rendering each bullet.
The way I move my bullets is the following formula:
Code: Select all
currentBulletPosition.X = currentBulletPosition.X + ((ship.constAccel * 1.0f) * (2.0f * deltaTime));
currentBulletPosition is that individual bullet's current position, stored as a Vector3 object, and when the bullet is initialized, it's set to my ships current position in the world;
deltaTime is the current framerate returned from my timer function;
ship.constAccel is my world's constant forward movement rate [remember, this is a shmup! ]
This works wonders for all my normal bullet types - standard straight shots, sine/cosine waves [with a few tweaks of course]... but it doesn't work for rotated bullets.
Here is my problem:
I want to build in a Gradius-style "Double" shot, where one of the bullet streams is angled up a bit. I also want this function to permit sprays of bullets at various angles, or even 360 degrees around the ship firing.
I'm racking my brain figuring out how to get it to work right. Here is what I have so far:
In the Fire() method:
Code: Select all
for(int i = 0; i<360; i = i + 30)
{
newBullet = new weapons.ammo(this, x, y, z, bullet, ammo.firingType.FT_Standard_Angle, (float)i);
ammoControl.addAmmo(newBullet, "bullet");
}
<the Move() function is above>
The render() function:
Code: Select all
case firingType.FT_Standard_Angle:
{
Matrix rotMatrix = Matrix.RotationZ(Geometry.DegreeToRadian(firingAngle));
transform_matrix = rotMatrix * Matrix.Translation(currentBulletPosition);
break;
}
bulletMesh.Render(transform_matrix);
All that I can get it to do is fire tight clusters of bullets out in front of me, in the same pattern it fires normal bullets. Here's a picture:
Removing the move code all together leaves the clusters in their original places, which is basically where I want them to be - their center points need to stay where they were fired from - but I can't figure out how to transform the actual locations of each bullet individually. Any time I try to apply a transform to the bullets, it affects every one in the same manner. I once actually DID get it to fire them out into a burst pattern - except that each time I would fire a new bullet cluster, it wouldn't start from my current location - each bullet would start with the transform from the last cluster applied to it.
Anyone know what the heck I'm doing wrong? It's been too long since I've done vector math, and I haven't found any good sites for resources on how D3D's transforms work. It seemed like my way would make sense to me... rotate the mesh, then transform it out to where it needs to be. Apparently not.