Author Topic: Coding scrapbook (side multipart turrents)  (Read 6594 times)

0 Members and 1 Guest are viewing this topic.

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Coding scrapbook (side multipart turrents)
This is partly for odd thoughts, mostly in hope that someone better educated in 3D math can maybe give a helpful suggestion.

I think that the function that needs to be changed is the function that generates the turret's rotation matrix. (This is multiplied against the orientation matrix to find the find the final rotation, along with other messy calculations.)

The relevant function, model_make_turrent_matrix. Note that sm-> represents the barrel, and sm_turret-> represents the gun base.

Both base and gun barrel have three rotation compoents, pitch, bank, and heading.
Code: [Select]
//Clear all turret angles
model_clear_instance(model_num);
//Find turret's 'f' vector (?) component of rotation matrix in world coordinates
model_find_world_dir(&fvec, &turret->turret_norm, model_num, turret->turret_gun_sobj, &vmd_identity_matrix, NULL );

//Set base heading to -PI/2 radians (or -90 degrees)
sm_parent->angs.h = -PI/2.0f;
//Set gun pitch to -Pi/2 radians (or -90 degrees)
sm->angs.p = -PI/2.0f;
//Find the 'r' vector (?) component of the rotation matrix using these two angle changes
model_find_world_dir(&rvec, &turret->turret_norm, model_num, turret->turret_gun_sobj, &vmd_identity_matrix, NULL );

//Set base heading to 0 radians (or 0 degrees)
sm_parent->angs.h = 0.0f;
//Set base heading to -Pi/2 radians (or -90 degrees)
sm->angs.p = -PI/2.0f;
//Get 'u' vector (?) compoent of rotation matrix using angle changes.
model_find_world_dir(&uvec, &turret->turret_norm, model_num, turret->turret_gun_sobj, &vmd_identity_matrix, NULL );

//Normalize all three vector components
vm_vec_normalize(&fvec);
vm_vec_normalize(&rvec);
vm_vec_normalize(&uvec);

//Copy normalized vectors to permanent location
turret->turret_matrix.vec.fvec = fvec;
turret->turret_matrix.vec.rvec = rvec;
turret->turret_matrix.vec.uvec = uvec;

My guess (after writing that up) is that for side turrets, I need to set te gun barrel to initially have a heading of -90 degrees (left side facing out) or 90 degrees (right side facing out) and use the difference for the 'r' and 'u' vectors. And for the base, start it out with the same.

As in, the default position would be the gun barrel sticking out to the side, and able to twist fore and aft. (But in order to twist up or down at all, the base would have to turn). Although the model I'm working with now seems to have it as the reverse; the barrel can twist up and down without the base moving, but not fore and aft.

Edit: Can't test this now, as fs2_open has started crashing every time I launch the test mission (seems to be an unrelated bug). However the headings have been changed, although I don't feel too confident of it being the solution. (Not to mention I also have to figure out which turrets are side turrets to apply this).

Edit 2: Here's my p/b/h chart. I keep getting them mixed up, so I'm not 100% sure of this, either. :rolleyes:

« Last Edit: December 14, 2005, 03:41:04 am by WMCoolmon »
-C

 
Re: Coding scrapbook (side multipart turrents)
Quote
model_make_turrent_matrix

Deliberate or accidental? :p

I wonder, could the bank be used to create side-mounted multi-part turrets? Or indeed, placed at any angle on the hull?

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: Coding scrapbook (side multipart turrents)
that function only deals with the inital state of the turret, model_rotate_gun (wich is just below it) is were most of your work is likely to be.
(and yes people, that is how the function is spelled, this is the ONLY instance in the code were it was spelled like this (there are four references, one for the function definition, one for the declairation and two for the coment above each))

for the inital matrix you just need to remember what the three vectors of the matrix are fvec(forward vector, the vector along wich the guns will shoot), uvec(up vector, should generaly be pointing up (0,1,0) if the fvec is pointing out to the side), and the rvec(right vector, should be pointing to the back on turrets on the tight side of the ship, forward on turrets on the left side of the ship). if you want to assume that the turret will always be pointing directly to the side of the ship it will make things infinitely easier, but haveing code for any orientation is perfictly posable.

pitch is rotation around the x axis (around rvec), heading is rotation around the y axis (around uvec), and bank is rotation around the z axis (arounf fvec).

I think you are going to have to add stuff to the submodel properties allowing for a custum made orientation matix, and flagging the turret as useing new rotation code.
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Coding scrapbook (side multipart turrents)
any chance of having turret rotation limits, so you could make a turret that can only rotate about 90 defrees in either direction. you could use that to put turrets on the side that rotate the same way normal turrets do, but wouldnt turn so the barrel points inward. sorta like the side turrets you see on early ww1 tanks.

