Toribash
There is an error in the part that searches for the player and the bodypart int the .tbm file. It's fixed in this one.
Attached Files
get_body_flag.lua (1.6 KB, 7 views)
Last edited by psycore; Dec 8, 2011 at 03:36 AM. Reason: New error. Must have been drunk or something oO
Signature temporarily out of order.
Getting joint rotation
EDIT: Sry, i'm an idiot. This message should be in this thread.

Is there any way to get joint rotation among each other better than some magic manipulations with body_info.rot or counting them from joint world coods?

I'm just trying to do .rpl - .bvh converter, and made basic script, that saves replays as array of POS data of every frame. But .bvh uses only rotation of joints, so this script is completely unuseful.

I see only two ways how to get joint rotation:
1. Just subtract world angles of joint, for example, rotation of elbow among shoulder would be something like rot.elbow=elbow.y - shoulder.y, it cannot be rotated any other angle, so it should be simple.
The problem with it is that i dont understand, how body_info.rot works. Only one match in google was this thread with some strange code with many glitches.
2. Calculate rotation thru arcsin. For example, if x,y,z=elbow[x,y,z]-shoulder[x,y,z], then rot.z=arcsin(y/((x^2+y^2)^.5)). The only problem is too much operations, and, as a consequence, low performance.

Any ideas how to do it?
Last edited by rfxDarth; Jan 4, 2012 at 07:47 AM.
HAMPA SUX!
URL removed ~SF
The body rotation just tells you how the bodypart is rotated around its center, not around its joint.
If what you wrote in 2. already has to much operations I don't see much you can do. I'm not sure how the "^" operator works but it may be faster if you just write x*x instead of x^2.
I don't quite get which angle you're trying to get. I made a little sketch and it doesn't seem to make any sense:

I assume that you want the angle between biceps and triceps to measure how far the elbow is rotated. To get that you'll need far more operations than those you wrote.

Are you calculating the coordinates while playing the replay? If yes then I'd reccomend calculating them first, saving them into an array and the use the saved values.
Signature temporarily out of order.
Originally Posted by psycore View Post
The body rotation just tells you how the bodypart is rotated around its center, not around its joint.

but it should be equal to joint rotation, isn't it?
Originally Posted by psycore View Post
If what you wrote in 2. already has to much operations I don't see much you can do. I'm not sure how the "^" operator works but it may be faster if you just write x*x instead of x^2.
I don't quite get which angle you're trying to get. I made a little sketch and it doesn't seem to make any sense:

I assume that you want the angle between biceps and triceps to measure how far the elbow is rotated. To get that you'll need far more operations than those you wrote.

Yes, it should be calculated for every axis. The problem is it's 5*3*40 operations per frame. And yeah, that should some more 'magic' operations, that would make only one axis rotation from three of them. I'm not sure how it works.

Originally Posted by psycore View Post
Are you calculating the coordinates while playing the replay? If yes then I'd reccomend calculating them first, saving them into an array and the use the saved values.

No, during replay i only save world postitions of joints. Even with it, i got some frame-skipping problems. Data is ok, because it freezes every frame, but i dont know, how to remove gap between freeze and unfreeze, cuz threre's no "shift+space" command.
HAMPA SUX!
URL removed ~SF
Sorry, took me a while to figure some stuff out.
Originally Posted by rfxDarth View Post
but it should be equal to joint rotation, isn't it?

It's possible that we're not speaking of the same thing. With joint rotation I meant the angle between the two bodyparts conected by the joint. If that's what you meant, too, then joint rotation is not equal to body rotation. Imagine you hold your elbow but raise your shoulder. The angle between biceps and tricepts (the joint angle of the elbow) did not change but the triceps rotated.

But if you wanted to know how far you have to rotate the original (unrotated) bodypart to get the current rotation, this might help:
"Lua code:
local bpRot = get_body_info(player, bp).rot
local x = math.atan2(-bpRot.r6, bpRot.r10)
local y = math.asin(bpRot.r2)
local z = math.atan2(-bpRot.r1, bpRot.r0)

At least this is what I got after some time of thinking. I checked it with the draw_box() command and it seems that it has the wrong sign. I don't know if I made a mistake in my calculations or draw_box() rotates objects the wrong way round. Just check it.


Originally Posted by rfxDarth View Post
cuz threre's no "shift+space" command.

