General Category > ASL Scripts

RIBRobin

<< < (2/2)

Steve:
Good work Raxx.  (But camera "ears" are stealing something I have added for the next release!)

Francesco:
Very good idea Raxx, wish you good time coding it - and by the way, there is always "a better way", so, as long as the program does the work, I wouldn't mind about getting it earlier or later, and neither I would mind about it being the "neatest" or the "hardest crucher" ;)

The model is great!

Raxx:
Cool Steve, looks like we're on the same page ;) Nah, it just means I'll have to adjust my "ears" to fit yours exactly once you release it!

Francesco, thanks :) I know there's a better way and I'm stuck on a problem, perhaps some of you math/3d coordinate geniuses could help me out!

The problem is this: Apparently how the renderman spec works is that instead of moving and rotating the camera around the coordinate system, the entire coordinate system moves and rotates around the camera.

So I need help reverse calculating the camera's position and orientation and instead applying it to the 3D coordinate system. I've been looking up math formulas online but the stuff is just flying right over my head and I have yet to find something with all factors tied in...any pointers would be a great help.

If you guys are interested, here's some sample code to play with if you have ideas on how to turn it into the right equations and such:


--- Code: ---shape $shape, $Cameras[0];
quaternion $orientation;
point2 $uv;
point3 $location, $CamRot;
int $width, $height;
float $FOV, $nearClip, $farClip;

/* Objects were sorted out beforehand and */
/* this chunk of code deals with the camera */

if ($Cameras.size == 1)
{
$shape = $Cameras.pop();

/* Since I couldn't read parameters from parametric shapes, */
/* I made the shape embed the data into the uv coords, and  */
/* it gets read by the export script                        */

/* Get meshdata and read the UV coords as parameters*/
$mdata = $shape.GetMeshData();
$uv = $mdata.GetTexCoord(0);
$width = $uv.x;
$height = $uv.y;
$uv = $mdata.GetTexCoord(1);
$FOV = $uv.x;
$nearClip = $uv.y;
$uv = $mdata.GetTexCoord(2);
$farClip = $uv.x;

/* Our camera's location and orientation */
$location = $shape.loc;
$orientation = $shape.orientation;

/* Code to convert the rotation quaternion into euler */
/* Special thanks to Leslie's post at                 */
/* http://www.anim8or.com/ubb/Forum1/HTML/014922.html */
$CamRot = (-atan2(2*$orientation.x*$orientation.w-2*$orientation.y*$orientation.z , 1 - 2*$orientation.x*$orientation.x - 2*$orientation.z*$orientation.z),
-atan2(2*$orientation.y*$orientation.w-2*$orientation.x*$orientation.z , 1 - 2*$orientation.y*$orientation.y - 2*$orientation.z*$orientation.z),
-asin(2*($orientation.x*$orientation.y + $orientation.z*$orientation.w)));

/* Convert from radians to degrees */
$CamRot = ($CamRot.x*(180/PI), $CamRot.y*(180/PI), $CamRot.z*(180/PI));
}

--- End code ---
So pretty much the main things you have to work with is the point3 $location which is the x,y,z coordinates of the camera's origin, and the point3 $CamRot which is the x,y,z rotation for the camera. So now we have to pretend that the camera is the one staying still and instead the entire world around the camera is moving and rotating around it. Of course if it's easier then the quaternions can be worked on before being converted to eulers.

Note that all other shapes already have their relative offsets and rotations applied to them (via float4x4 transform matrix).

The way the camera/coordinate system in .rib files is written out is:

--- Code: ---Translate X Y Z

--- End code ---
The coordinate system moves to that position away from the camera


--- Code: ---Rotate [Angle] X Y Z

--- End code ---
I can't really tell if this is equal to an axis angle system or just eulers. Put in the angle it rotated on an axis, and set 1 for the axis it represents and 0 for the others. So if rotating the entire world 45 degrees on the X-axis, you do "Rotate 45 1 0 0"

Any hints, links or just plain solving would be greatly appreciated, and of course I'll give you credit in the script like I'm doing for Leslie :)

Francesco:
Unfortunately I'm stuck on the inverse problem (converting from eulers to quaternion) for my BVH->AN8 conversion, and being that I'm not on firm ground with quaternions, I could really help to mess things up instead ;)

Let's hope on a tip falling from higher floors ;)

Francesco:
Wait, I think I mistaken your problem.

If I got it right, you already have cam's orientation and position worked out, correct? Now the thing you want to do is to calculate the inverse orientation and offset of the entire scene (if I got it right once again).

I met a similar problem while working on the magnet scripts, and I ended up with this code (snipping another post of mine):

quaternion $mag_q, $clay_q;
$mag_q = $magnet.orientation;
$clay_q = $clay.orientation;

float4x4 $mag_rotmat, $clay_rotmat;
$mag_rotmat = toFloat4x4($mag_q);
$clay_rotmat = toFloat4x4($clay_q);

/* invert orientation quaternion for building inverse transformation */
$mag_q = ( -$mag_q.x, -$mag_q.y, -$mag_q.z, $mag_q.w);
$clay_q = ( -$clay_q.x, -$clay_q.y, -$clay_q.z, $clay_q.w);

float4x4 $mag_inv_rotmat, $clay_inv_rotmat;
$mag_inv_rotmat = toFloat4x4($mag_q);
$clay_inv_rotmat = toFloat4x4($clay_q);



If you want to, you can change a simple point go back and forth on the two systems using code like this:

/* translate clay point to magnet's coordinates */
$clay_p = $clay_rotmat.Project($clay_p) + $clay_l - $mag_l;
$clay_p = $mag_inv_rotmat.Project($clay_p);

...and back:
/* translate back clay point to clay's coordinates */
$clay_p = $mag_rotmat.Project($clay_p) - $clay_l + $mag_l;
$clay_p = $clay_inv_rotmat.Project($clay_p);


But if your problem involves changing the orientation quaternion of each object, then I think this link could help you more than me:
http://www.flipcode.com/documents/matrfaq.html

I did not face nor dig this passage in particular, but I think it's about multiplicating quaternions together... have a look and good continuation.

Navigation

[0] Message Index

[*] Previous page

Go to full version