# Hard Light Productions Forums

## Modding, Mission Design, and Coding => The Modding Workshop => Modding Tutorials => Topic started by: Vertigo 7 on January 10, 2009, 12:05:31 am

Title: multipart turrets on angled surfaces
Post by: Vertigo 7 on January 10, 2009, 12:05:31 am
can this be done? i thought that you could "define" the X Y and Z rotation
Title: Re: multipart turrets on angled surfaces
Post by: Wanderer on January 10, 2009, 01:26:58 am
I think this has already been described in IRC but...

Some of the work needs to be done in some modelling application and some while the subobject properties. First you just need to know the uvec (ie. surface normal of the turrets location) and fvec (turrets front vector. These can be determined in number of ways, most often this means that you can handle basic trigonometry.

Also the turret should also be placed (while modelling) so that it faces the fvec AND has barrels in 90 deg elevation (ie. pointing along uvec)
Title: Re: multipart turrets on angled surfaces
Post by: Scooby_Doo on January 10, 2009, 02:34:05 am
I've written a program that'll help generate the uvec and fvec. I'll get it uploaded sometime soon.  (BTW it does require .Net 2.0)
Title: Re: multipart turrets on angled surfaces
Post by: Scooby_Doo on January 11, 2009, 10:31:43 pm
Here you go: http://scoobydoo.freespacemods.net/Completed/Angle2VectorConverter.exe

It's ready for 3dmax usage (or any app where Z is up/down) and for those still using the old truespass cob method.

The angle of the turret is the "Rotation", if the original turret isn't facing up forward (i.e. it's original angle isn't at 0,0,0) then add "turret origin".
i.e. The most common case: if you made a turret facing up-forward then rotated it to it's correct angle on the hull of let's say (20,0,0) then rotation would be (20,0,0) and turret origin would be (0,0,0).

I'm not make any guarantees that it's 100% correct.
Title: Re: multipart turrets on angled surfaces
Post by: Roanoke on January 14, 2009, 03:37:35 pm
I'd be surprised if Max doesn't already have some feature that allows a user to view & manipulate normals.
Title: Re: multipart turrets on angled surfaces
Post by: Talon 1024 on January 17, 2009, 09:01:13 pm
Sorry, I don't regularly visit the IRC channel, so I don't know how to do this, or if it is already in the code.

How do I set the turret rotation? is it defined in the tables or the model itself?
Title: Re: multipart turrets on angled surfaces
Post by: Scooby_Doo on January 17, 2009, 10:26:05 pm
Sorry, I don't regularly visit the IRC channel, so I don't know how to do this, or if it is already in the code.

How do I set the turret rotation? is it defined in the tables or the model itself?

It's in the pof model, on the subsystem. It's \$uvec and \$fvec
Title: Re: multipart turrets on angled surfaces
Post by: Wanderer on January 18, 2009, 02:08:13 am
Step 1.
When placing the turret on to the ship in some modeling proggie make sure the turret model's front points to the desired front vector (future fvec) direction and that the barrels are in 90 degree elevation (pointing along the desired up vector or uvec).

Step 2.
Use whatever means possible to gather the data required to set up the fvec and uvec. There are utilities (like what Scooby posted, one hopefully soon to be released MAXscript or some other utility), or determine the vector by some other means (like using dummy objects with modeling program), or then by trial and error.

Step 3.
Input the data to the subobject properties box when editing pof data (with for example PCS2). Most likely last entries of that particular subsystem.
Quote
\$uvec:x,y,z
\$fvec:x,y,z

Step 4.
Setup the animation code part of that subsystem entry in ships.tbl to what ever default you want the barrels to point to.
Title: Re: multipart turrets on angled surfaces
Post by: Talon 1024 on January 21, 2009, 10:11:10 pm
Thanks for the tutorial, Wanderer.  I'm going link to this thread in my sig, for future reference.

@Scooby Doo: I don't understand what the "Turret origin" is...
Title: Re: multipart turrets on angled surfaces
Post by: Scooby_Doo on January 21, 2009, 10:53:10 pm
Turret origin is usually (0,0,0).  If you designed your turret so it's facing up forward it'll be 0,0,0.  In the odd case you designed the turret facing down it'll be 0,180,0 (i think).

Basically this is the angle required to bring the turret so it's facing up forward, if it's already up facing forward then theres no angle offsets needed.  :)
Title: Re: multipart turrets on angled surfaces
Post by: Scooby_Doo on June 06, 2009, 03:52:35 pm
Just a heads up, my app won't run in Win7 64bit (i dunno about vista 64).   It'll run but when you hit calc it'll crash complaining about bad image.  Something to do with DirectX Vector3  :confused:  I'll have an updated version uploaded soon.
Title: Re: multipart turrets on angled surfaces
Post by: FreeSpaceFreak on November 01, 2009, 02:39:53 am
So, for a rear-facing turret, the uvec would point straight to the back... and the fvec as well?
Title: Re: multipart turrets on angled surfaces
Post by: Scooby_Doo on November 01, 2009, 03:08:20 am
The uvec would be facing back, the fvec (forward) would be either straight up or straight down (depending on how you setup the turret).  Think of forward vector as the vector where the front of the turret is facing.

