GetUnit( )
by DIAG · in Torque Game Engine · 06/29/2004 (5:09 am) · 17 replies
Hello,
I have noticed that the getWord function in scripts makes a call to getUnit( ). I would like to use this myself in C++, but it cannot find where it is declared, so as to include the appropriate header file. Can anyone help?
CHeers
I have noticed that the getWord function in scripts makes a call to getUnit( ). I would like to use this myself in C++, but it cannot find where it is declared, so as to include the appropriate header file. Can anyone help?
CHeers
#2
I've been looking at the getUnit() declaration, and it seems like it should work, but whenever I try and use this in my engine-side code, I just get the error that it hasn't been declared. Doing a full search of all the engine source for Torque, it seems the only file that has getUnit is consoleFunctions.cc, so there isn't any library file to load up.
So... how exactly do I make this work so I can do something like the "getWord(string,3)" function in the engine?
Thanks,
-Dave C.
02/02/2005 (2:03 pm)
Did you ever figure this out DIAG (or can anyone else direct me?)?I've been looking at the getUnit() declaration, and it seems like it should work, but whenever I try and use this in my engine-side code, I just get the error that it hasn't been declared. Doing a full search of all the engine source for Torque, it seems the only file that has getUnit is consoleFunctions.cc, so there isn't any library file to load up.
So... how exactly do I make this work so I can do something like the "getWord(string,3)" function in the engine?
Thanks,
-Dave C.
#3
02/02/2005 (9:44 pm)
There's no header for that function; it's mostly for script use. What are you trying to do? It might be a lot easier and faster to just use printf or scanf.
#4
02/03/2005 (6:21 am)
I'm attempting to get and modify the rotation of an object in the engine. I found that I can use object->getTransform() just like in script (or so it would appear) to get the rotation, but then I needed to be able to modify that with something like getWord and setWord. I found that getUnit and setUnit were the engine commands to do that, and.. well... I was hoping to use those to do it like I would in script.
#5
02/03/2005 (6:44 am)
As I mentioned in the other post, the only reason you are "used to" manipulating transforms in script with getWord() is because of the nature of passing variables back and forth from code to scripts. Manipulating transforms as strings is the least efficient, and least capable, way of doing so--you should instead look at all the various ways matrices can be manipulated in code.
#6
Playing around in that direction, it all seems pretty clear... EXCEPT... the rotational transform in the matrix is read as... some other number, which I'm understand is a quad.
Just to clarify, when I click on the object in the world editor, the rotation is this:
0 0 -1 30.0622
But when I get the info from the matrix, the numbers in those positions are:
0.500941 0 0 0.865482
I'm not really sure what is going on here... so, what am I supposed to do if I just want to rotate the object in code? I've looked through a bunch of the other code and it all seems to use the getTransform and setTransform and modifying places in the matrix, which is cool, but... the radian/quad or whatever thing seems a bit odd. What's up with that?
02/03/2005 (7:08 am)
Okay, I understand now. Playing around in that direction, it all seems pretty clear... EXCEPT... the rotational transform in the matrix is read as... some other number, which I'm understand is a quad.
Just to clarify, when I click on the object in the world editor, the rotation is this:
0 0 -1 30.0622
But when I get the info from the matrix, the numbers in those positions are:
0.500941 0 0 0.865482
I'm not really sure what is going on here... so, what am I supposed to do if I just want to rotate the object in code? I've looked through a bunch of the other code and it all seems to use the getTransform and setTransform and modifying places in the matrix, which is cool, but... the radian/quad or whatever thing seems a bit odd. What's up with that?
#7
Just to make it a little more clear what I'm doing, here is the code:
And this is what the console is spitting out:
Got to A.
TransformColumA is: 0.865482 0.500941 0.000000
TransformColumB is: -0.500941 0.865482 0.000000
TransformColumC is: 0.000000 0.000000 1.000000
TransformColumC is: 43.400002 -501.882996 145.000000
TransformColumC is: 0.500941 0.000000 0.000000
TransformColumC is: 0.865482 0.000000 0.000000
Got to B.
That's all well and good.... if I wanted to modify the position. But the only thing I am interested here is the rotation, and that dosen't look anything like the rotation I'm used to...
02/03/2005 (8:06 am)
(Duplicated from this post: www.garagegames.com/mg/forums/result.thread.php?qt=25633)Just to make it a little more clear what I'm doing, here is the code:
ConsoleMethod(StaticShape,ControlledRotation, F32, 3, 3, "()")
{
Con::printf("Got to A.");
// F32 test = argv[2];
MatrixF getObjectRotation;
Point3F transformColumnA;
Point3F transformColumnB;
Point3F transformColumnC;
Point3F transformColumnD;
Point3F transformColumnE;
Point3F transformColumnF;
getObjectRotation = object->getTransform();
getObjectRotation.getColumn(0,&transformColumnA);
getObjectRotation.getColumn(1,&transformColumnB);
getObjectRotation.getColumn(2,&transformColumnC);
getObjectRotation.getColumn(3,&transformColumnD);
getObjectRotation.getColumn(4,&transformColumnE);
getObjectRotation.getColumn(5,&transformColumnF);
object->ControlledRotation(transformColumnA,transformColumnB,transformColumnC,transformColumnD,transformColumnE,transformColumnF);
Con::printf("Got to B.");
}
void StaticShape::ControlledRotation(Point3F transformColumnA, Point3F transformColumnB,Point3F transformColumnC,Point3F transformColumnD,Point3F transformColumnE,Point3F transformColumnF)
{
Con::printf("TransformColumA is: %f %f %f",transformColumnA.x,transformColumnA.y,transformColumnA.z);
Con::printf("TransformColumB is: %f %f %f",transformColumnB.x,transformColumnB.y,transformColumnB.z);
Con::printf("TransformColumC is: %f %f %f",transformColumnC.x,transformColumnC.y,transformColumnC.z);
Con::printf("TransformColumC is: %f %f %f",transformColumnD.x,transformColumnD.y,transformColumnD.z);
Con::printf("TransformColumC is: %f %f %f",transformColumnE.x,transformColumnE.y,transformColumnE.z);
Con::printf("TransformColumC is: %f %f %f",transformColumnF.x,transformColumnF.y,transformColumnF.z);
}And this is what the console is spitting out:
Got to A.
TransformColumA is: 0.865482 0.500941 0.000000
TransformColumB is: -0.500941 0.865482 0.000000
TransformColumC is: 0.000000 0.000000 1.000000
TransformColumC is: 43.400002 -501.882996 145.000000
TransformColumC is: 0.500941 0.000000 0.000000
TransformColumC is: 0.865482 0.000000 0.000000
Got to B.
That's all well and good.... if I wanted to modify the position. But the only thing I am interested here is the rotation, and that dosen't look anything like the rotation I'm used to...
#8
1) Get a book and study up on the three topics.
2) Diligently search the code for examples of what you want to do, and see how they do it. There are a variety of game implementations that deal with just grabbing the rotation of an object for example (and in fact they are implemented in different ways for different objects--one of the down sides to an aggregate project such as TGE).
The big thing to keep in mind however is that when viewed from script (which includes world editor gui's), the 4 values you see for rotations are made to be easily human readible and understandable. When you are in code, the matrix storing the information is not in any way presented to be easily "read" by a human, but is stored for efficiency, performance, and mathematical reasons--which I myself don't quite understand yet!
In other words, it may just be in your best interest to not worry about how the data is stored, but focus on how to use the data. If you really want to understand it, a book on 3-D math, specifically the above topics, would be the way to go.
02/03/2005 (11:57 am)
I'm not an expert on matrix/Axis Angle/Quaternion math myself, but these are basically your two options:1) Get a book and study up on the three topics.
2) Diligently search the code for examples of what you want to do, and see how they do it. There are a variety of game implementations that deal with just grabbing the rotation of an object for example (and in fact they are implemented in different ways for different objects--one of the down sides to an aggregate project such as TGE).
The big thing to keep in mind however is that when viewed from script (which includes world editor gui's), the 4 values you see for rotations are made to be easily human readible and understandable. When you are in code, the matrix storing the information is not in any way presented to be easily "read" by a human, but is stored for efficiency, performance, and mathematical reasons--which I myself don't quite understand yet!
In other words, it may just be in your best interest to not worry about how the data is stored, but focus on how to use the data. If you really want to understand it, a book on 3-D math, specifically the above topics, would be the way to go.
#9
I've actually been studying up on all of those topics lately... got a stack of books, been reading up online and in the books, etc. etc. My problem here is that I've been coding in TorqueScript for awhile now, and am now getting into the engine side of things - which is a tremendous change and very, very hard to do from what I am finding. Even with the information published in the torque documentation, there still are a lot of things that are tough to get without some of the good help that you can only get in the GarageGames forums.
Okay... so, now knowing that the matrix will NOT have the numbers I am looking for, I next need to learn exactly what the numbers are that I am being shown in the matrix (aside from the position) and what it takes to transform these groups of numbers.
So, let me ask this... I understand that the matrix I get back is like this:
A B C
[ D E F ]
H I J
X Y Z
X Y Z I get. What do ABC / DEF / HIJ represent? I mean, I'm sure that it's full of information in those 9 numbers, including the rotation... so if X Y Z is the X Y Z position in the world, what do the rest represent?
02/03/2005 (12:12 pm)
It stores it differently in the matrix than it is displayed in script? OKAY! That is actually a _MASSIVE_ help and means I won't be continuously searching the matrices for the rotational transform! =)I've actually been studying up on all of those topics lately... got a stack of books, been reading up online and in the books, etc. etc. My problem here is that I've been coding in TorqueScript for awhile now, and am now getting into the engine side of things - which is a tremendous change and very, very hard to do from what I am finding. Even with the information published in the torque documentation, there still are a lot of things that are tough to get without some of the good help that you can only get in the GarageGames forums.
Okay... so, now knowing that the matrix will NOT have the numbers I am looking for, I next need to learn exactly what the numbers are that I am being shown in the matrix (aside from the position) and what it takes to transform these groups of numbers.
So, let me ask this... I understand that the matrix I get back is like this:
A B C
[ D E F ]
H I J
X Y Z
X Y Z I get. What do ABC / DEF / HIJ represent? I mean, I'm sure that it's full of information in those 9 numbers, including the rotation... so if X Y Z is the X Y Z position in the world, what do the rest represent?
#10
A search in files on your source code directory will give you a huge amount of examples. For example, based on the assumption that a setTransform() in code probably means that something was done to modify the transform first, you can search for setTransform(), and then look at how it's used (and why) one by one until you start to aggregate a good feel for the various techniques and uses of the transform matrices.
It may not be the most mathematically pure way to implement functionality, but hey, the code is there, and it's good code, so I use it!
02/03/2005 (12:31 pm)
Above my head quite honestly--I have no idea what is actually stored, why, and how it's manipulated within the matrices (ok, so I used to, but that was seriously 17 years ago)--now, I focus on the important techniques on how to use the information. And that comes from looking at existing code within the SDK that does approximately what I am looking for, and then duplicating and experimenting with it.A search in files on your source code directory will give you a huge amount of examples. For example, based on the assumption that a setTransform() in code probably means that something was done to modify the transform first, you can search for setTransform(), and then look at how it's used (and why) one by one until you start to aggregate a good feel for the various techniques and uses of the transform matrices.
It may not be the most mathematically pure way to implement functionality, but hey, the code is there, and it's good code, so I use it!
#11
Problem with this case, I've found millions of examples where the transform of the position is changed - but I can't seem to find anything that transforms the rotation, which is driving me batty since I KNOW that it's done quite frequently.
The best example I have so far found is in item.cc, where it allows the item to rotate. I'm gonna study that for awhile and see if I can just modify that to do what I need.
Thanks for all your help!!
02/03/2005 (12:42 pm)
Yea, I work the same way - find code, and reuse instead of remaking the wheel. =)Problem with this case, I've found millions of examples where the transform of the position is changed - but I can't seem to find anything that transforms the rotation, which is driving me batty since I KNOW that it's done quite frequently.
The best example I have so far found is in item.cc, where it allows the item to rotate. I'm gonna study that for awhile and see if I can just modify that to do what I need.
Thanks for all your help!!
#12
One thing to keep in mind, there are a lot of ways to skin this particular cat, and even more techniques for rotation throughout the code base. I've seen Axis Angle, Quat, Euler, and a lot of other things I really don't understand myself--find one or two, experiment, and see which you like to use!
02/03/2005 (12:50 pm)
The advancedCamera resource does a lot of rotational and positional modification of the camera object, and should give you a good handle on the various techniques as well.One thing to keep in mind, there are a lot of ways to skin this particular cat, and even more techniques for rotation throughout the code base. I've seen Axis Angle, Quat, Euler, and a lot of other things I really don't understand myself--find one or two, experiment, and see which you like to use!
#13
The item class is probably a good place to start. Looks like it just explicitly sets the rotation by passing in euler angles.
02/03/2005 (12:53 pm)
The transform Matrix is a composite of the Rotation, Translation, and scale Matrices multiplied together in that order. If you want to get the rotation in Axis-Angle form the AngAxisF class has a constructor that takes a transform Matrix as an argument. So you could do the following:AngAxisF aaf( getTransform() ); aaf.axis ( [0] for x, [1] for y, [2] for z ) aaf.angle
The item class is probably a good place to start. Looks like it just explicitly sets the rotation by passing in euler angles.
#14
Owen: AngAxisF? Sounds interesting... I'll look into it now... thanks a lot!!
I spent some time looking through the Item class, but it seemed a bit crazy, and got me confused. I was trying to merge it with StaticShape, but it had lots of methods that StaticShape didn't even have... and the more I tried to merge, the more errors I received, so I finally just backed out and realized it was a very bad move, and I just need to write this myself.
Been at this for almost 1.3 weeks straight now... I'm gonna get it soon, I know it!
02/03/2005 (4:05 pm)
Stephen: Please pardon my n00bness, but I looked through the advancedCamera resource (have been for about a week now), and I can't find anything in there that actually rotates the object. I found one thing that gets the rotation based on another object... but even then, I couldn't find where it was actually getting and setting the rotational numbers.Owen: AngAxisF? Sounds interesting... I'll look into it now... thanks a lot!!
I spent some time looking through the Item class, but it seemed a bit crazy, and got me confused. I was trying to merge it with StaticShape, but it had lots of methods that StaticShape didn't even have... and the more I tried to merge, the more errors I received, so I finally just backed out and realized it was a very bad move, and I just need to write this myself.
Been at this for almost 1.3 weeks straight now... I'm gonna get it soon, I know it!
#15
02/03/2005 (4:31 pm)
@Orwen: You are the MAN!!! That is EXACTLY what I have been looking for, thank you _SO_ much!!!! AngAxisF returned the crucial numbers that I needed to make a rotation work... _THANK YOU_!!!! Now I can finally get to making my object rotate!!!
#16
Here is the solution:
const char* getWord(const char* data, U32 index)
{
return Con::getReturnBuffer( StringUnit::getUnit(data,
index, "\t\n") );
}
Just thought it might be useful for someone.
05/22/2010 (5:22 pm)
I know this is a pretty old thread, but I also wanted to use the getWord function in C++. The solution is very simple, using getUnit(), which is defined in consoleFunctions.cc.Here is the solution:
const char* getWord(const char* data, U32 index)
{
return Con::getReturnBuffer( StringUnit::getUnit(data,
index, "\t\n") );
}
Just thought it might be useful for someone.
#17
05/22/2010 (11:12 pm)
A thread is never old if it can be solved. ;)
Associate Kevin Ryan
Top Meadow Inc.