run_frames(1) is like shift+space.
Signature temporarily out of order.
Yes, I know that this is a double post but there are several reasons why I made one:
My last post was over one week ago.
It was a response to someone and has nothing to do with this post.
Editing the last post totally screwd up the BB code. I don't know why but using [ lang ] or [ code ] tags again totally messed up the preview.

So I hope you can forgive me. No to the actual problem (sorry that it's that long. It's a bit complex so I have to explain quite a bit):


e: Since I'm not sure if a double post in this case would be allowed I just edited my last post.

I have a problem with a piece of lua code that is supposed to get certain colors from the item.dat file. Further down there is a simplyfied version of it.
It has an array called "colors" which has the form color[colorID] = colorinfo.
Becaues there are many different "colortypes" (relax color, force color, ...) I decided to make an array looking like this: colortype[keyword] = pos
"keyword" is one of "body, relax, force" and stands for the jointcolors during replays, relax color and force color.
"pos" gives the index of the colorID in the item.dat file.

The function getN(str, n) gets the nth number in the string str. This is used to get the colorID from the ITEM line.

Finally the function getColor(cType, itemLine) does the real work. It takes one of "body", "relax" and "force" as cType and the line starting with "ITEM" from item.dat as itemLine to return the color infos of the requested colortype.
In code this means it simply returns
Lua code:
colors[getNumber(itemLine, colortype[cType:lower()])]
.
It first looks the position of the requested colortype up (colortype[ctype:lower()]; the :lower() is just to avoid problems with case sensitivity), then it gets the colorID at that position from itemLine (getNumber(...)) and finally it returns the colorinfo of the color with that ID.

Now the only problem is ... it doesn't work.
Now before further explaining, here's the code:
Lua code:
local colortype = { body = 2,  relax = 3, force = 4 }
local colors = { "color1", "color2", "color3", "color4", "color5" }

local function getNumber(str, n)
local getN = str:gfind("%d+")
for i=1, n-1 do getN() end
return getN()
end

local function getColor(cType, itemLine)
echo("colors["..getNumber(itemLine, colortype[cType:lower()]).."]")
echo(colors[getNumber(itemLine, colortype[cType:lower()])] or "nil")
echo("(hardcoded) colors[5]: "..colors[5])
echo("end getColor()")
return colors[getNumber(itemLine, colortype[cType:lower()])]
end
echo("result: "..(getColor("relax", "ITEM 0; 3 5 2 33 and so on") or "nil"))


As you can see there are some control outputs. The fun part is, the first output in getColor() is "colors[5]". Everything seems to work fine. But then the next output which should be the result is nil. So I thought maybe there is a scoping error I didn't think of, so I checked it by simply echoing colors[5] without calculating the 5. Result: it works. Perfectly. So getting the colorID works, putting out the colorinfo of a hardcoded colorID works but putting out the colorinfo of a calculated colorID doesn't work. And I just can't see why. My last idea was that it is some kind of stack problem so I changed Lua code:
return colors[ getNumber(itemLine, colortype[cType:lower()]]

to
Lua code:
local n = getNumber(itemLine, colortype[cType:lower()])
echo("n: "..n)
return colors[n]

result:
n is 5
colors[n] is nil
Seriously, wtf?
Signature temporarily out of order.
I think the problem may be that while you use %d in the pattern, it still returns a string and not a number, so it's checking colors["5"] not colors[5]

So if you change your getNumber function to:

Lua code:
local function getNumber(str, n)     
local getN = str:gfind("%d+")
for i=1, n-1 do getN() end
return tonumber(getN())
end


A good way of debugging values in dynamic languages is to also throw in a type check, say:

Lua code:
function PrintCheckVar(v)
echo(string.format("CHECK [Type %q] [Value %q]", type(v), v))
end

StringOrNumber = "50.34"
PrintCheckVar(StringOrNumber)
Last edited by Blam; Jan 15, 2012 at 10:09 PM.
:D
Damn. Somehow I expected Lua to convert between strings to numbers as usual. I'm just not used to strings as array keys.
Thanks for the help.
Signature temporarily out of order.
How do i make that lua files.


Lua




See this is the Uke replayer file.

But i don't know how to run this.
Last edited by sir; Jan 21, 2012 at 11:24 PM.
All the wrong I've done the Lord still keep on blessin' me
There's a Lua FAQ for a reason.

Follow these steps:

Save under toribash/data/scripts. For example as "uke_replayer.lua". Then go in singleplayer and type "/ls uke_replayer.lua".
Signature temporarily out of order.