_SIO2parent transform?
+2
Jawdy
Tom
6 posters
Page 1 of 2 • 1, 2
_SIO2parent transform?
Hi
I have a scene in blender with a car, and 4 wheels separate. I want to be able to have the wheels automatically move with the car, and then be able to rotate the wheels and turn the front wheels etc.
In my loading function I did something like this:
Now the wheels follow the car like I want. The problem is that their Y axis is wrong, so they float around above the car. I can't for the life of me imagine what would make them do that. In the blend file they appear on the correct spot in relation to the car. Do I manually have to set the position in relation to the car in code after setting the parent?
I have a scene in blender with a car, and 4 wheels separate. I want to be able to have the wheels automatically move with the car, and then be able to rotate the wheels and turn the front wheels etc.
In my loading function I did something like this:
- Code:
wheel_fl->_SIO2transform->_SIO2parent = car->_SIO2transform;
wheel_fr->_SIO2transform->_SIO2parent = car->_SIO2transform;
wheel_rl->_SIO2transform->_SIO2parent = car->_SIO2transform;
wheel_rr->_SIO2transform->_SIO2parent = car->_SIO2transform;
Now the wheels follow the car like I want. The problem is that their Y axis is wrong, so they float around above the car. I can't for the life of me imagine what would make them do that. In the blend file they appear on the correct spot in relation to the car. Do I manually have to set the position in relation to the car in code after setting the parent?
Last edited by Tom on Mon Mar 23, 2009 5:23 am; edited 1 time in total
Tom- Posts : 13
Join date : 2009-03-23
Re: _SIO2parent transform?
How does the center differ from the pivot point? I set the center of the wheels to the cars center and it didn't seem to change anything.
Thanks for the help.
Thanks for the help.
Tom- Posts : 13
Join date : 2009-03-23
Re: _SIO2parent transform?
Hello,
I am also trying to do the same thing. But when i set wheel->_SIO2transform->_SOI2parent = car->_SIO2transform my wheel does not get rendered!
What type of bodies are the chassis and wheels? (rigidbody, dynamic..)?
What should be their collision shapes?
I also want to rotate my wheels..Should i simply rotate my wheels using _Sio2transform->rot->y? or should i apply rolling physics? How to apply rolling physics?
Sorry for my bad english
I am also trying to do the same thing. But when i set wheel->_SIO2transform->_SOI2parent = car->_SIO2transform my wheel does not get rendered!
What type of bodies are the chassis and wheels? (rigidbody, dynamic..)?
What should be their collision shapes?
I also want to rotate my wheels..Should i simply rotate my wheels using _Sio2transform->rot->y? or should i apply rolling physics? How to apply rolling physics?
Sorry for my bad english
williamcheng- Posts : 8
Join date : 2009-09-19
Re: _SIO2parent transform?
I am also trying to do the same thing. But when i set wheel->_SIO2transform->_SOI2parent = car->_SIO2transform my wheel does not get rendered!
>> You need to assign the world space position to the _SIO2transform->loc, simply add the parent loc + the wheel offset in parent world space
>> You need to assign the world space position to the _SIO2transform->loc, simply add the parent loc + the wheel offset in parent world space
Re: _SIO2parent transform?
hi sio2interactive,
thank you for replying.
i did not understand how to do. how to assign the world space position to the _SIO2transform->loc? how to add the parent loc + the wheel offset in parent world space? sorry for the trouble but i did not understand...
thank you for replying.
i did not understand how to do. how to assign the world space position to the _SIO2transform->loc? how to add the parent loc + the wheel offset in parent world space? sorry for the trouble but i did not understand...
williamcheng- Posts : 8
Join date : 2009-09-19
Re: _SIO2parent transform?
hi,
i have searched the forum and i think sio2Project/sio2UnProject can help me. can anyone tell me how to use these functions to get it work...
i have searched the forum and i think sio2Project/sio2UnProject can help me. can anyone tell me how to use these functions to get it work...
williamcheng- Posts : 8
Join date : 2009-09-19
Re: _SIO2parent transform?
I had the same problem: my objects were arranged in Blender in the same position relative to each other in which they are supposed to be rendered on the iPhone. I wanted one of the objects to be the parent of the others, so I only needed to move that object in order to move the entire collection of objects. If you export the scene from Blender and only parent the child objects to the parent object in code without changing the child transform matrices, the arrangement will not render correctly, because the child matrices, which represented the child's absolute position, are now interpreted as relative to the parent transform. So, if in Blender your parent is at x=10 and the child at x=12, parenting will cause the child to be rendered at x=22. To fix that, I wrote a helper function:
You can use this to parent one object to another, if the transform matrices of both are in absolute world coordinates, as they are when you export the scene from Blender.
- Code:
void makeChildOf(SIO2transform* child, SIO2transform* parent)
{
btTransform parentTransform, childTransform;
parentTransform.setFromOpenGLMatrix( parent->mat );
childTransform.setFromOpenGLMatrix( child->mat );
if (child->_SIO2parent) {
btTransform oldParentTransform;
oldParentTransform.setFromOpenGLMatrix((( SIO2transform * )child->_SIO2parent)->mat);
childTransform = childTransform * oldParentTransform;
}
btTransform inParentCoord = parentTransform.inverse() * childTransform;
inParentCoord.getOpenGLMatrix(child->mat);
child->_SIO2parent = parent;
}
You can use this to parent one object to another, if the transform matrices of both are in absolute world coordinates, as they are when you export the scene from Blender.
Faikus- Posts : 23
Join date : 2009-05-26
Location : Berlin
Re: _SIO2parent transform?
Hi Faikus,
Thank you for the reply. But when i run this code i get an error at the first line of the makeChildOf() function...
It shows this error message "Stopped at breakpoint1"
Thank you for the reply. But when i run this code i get an error at the first line of the makeChildOf() function...
It shows this error message "Stopped at breakpoint1"
williamcheng- Posts : 8
Join date : 2009-09-19
Re: _SIO2parent transform?
do i have to include any file to support btTransform()?
williamcheng- Posts : 8
Join date : 2009-09-19
Re: _SIO2parent transform?
Yes, the code uses the Bullet class btTransfrom, so you need to add this line to the beginning of the file:
- Code:
#include <bullet/btTransform.h>
Faikus- Posts : 23
Join date : 2009-05-26
Location : Berlin
Re: _SIO2parent transform?
Hi Faikus,
Still having the same problem...i included the file using this code
Can you send an example template.mm file which uses that function?
Still having the same problem...i included the file using this code
- Code:
#include "../src/bullet/btTransform.h"
Can you send an example template.mm file which uses that function?
williamcheng- Posts : 8
Join date : 2009-09-19
Re: _SIO2parent transform?
Plonk the makeChildOf function into template.mm of tutorial09 above the templateRender function and paste the following code into the templateRender function below the line "sio2->_SIO2window->fps = 30;":
Make sure it compiles without warnings.
- Code:
makeChildOf((( SIO2object * )sio2ResourceGet( sio2->_SIO2resource, SIO2_OBJECT, "object/peacock"))->_SIO2transform,
(( SIO2object * )sio2ResourceGet( sio2->_SIO2resource, SIO2_OBJECT, "object/meadow" ))->_SIO2transform);
Make sure it compiles without warnings.
Faikus- Posts : 23
Join date : 2009-05-26
Location : Berlin
Re: _SIO2parent transform?
Thanks Faikus,
I put a breakpoint by mistake and that was causing all the trouble. I tested your code in tutorial 09 works fine but the object disappears after the player travels some distance.
When i run it in my code the wheels dont get rendered at all. After the player travels some distance the wheels appear and then disappear again
Any ideas why?
I put a breakpoint by mistake and that was causing all the trouble. I tested your code in tutorial 09 works fine but the object disappears after the player travels some distance.
When i run it in my code the wheels dont get rendered at all. After the player travels some distance the wheels appear and then disappear again
Any ideas why?
williamcheng- Posts : 8
Join date : 2009-09-19
Re: _SIO2parent transform?
Its probably related with the SIO2object->_SIO2transform->loc that is not set in world space coordinate.
Re: _SIO2parent transform?
sio2interactive wrote:Its probably related with the SIO2object->_SIO2transform->loc that is not set in world space coordinate.
How do I set? How
The distance between them become shorter that?
thank you !
- Code:
SIO2object *m_Cylinder01,*m_pCylinder;
m_pCylinder = ( SIO2object * )sio2ResourceGet( sio2->_SIO2resource,
SIO2_OBJECT,
"object/Cylinder" );
m_Cylinder01 = ( SIO2object * )sio2ResourceGet( sio2->_SIO2resource,
SIO2_OBJECT,
"object/Cylinder.001" );
m_Cylinder01->_SIO2transform->_SIO2parent = m_pCylinder->_SIO2transform;
sio2TransformBindMatrix(m_Cylinder01->_SIO2transform);
LuisLee- Posts : 85
Join date : 2009-04-26
Age : 37
Re: _SIO2parent transform?
@sio2interactive
i am getting really confused about world coordinates and relative/local coordinates...
How to set _SIO2transform->loc to world coordinates? i thought they are by default in world coordinates when we export from blender...
i am getting really confused about world coordinates and relative/local coordinates...
How to set _SIO2transform->loc to world coordinates? i thought they are by default in world coordinates when we export from blender...
williamcheng- Posts : 8
Join date : 2009-09-19
Re: _SIO2parent transform?
The disappearing of the child objects is probably due to culling: culling works on the transform->loc vector and does not take parenting into account. Try uncommenting sio2ResourceCull. If the wheels appear and move correctly now, culling is the only problem. What I did in my code is to manually set ->dst of the children after culling to 1 in order to uncull them.
Faikus- Posts : 23
Join date : 2009-05-26
Location : Berlin
Re: _SIO2parent transform?
Now I see this is probably what Rom meant: the child needs to keep its position saved in ->mat relative to its parent for the child to be rendered in the correct position, but it also needs to keep the position saved in ->loc in absolute coordinates for the culling to work correctly.
Faikus- Posts : 23
Join date : 2009-05-26
Location : Berlin
Re: _SIO2parent transform?
BTW, are your wheels physics objects? As far as I can tell, the parenting mechanism does not work if the children are dynamic physic actors.
Faikus- Posts : 23
Join date : 2009-05-26
Location : Berlin
Page 1 of 2 • 1, 2
Similar topics
» texture transform
» How to get Transform from Physic Object?
» 1.4 transform and linear velocity bug
» Simple Transform Animation System
» How to get Transform from Physic Object?
» 1.4 transform and linear velocity bug
» Simple Transform Animation System
Permissions in this forum:
You cannot reply to topics in this forum