i always thought of those kind of turrets as astheitcally pleasing and would only require rotation limits. simply implementing turret angle limitations now would greatly improve the versitility of turrets. im not saying dont do side turrets, im saying do this too :D and if you got time, gatling turrets please :D
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline StratComm

  • The POFressor
  • 212
  • Cameron Crazy
    • http://www.geocities.com/cek_83/index.html
Re: Coding scrapbook (side multipart turrents)
You and your gatling obsession :rolleyes: 

While I think proper 2-dimensional fov arguments are worth implimenting, I feel that I need to point out something.  There's a world of difference between changing the (retarded) hard-coded way that multiparts are handled in order to generalize them to side turrets, etc. and allowing truly arbitrary rotation.  They are almost not even related.  And apparently, :v: can't spell "turret" either.  :p
who needs a signature? ;)
It's not much of an excuse for a website, but my stuff can be found here

"Holding the last thread on a page comes with an inherent danger, especially when you are edit-happy with your posts.  For you can easily continue editing in points without ever noticing that someone else could have refuted them." ~Me, on my posting behavior

Last edited by StratComm on 08-23-2027 at 08:34 PM

 

Offline phreak

  • Gun Phreak
  • 211
  • -1
Re: Coding scrapbook (side multipart turrents)
Code: [Select]
Searching for 'turrent'...
C:\projects\fs2_open\code\model\model.h(1341):// Tries to move joints so that the turrent points to the point dst.
C:\projects\fs2_open\code\model\modelread.cpp(3883):void model_make_turrent_matrix(int model_num, model_subsystem * turret )
C:\projects\fs2_open\code\model\modelread.cpp(3926):// Tries to move joints so that the turrent points to the point dst.
C:\projects\fs2_open\code\model\modelread.cpp(3947): model_make_turrent_matrix(model_num, turret );
4 occurrence(s) have been found.


edit:

Code: [Select]
Commiter   : fs2source
CVSROOT    : /home/fs2source/cvsroot
Module     : fs2_open
Commit time: 2005-12-15 04:31:15 UTC

Log message:

[V] can't spell 'turret'

Modified files:
     code/model/modelread.cpp code/model/model.h
« Last Edit: December 14, 2005, 10:30:41 pm by PhReAk »
Offically approved by Ebola Virus Man :wtf:
phreakscp - gtalk
phreak317#7583 - discord

 

Offline StratComm

  • The POFressor
  • 212
  • Cameron Crazy
    • http://www.geocities.com/cek_83/index.html
Re: Coding scrapbook (side multipart turrents)
I so almost put in a comment about being suprised no one had done a find and replace on that yet, but decided not to because I was afraid someone would actually go and do it.  Guess I didn't even need to say it :p
who needs a signature? ;)
It's not much of an excuse for a website, but my stuff can be found here

"Holding the last thread on a page comes with an inherent danger, especially when you are edit-happy with your posts.  For you can easily continue editing in points without ever noticing that someone else could have refuted them." ~Me, on my posting behavior

Last edited by StratComm on 08-23-2027 at 08:34 PM

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: Coding scrapbook (side multipart turrents)
:V:'s spelling is law :eek:

Heathen!!!

Edit: Oh, and before I de-rail my own thread :rolleyes: while it'd be nice to have turrets rotatable on any orientation, that's probably a little beyond me at this point...I thought I could use turret normals to determine turret orientation and generate a rotation matrix on that, but some of the 'straight' turrets on the Galactica have bizarre normals.
« Last Edit: December 15, 2005, 03:01:14 am by WMCoolmon »
-C

 

Offline Flipside

  • əp!sd!l£
  • 212
Re: Coding scrapbook (side multipart turrents)
:lol: I always thought it was because people got confused between turret and torrent that caused that spelling mistake. It must be some kind of strange universal mental block...

It'd be great to see side turrets working, I must admit :)

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: Coding scrapbook (side multipart turrents)
if a rotation axis vector is given for the two models it should be posable to set up a matrix like that easily
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: Coding scrapbook (side multipart turrents)
Hmm...OK, I took another look at this. I'm a bit confused though - where do the values for the turret normal come from?

Erg...at the moment all that I'm really sure of is that I need to change this section of code:
Code: [Select]
angles desired_angles;

desired_angles.p = (float)acos(of_dst.xyz.z);
desired_angles.h = PI - atan2_safe(of_dst.xyz.x, of_dst.xyz.y);
desired_angles.b = 0.0f;

// mprintf(( "Z = %.1f, atan= %.1f\n", of_dst.xyz.z, desired_angles.p ));

