Author Topic: Big feature request: Native 'S-Foil' Support (Action Scripting)  (Read 8469 times)

0 Members and 1 Guest are viewing this topic.

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Big feature request: Native 'S-Foil' Support (Action Scripting)
the way i handled animations when i did my working controls mod was sorta broken up into its own section and well commented. you would add a branch to an if statement for your ship's name string from the table, and by identifying what each block does and what needs to be changed to copy it and use it on another ship. something really easy to modify.

you could also use submodel name strings to trigger certain features for certain subobjects you could name your s-foils s-foil1,sfoil2, ect, then if detected by the script it would then animate those objects automatically. though this could lead to bloat, as with what happened with my turret script, (the whole thing is replaced by a mere 10 lines of code now). if i was a modder with no programming experience, id go with the first option.
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: Big feature request: Native 'S-Foil' Support
You could only do some of this via LUA, and it would be much more difficult for others to understand and edit, let alone create in the first place. AFAIK there is currently no way to properly replicate submodel animation particularly in LUA at all since you can only set subobject positions - which breaks collision detection. It's also infinitely easier to specify a rotation angle, velocity and acceleration than it is to come up with an equation that will perform the same task. ;)

You can set subsystem orientation, although I have no clue if that will actually transfer into subobject orientation in the same way that the animation system does.

Regardless, it's a bit silly to force people to write a lua script every time they want to add in some kind of subsystem orientation, so I think it's worth it to make it doable via a system of some kind; it's also more efficient.

Except that only plain script eval works... number or string do not - well at least they didnt work the last time i tried to make them work with karajorma. You would probably need to go via sexp variables.

I checked mantis and there's no bug report there, so as far as I know they're working right now. I may have fixed them in the last build I posted, which hasn't been committed to SVN as there are some changes I can't commit and I haven't gotten around to sorting them out yet.

I don't like it when people say 'this doesn't work' and they don't know for sure, or don't make a bug report. All it does is scare people away from using them, so either nobody uses perfectly functional code, or they don't get fixed because people are discouraged from using them before a bug report gets registered. This has already happened once with the improper/inconsistent scaling of the mouse/graphics functions in scripting.

EDIT: All that being said, there's nothing stopping someone from creating a script that does do animations and sharing it with other mods.
« Last Edit: April 14, 2008, 05:17:40 pm by WMCoolmon »
-C

 

Offline Vasudan Admiral

  • Member
  • 211
    • Twisted Infinities
Re: Big feature request: Native 'S-Foil' Support (Action Scripting)
Oh....
Code: [Select]
Orientation = orientation
Orientation of subobject or turret base
Value: Subsystem orientation, or null orientation if handle is invalid


Right.
I looked right through the scripting html file before posting that so I wouldn't look like an idiot. Whoops. :\
Get the 2014 Media VPs and report any bugs you find in them to the FSU Mantis so that we may squish them. || Blender to POF model conversion guide
Twisted Infinities

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: Big feature request: Native 'S-Foil' Support (Action Scripting)
Well, it doesn't necessarily mean that you're wrong. It still might not work like the animation code, I'm not altogether familiar with the animation code.

Also, forgot to mention it before, but:
It's also infinitely easier to specify a rotation angle, velocity and acceleration than it is to come up with an equation that will perform the same task. ;)

I had to come up with (and finally understood, thanks to physics) the equations for this in order to do the camera update which I have never gotten around to releasing in any shape or form. What I found in testing was that the equations did work, but converting those angles back into matrices resulted in some odd wobbly movements at certain points, presumably due to some inaccuracy in the calculations. I don't know if this was something specific to the graphics code and if it would carry over into some other application, however, if somebody wants to work on that, I do have those lying around.
-C

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: Big feature request: Native 'S-Foil' Support (Action Scripting)
I don't like it when people say 'this doesn't work' and they don't know for sure, or don't make a bug report. All it does is scare people away from using them, so either nobody uses perfectly functional code, or they don't get fixed because people are discouraged from using them before a bug report gets registered. This has already happened once with the improper/inconsistent scaling of the mouse/graphics functions in scripting.
Well...  i did tell it karajorma and mistakenly assumed the information would propagate.. Besides i didnt see that in anyway critical as we found IMO easier method of returning stuff back to 'SEXP side'.. that is via the SEXP variables.

For some reason i cant even set 'modify-variable' to use script-eval-string if the variable is of string type. Release build of the said buildset fails to run.. debug works though. And apparently script-eval-num does not change the variable but neither does it crash the game. But then again i have never been that good with Fred so the problem can be in there too... I can post these to Mantis if you want me to.
Do not meddle in the affairs of coders for they are soggy and hard to light

  

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Big feature request: Native 'S-Foil' Support (Action Scripting)
i personally wouldn't mind a revamp of the submodel animation system. so far it only supports a hand full of actions and only supports on and off animations that reset themselves after some time. i think bobs original plan was to have more animation triggers and animation types. like linked animations which would couple an animation to a variable. at some point it was possible to add a lua based animation right in a ships table entry which would be auto-applied to every ship of that class, but i dont think that was ever commited. id like to see those features revised and added to the engine. but i have no problem using scripting, as ive solved most of the problems associated with it (namely the ability to store metadata on a ship by ship basis), i just need to bring everything together.

