Direct3D Vector Headaches! Anyone know the solution?

A place for people with an interest in developing new shmups.
Post Reply
User avatar
sniperwolf
Posts: 39
Joined: Wed Aug 10, 2005 10:44 pm
Location: Oregon

Direct3D Vector Headaches! Anyone know the solution?

Post by sniperwolf »

Okay... progress is going great on the engine. Except one little problem that's been KILLING me for 3-4 days now. I've been working on it day and night now, and I can't seem to solve it...

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));
Where:

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 bullet class:

<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);

As you can see, it constructs a world transform matrix for the object, then passes it off to that bullet's render() function.

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:

Image

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. :evil:

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. :(
How do I wrote code?
ynohtna
Posts: 3
Joined: Fri Feb 18, 2005 1:45 pm
Location: Brighton, UK
Contact:

Post by ynohtna »

Uh. constructing and multiplying several 3D matrices to move each angled bullet is somewhat, um, non-optimal. In addition, it makes the code highly susceptible to bugs such as the one you're currently experiencing.

Do you have a good reason for implementing it this way instead of directly applying basic trigonometry?
User avatar
landshark
Posts: 2156
Joined: Wed Jan 26, 2005 5:27 am
Location: Chicago 'Burbs

Post by landshark »

ynohtna wrote: Do you have a good reason for implementing it this way instead of directly applying basic trigonometry?
That's my suggestion too. Store a direction vector and increment the position by this vector scaled by your framerate.
User avatar
sniperwolf
Posts: 39
Joined: Wed Aug 10, 2005 10:44 pm
Location: Oregon

Post by sniperwolf »

I should've added, I was working on using basic trig to do the movements like you guys said, but for some reason I had it stuck in my head that it'd be easier to use the matrix functions.

And really, I had the Gradius-style double shot working fine with a simple trig function, but it broke when I tried to rotate the bullets around the whole ship. Now that I think about it, I don't think it's a hard fix...

Thanks for the advice!

Oh, and also, in the name of not having to recompile and retest things every time I make a minor change, I've started work on a "bullet simulator" app. Something almost like bulletML's tester applet. Something to let me try out new equations and fine tune them till they're juuust right, without having to mess with the main application.
How do I wrote code?
User avatar
sniperwolf
Posts: 39
Joined: Wed Aug 10, 2005 10:44 pm
Location: Oregon

Post by sniperwolf »

Wooo! Progress!

I went back and messed a little bit with the existing trig function I was playing with.. and this just looks a lot better. :)

Image

Oh, and the background picture is blatently ripped off from DeviantArt. I need to get permission from the artist to use it in the released sample game though, I like it. :D
How do I wrote code?
Post Reply