//------------
// Gradually turn the turret towards the desired angles
float step_size = turret->turret_turning_rate * flFrametime;

vm_interp_angle(&base_angles->h,desired_angles.h,step_size);
vm_interp_angle(&gun_angles->p,desired_angles.p,step_size);

Possibly using vm_extract_angles_vector on of_dst instead of the manual calcs...

At this point I think I'm pretty lost :sigh:

As near as I can tell, the "normal" field on turrets either means something, or means something different than orientation. vm_extract_angles works, but does not fix the side turret on the BSG. Presumeably I'm missing something, and need to translate the "b" component into the "p" and "h" components of the side turrets somehow.
-C

 

Offline Mav

  • 28
  • location: Shivan fleet - closing in on GTVA space
Re: Coding scrapbook (side multipart turrents)
hmmm... the "desired_angles.b = 0.0f;" says it to not change rotation around one of the axes, I'd say - doesn't it?  :confused: Then that would be one point that'd certainly need changing. (maybe creat a copy of the function for side turrets that says something like 90 degrees there? could eventually work...)
Btw, what does "of_dst.xyz.z" do? Give you the specified component of the vector?

(sorry, not much time now for calculating; maybe sometime (read: days) later  :( )
-__ o_O___O_o
I______O_O_______dragons
________o

-----------------------------------
capship shields DO WORK !!!
my models, now with pics
test mission for commanding capships
-----------------------------------
suffering from a late stage of BoE-infection - DON'T call a doctor, it's too late for that anyway ;o)

  

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Coding scrapbook (side multipart turrents)
i think hes got a point.

i figure on a side turret youd just need to swap

desired_angles.p = (float)acos(of_dst.xyz.z);
desired_angles.h = PI - atan2_safe(of_dst.xyz.x, of_dst.xyz.y);
desired_angles.b = 0.0f;

with

desired_angles.p = PI - atan2_safe(of_dst.xyz.x, of_dst.xyz.y);
desired_angles.h = (float)acos(of_dst.xyz.z);
desired_angles.b = 0.0f;

essentially swapping pitch for heading. likewise if you wanted a rotating turret on front back you could probibly use

desired_angles.p = (float)acos(of_dst.xyz.z);
desired_angles.h = 0.0f;
desired_angles.b = PI - atan2_safe(of_dst.xyz.x, of_dst.xyz.y);

only problem is i bet it would alter all turrets youd have to do an if to check where the turret is (based probibly off a subobject property value) and then run the proper arangement for that type. but im not a coder and im just talking out of my ass.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: Coding scrapbook (side multipart turrents)
Yeah, it would alter all turrets. At first I thought I could use the turret normals to check if a turret is on the side or not, but apparently not...
-C

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Coding scrapbook (side multipart turrents)
perhaps ad a subsystem property for side turrets like $turret pos: with values like side and front. of course top would be default.

also it looks like if you wanted to have a turret rotation limit feature, whis would be where to put it. just a mater of changing the math abit.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline TrashMan

  • T-tower Avenger. srsly.
  • 213
  • God-Emperor of your kind!
    • FLAMES OF WAR
Re: Coding scrapbook (side multipart turrents)
Yeah, it would alter all turrets. At first I thought I could use the turret normals to check if a turret is on the side or not, but apparently not...

Why not? Shouldn't you be able to just compare the turret base normal with the normal of the ship hull?
Nobody dies as a virgin - the life ****s us all!

You're a wrongularity from which no right can escape!

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: Coding scrapbook (side multipart turrents)
this looks like a job for!!!

...the subobjects properties feild.
just add a '+rotation_axis:' thing to there. y is default, x would be side, z would be a weird thing that probly would never get used.
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Taristin

  • Snipes
  • 213
  • BlueScalie
    • Skelkwank Shipyards
Re: Coding scrapbook (side multipart turrents)
this looks like a job for!!!

...the subobjects properties feild.
just add a '+rotation_axis:' thing to there. y is default, x would be side, z would be a weird thing that probly would never get used.

no forwar facing multi-part turrets?

(mulit part turrents! :D)
Freelance Modeler | Amateur Artist

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: Coding scrapbook (side multipart turrents)
well I guess I could see them being used for some sort of odd offencive thing, but realy I doubt it would get much use, though you might as well through it in there if your going to do the rest.
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Trivial Psychic

  • 212
  • Snoop Junkie
Re: Coding scrapbook (side multipart turrents)
this looks like a job for!!!

...the subobjects properties feild.
just add a '+rotation_axis:' thing to there. y is default, x would be side, z would be a weird thing that probly would never get used.
I don't recall seeing that one in the WiKi.
The Trivial Psychic Strikes Again!