to script animations for every ship would require alot of work and probably my ship meta data system from the freespace rts (to track animation status from ship to ship). to do something simple which requires no metadata, by using a value thats part of the ship object and its children objects (subsystems, ship.physics, etc) , such as desired velocity, shield strength, hit points and so on. take your value that you want to use, crunch some numbers so that it represents the amount of some motion, build a matrix and apply it to an object. as the value changes, the object animates. heres an example:

Code: [Select]
if ship:isValid() then
--set vars for animations and input
--determine the input axes in -1 to 1 scaler format
local rotx = ship.Physics.RotationalVelocityDesired.x / ship.Physics.RotationalVelocityMax.x --yaw
local roty = ship.Physics.RotationalVelocityDesired.y / ship.Physics.RotationalVelocityMax.y --pitch
local rotz = ship.Physics.RotationalVelocityDesired.z / ship.Physics.RotationalVelocityMax.z --roll
local gox = ship.Physics.SideThrust --lateral
local goy = ship.Physics.VerticalThrust --vertical
local goz = ship.Physics.ForwardThrust --longitudinal
local msx, msy = mousejoy() --mouse axes

as you can see i took every axis (including the mouse position), abstracted it down to a -1 to 1 value and stored it in a bunch ov vars. continuing:

Code: [Select]
--control animation
if ship.Class:isValid() then --had to idiot proof this
if ship.Class.Name == "PB Sepulture" then
--get submodels
local psub = ship["stick_pitch"]
local rsub = ship["pilot_stick"]
local rsub2 = ship["copilot_stick"]
local tsub = ship["throttle"]

--yoke pitch
if psub:isValid() then
local Angs = psub.Orientation
Angs.p = rotx * 0.03
psub.Orientation = Angs
end

--yoke roll
if rsub:isValid() then
local Angs = rsub.Orientation
Angs.b = rotz * 2
rsub.Orientation = Angs

if rsub2:isValid() then rsub2.Orientation = Angs end
end

--throttle stick
if tsub:isValid() then
if goz >= 0 then goz = goz * 1.2 else goz = goz / 15 end
local Angs = tsub.Orientation
Angs.p = goz - 1.1
tsub.Orientation = Angs
end
if ship.Class.Name == "some other ship" then
--do the next ships animations
end
end
end

what ive done first is get handles for all the subobjects i wish to animate, in this case some flight controls in the cockpit. then for each i have a few lines of code to handle the animation. basicly all im doing is taking the objects old orientation, modifying it (my editing p,b,h values or by matrix multiply). more complicated animations, like a rotation on an arbitrary axis, would require a better understanding of matrix math.

a crash course in matrix ops for those that need it:
matrices represent the rotation of an object. the reason they are used is because it sort of streamlines the math involved in transformations. they are easy to combine using matrix multiply, the * operator. to apply to vectors you use ori:unrotateVector(vec) and ori:rotateVector(vec), one is essentially the inverse of the other. to apply a matrix to a ship or subobject, you can apply it directly, which would set an absolute orientation in world or model space, respectively. if you want to rotate something relative to how it is currently oriented, get its current matrix from its .orientation, and multiply it by the matrix that represents the orientation you want to add to it.

matrix multiply is how you combine rotations. its important to note that with matrix multiplication that a*b != b*a. so if matrix a stores a 90 degree rotation on the y axis, and matrix b represents a 90 degree rotation on the x axis, and assuming you have a ship in local space. a*b would make a matrix that when applied to the object would rotate it so that it points up and is rolled 90 degrees, while b*a would rotate the object so its pointed to a side and rolled 90 degrees.

fortunately scripting has most of the matrix ops needed pre coded for you, so you dont need to directly concern yourself with how to do it, rather how to use it. you can create a rotation from euler angles (rotations about primary axes in radians), and from a vector (though this doesnt give you any control over roll) about the only thing not in there is arbitrary axis rotation, which could be done with this function:

Code: [Select]
arbrot = function(a, r)
local s = math.sin(r)
local c = math.cos(r)
local t = 1 - c
local m = ba.createOrientation()

m[1] = t * a.x^2 + c
m[2] = t * a.x * a.y + s * a.z
m[3] = t * a.x * a.z - s * a.y

m[4] = t * a.x * a.y - s * a.z
m[5] = t * a.y^2 + c
m[6] = t * a.y * a.z + s * a.x

m[7] = t * a.x * a.z + s * a.y
m[8] = t * a.y * a.z - s * a.x
m[9] = t * a.z^2 + c

return m
end


another way to deal with animations is to interpolate between two orientations. using a:getInterpolated(b, 0.5) would come up with a matrix thats in the middle of a and b, seting the last argument to zero would return a and setting it to 1 would return b. i haven't used this yet but its probably gonna be key to making good animations in lua.
« Last Edit: April 15, 2008, 08:14:08 am by Nuke »
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