edit: oh and ya, I've updated the program several months ago.
Title: Re: multipart turrets on angled surfaces
Post by: Vasudan Admiral on November 01, 2009, 06:38:02 am
Photo group demonstration of Fvec and Uvec!
http://i5.photobucket.com/albums/y184/VA--Twisted_Infinities/BlenderTutorialStuff/VectorTurret1.jpg
http://i5.photobucket.com/albums/y184/VA--Twisted_Infinities/BlenderTutorialStuff/VectorTurret2.jpg
http://i5.photobucket.com/albums/y184/VA--Twisted_Infinities/BlenderTutorialStuff/VectorTurret3.jpg
http://i5.photobucket.com/albums/y184/VA--Twisted_Infinities/BlenderTutorialStuff/VectorTurret4.jpg
http://i5.photobucket.com/albums/y184/VA--Twisted_Infinities/BlenderTutorialStuff/VectorTurret5.jpg

So, the Uvec always points straight up out of the turret, and forms the axis the turret base rotates around.

The Fvec is to tell FS where the front of the turret base IS facing - as in, you match it to the direction the arms ARE pointing rather than pointing it off in some other weird direction you would like them to face, where FS will have no idea what you're talking about and your arms will do stupid things like rotate around false axes.

As for how to get those vectors, I still reckon the easiest way is in PCS2 with 2 gunpoints. Place both gunpoints in the centre of rotation for the turret base, and begin entering whatever numbers you like in the normal field till you get the hang of how they work if you don't already know. Point one up out of the turret along the turret base' rotation axis, and point the other in the direction the turret base is facing. Press the "Norm" button to normalise (make equal to 1 unit long) those normals, and now you have your three X, Y and Z values for each vec. :)
Title: Re: multipart turrets on angled surfaces
Post by: FreeSpaceFreak on November 01, 2009, 02:14:12 pm
So what if you have an empty for turret base, does it matter where you point the fvec to? Should it be in the plane normal to the uvec?
The turret is mounted on the tail of a bomber, pointing straight rear by default.

(http://i35.tinypic.com/23r8ies.jpg)
Title: Re: multipart turrets on angled surfaces
Post by: Aardwolf on November 01, 2009, 04:15:47 pm
does it matter where you point the fvec to? Should it be in the plane normal to the uvec?

Yes. The fvec and uvec should always be perpendicular.
Title: Re: multipart turrets on angled surfaces
Post by: Vasudan Admiral on November 01, 2009, 04:57:21 pm
I don't know how strict that 'perpendicular-ness' rule is, so I wouldn't worry about how accurate you are there, BUT I don't think you can use an empty as FS hierarchy - use a tiny internal cube or something instead.
Title: Re: multipart turrets on angled surfaces
Post by: Bobboau on November 02, 2009, 12:52:53 am
as long as the two vectors aren't the same it should be fine, uvec has priority, fvec will be projected into the proper plane (defined by uvec), there is also an rvec that gets automajicaly calculated.
Title: Re: multipart turrets on angled surfaces
Post by: Vasudan Admiral on November 02, 2009, 02:05:17 am
Nice. :D
Title: Re: multipart turrets on angled surfaces
Post by: FreeSpaceFreak on November 03, 2009, 01:53:57 pm
Guh... I must be doing something wrong... The turret is there, but it's not firing... And it seems to be indestructible as well... Anyone willing to take a look? Download (http://www.sectorgame.com/ASW/Zakros_Public.zip)

(Placeholder textures and table, obvoiusly)
Title: Re: multipart turrets on angled surfaces
Post by: chief1983 on November 04, 2009, 08:09:03 pm
Usually, you use the detail0 turret subobject not the detail1 subobject.  Not sure if that alone could break it.  They're also set to no movement.  Is the ball supposed to move and shoot or remain stationary?  I'm also not sure what the purpose of the turretholder object is.  It's not visible as far as I can tell, nor part of the turret.  Why not just make it part of the main mesh?  Seems a waste of a subobject to me.
Title: Re: multipart turrets on angled surfaces
Post by: FreeSpaceFreak on November 05, 2009, 12:31:20 am
Wow, that's just a few dumb mistakes... :nervous: It moves and fires alright now, thanks.
The ball is supposed to move and shoot, yeah. As for the turretholder thing, I split that off for convenient unwrapping. Made it an untargetable subsystem now.
Title: Re: multipart turrets on angled surfaces
Post by: Talon 1024 on November 24, 2009, 12:04:12 am
If you are using Blender and you want to use Scooby Doo's utility for calculating the uvec and fvec:
- Copy the angle of the turret (or an empty with it's "z" as the uvec and it's "y" as the fvec) into the converter
- Press Calculate
Title: Re: multipart turrets on angled surfaces
Post by: Wanderer on November 24, 2009, 06:23:18 am
Important notes...

• When viewing model in PCS2 and setting uvec and fvec values using PCS2 vectors it is important to notice that first vector element ('X') needs to be reversed.
• Turret uvec and turret normal need to match (while remembering the above rule) or otherwise turret rotation matrix will not work as it should.
Title: Re: multipart turrets on angled surfaces
Post by: Talon 1024 on April 14, 2011, 11:00:47 am
You may also need to reverse the "z" element on the uvec and the "y" element on the fvec in some cases, particularly if you've got a multipart rotated on the x-axis only.

The "x" element almost always needs to be reversed.
Title: Re: multipart turrets on angled surfaces
Post by: Wanderer on April 14, 2011, 11:05:27 am
As this thread was revived i could add a note that it is no longer necessary to match turret uvec and turret normal. Assuming you have a valic turret fvec and uvec the uvec will override (and overwrite) the turret normal.
Title: Re: multipart turrets on angled surfaces
Post by: Kusanagi on April 16, 2011, 01:52:21 am
As this thread was revived i could add a note that it is no longer necessary to match turret uvec and turret normal. Assuming you have a valic turret fvec and uvec the uvec will override (and overwrite) the turret normal.

This also means that the firing points will look very messed up in PCS2, but as long as you rigged them just fine in your 3d program they'll work in game.