FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

_SIO2parent transform?

+2
Jawdy
Tom
6 posters

Page 1 of 2 1, 2  Next

Go down

_SIO2parent transform? Empty _SIO2parent transform?

Post  Tom Mon Mar 23, 2009 5:11 am

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:

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

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  Jawdy Mon Mar 23, 2009 5:17 am

Did you definately select all your objects and "Centre New" on them?
Jawdy
Jawdy

Posts : 65
Join date : 2009-03-17
Location : UK

http://www.gaslightgames.co.uk

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  Tom Mon Mar 23, 2009 5:23 am

Yep.

Tom

Posts : 13
Join date : 2009-03-23

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  sio2interactive Mon Mar 23, 2009 5:43 am

can you post a screenshot?
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  Tom Mon Mar 23, 2009 5:48 am

_SIO2parent transform? Img_0010

Tom

Posts : 13
Join date : 2009-03-23

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  sio2interactive Mon Mar 23, 2009 5:59 am

the pivot point of the wheel should be the same as the car...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  Tom Mon Mar 23, 2009 6:14 am

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.

Tom

Posts : 13
Join date : 2009-03-23

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  williamcheng Sat Sep 19, 2009 4:36 pm

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
Smile

williamcheng

Posts : 8
Join date : 2009-09-19

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  sio2interactive Sat Sep 19, 2009 5:00 pm

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
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  williamcheng Sat Sep 19, 2009 5:50 pm

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...

williamcheng

Posts : 8
Join date : 2009-09-19

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  williamcheng Sat Sep 19, 2009 8:55 pm

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... No

williamcheng

Posts : 8
Join date : 2009-09-19

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  sio2interactive Sun Sep 20, 2009 12:45 am

Check tutorial14...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  Faikus Mon Sep 21, 2009 3:08 am

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:

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

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  williamcheng Tue Sep 22, 2009 10:32 pm

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"

No

williamcheng

Posts : 8
Join date : 2009-09-19

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  williamcheng Tue Sep 22, 2009 10:33 pm

do i have to include any file to support btTransform()?

williamcheng

Posts : 8
Join date : 2009-09-19

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  Faikus Wed Sep 23, 2009 3:07 am

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

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  williamcheng Wed Sep 23, 2009 11:36 am

Hi Faikus,

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

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  Faikus Wed Sep 23, 2009 1:50 pm

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;":

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

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  williamcheng Wed Sep 23, 2009 8:44 pm

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 Sad

Any ideas why?

williamcheng

Posts : 8
Join date : 2009-09-19

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  sio2interactive Thu Sep 24, 2009 1:09 am

Its probably related with the SIO2object->_SIO2transform->loc that is not set in world space coordinate.
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  LuisLee Thu Sep 24, 2009 1:46 am

sio2interactive wrote:Its probably related with the SIO2object->_SIO2transform->loc that is not set in world space coordinate.

_SIO2parent transform? 092410

How do I set? How
The distance between them become shorter that?


Very Happy 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

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  williamcheng Thu Sep 24, 2009 2:18 am

@sio2interactive

i am getting really confused about world coordinates and relative/local coordinates... Crying or Very sad

How to set _SIO2transform->loc to world coordinates? i thought they are by default in world coordinates when we export from blender... No

williamcheng

Posts : 8
Join date : 2009-09-19

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  Faikus Thu Sep 24, 2009 2:48 am

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

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  Faikus Thu Sep 24, 2009 3:06 am

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

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  Faikus Thu Sep 24, 2009 3:18 am

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

Back to top Go down

_SIO2parent transform? Empty Re: _SIO2parent transform?

Post  Sponsored content


Sponsored content


Back to top Go down

Page 1 of 2 1, 2  Next

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum