Attached objects?

View previous topic View next topic Go down

Attached objects?

Post  iphoniac on Tue Mar 03, 2009 6:50 am

I think perhaps this have been answered before but I donīt find it.

Can I attach an object to another (I guess using blender) so both are always together.

Imagine a light attached to a lantern object so as you move the lantern, the light also moves.

Cheers.

iphoniac

Posts : 62
Join date : 2008-12-11

View user profile http://thecaveaniphonegame.blogspot.com/

Back to top Go down

Re: Attached objects?

Post  sio2interactive on Tue Mar 03, 2009 7:09 am

_SIO2transform->parent

_________________
SIO2 Interactive
Free Open Source 3D Game Engine for iPhone and iPod Touch
http://sio2interactive.com
avatar
sio2interactive

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

View user profile http://sio2interactive.com

Back to top Go down

Re: Attached objects?

Post  iphoniac on Tue Mar 03, 2009 7:58 am

arg! And what about in 1.3.1? or another way, can I attach a light to an object in Blender?

iphoniac

Posts : 62
Join date : 2008-12-11

View user profile http://thecaveaniphonegame.blogspot.com/

Back to top Go down

Re: Attached objects?

Post  sio2interactive on Tue Mar 03, 2009 3:31 pm

only in code... I think its time you upgrade Wink

_________________
SIO2 Interactive
Free Open Source 3D Game Engine for iPhone and iPod Touch
http://sio2interactive.com
avatar
sio2interactive

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

View user profile http://sio2interactive.com

Back to top Go down

Re: Attached objects?

Post  iphoniac on Wed Mar 04, 2009 1:10 am

I know I know. I want to to update but Iīm still having this problem.

iphoniac

Posts : 62
Join date : 2008-12-11

View user profile http://thecaveaniphonegame.blogspot.com/

Back to top Go down

Re: Attached objects?

Post  sio2interactive on Wed Mar 04, 2009 1:22 am

Ok long story short when you update from 1.3.1 to 1.3.2 and +, independent pos, rot, scl have been replaced by one struct SIO2transform, for camera the struct also contain dir, and tar have been removed as it is not needed.

Dir = Normalize( Target - Position )

Camera does not have rotation, no need for it... just calculate the direction vector and the camera will render in that direction is that simple... you can always calculate it using something like that:

Code:



   hyp_a = hypotf( dir->x, dir->y );
   hyp_b = hypotf( hyp_a, dir->z );

   rot->x = asinf( dir->z / hyp_b ) * SIO2_RAD_TO_DEG;
   rot->z = asinf( dir->x / hyp_a ) * SIO2_RAD_TO_DEG;

   if( dir->y < 0.0f )
   { rot->z += 180.0f; }
   else
   { rot->z = 360.0f - rot->z; }

   rot->z += 90.0f;

   rot->z = sio2RoundAngle( rot->z );




All BindMatrix operation are now passing by sio2TransformBindMatrix in order to have everything unified as 1 struct that can be used by everything and also give you access to parent child matrices with the _SIO2transform->parent handle.

SIO2transform can be used 2 ways sio2TransformRender, that will use the precalculated matrix by a previous sio2TransformBindMatrix or sio2TransformApply that will use a good old glTranslate, glRotate and glScale sequence, the push and pop of the matrix is directly used by the different struct such as camera or object so you don't have to worry about it.

A black screen is usually the result when:

1. You didn't re-export your scene using the latest exporter.

2. You didn't calculate the right dir of the camera or didn't normalize it.

3. If you point directly the camera down the Z axis negating the rotation matrix column. If you want to do that, like a top view game:

- Point the camera down the positive Y axis

- Push the matrix before rendering your resource and rotate it 90 on the X axis then update the camera frustum then render the scene.

4. That's basically it...

_________________
SIO2 Interactive
Free Open Source 3D Game Engine for iPhone and iPod Touch
http://sio2interactive.com
avatar
sio2interactive

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

View user profile http://sio2interactive.com

Back to top Go down

Re: Attached objects?

Post  iphoniac on Wed Mar 04, 2009 5:27 am

1. You didn't re-export your scene using the latest exporter.

I did. This is not the problem.

2. You didn't calculate the right dir of the camera or didn't normalize it.

Can you explain it a little more?
This is my code:
Code:
glMatrixMode( GL_MODELVIEW );
  glLoadIdentity();
  sio2WindowEnterLandscape3D();
  {
      sio2CameraUpdateListener( sio2->_SIO2camera );
      sio2CameraRender( sio2->_SIO2camera );
     
     
      if( tap_select )
      {
        .
        .
        .
      }
     
     
     
      if (selection) {
        .
        .
        .       
      }
     
      glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
     
      sio2CameraUpdateFrustum( sio2->_SIO2camera );
     
      sio2ResourceCull( sio2->_SIO2resource,
                  sio2->_SIO2camera );       
     
     
      sio2ResourceRender( sio2->_SIO2resource,
                    sio2->_SIO2window,
                    sio2->_SIO2camera ,
                    SIO2_RENDER_SOLID_OBJECT | SIO2_RENDER_CLIPPED_OBJECT | SIO2_RENDER_ALPHA_OBJECT );
  }
  sio2WindowLeaveLandscape3D();

I update the camera perspective just after getting it:

Code:
sio2->_SIO2camera = ( SIO2camera * )sio2ResourceGet( sio2->_SIO2resource,
                                            SIO2_CAMERA,
                                            "camera/IntroCamera" );
     
sio2CameraSetPerspective( sio2->_SIO2camera, sio2->_SIO2window );

How do I calculate the right dir and normalize it?

3. If you point directly the camera down the Z axis negating the rotation matrix column.

Not the case.

Cheers.

iphoniac

Posts : 62
Join date : 2008-12-11

View user profile http://thecaveaniphonegame.blogspot.com/

Back to top Go down

Re: Attached objects?

Post  sio2interactive on Wed Mar 04, 2009 5:47 am

This code point straight to my player object wherever this object is:


Code:


        // tmp is whatever distance or position offset I want...
   sio2Vec3Add( _SIO2player->player->_SIO2transform->loc,
             &tmp,
             sio2->_SIO2camera->_SIO2transform->loc );   


   sio2Vec3Diff( _SIO2player->player->_SIO2transform->loc,
              sio2->_SIO2camera->_SIO2transform->loc,
              sio2->_SIO2camera->_SIO2transform->dir );

   
   sio2Normalize( sio2->_SIO2camera->_SIO2transform->dir,
              sio2->_SIO2camera->_SIO2transform->dir );


_________________
SIO2 Interactive
Free Open Source 3D Game Engine for iPhone and iPod Touch
http://sio2interactive.com
avatar
sio2interactive

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

View user profile http://sio2interactive.com

Back to top Go down

Re: Attached objects?

Post  meteors on Wed Mar 04, 2009 6:55 am

Thanks sio2!

-j
avatar
meteors

Posts : 241
Join date : 2008-11-08
Location : Sunny Florida

View user profile

Back to top Go down

Re: Attached objects?

Post  iphoniac on Wed Mar 04, 2009 8:43 am

Not working Sad

Iīve pasted just before updating camera frustrum:

Code:
vec3 tmp;
      tmp.x = 10.0f;
      tmp.y = 10.0f;
      tmp.z = 10.0f;
      
      SIO2object *_Object = ( SIO2object * )sio2ResourceGet( sio2->_SIO2resource, SIO2_OBJECT, "object/Skydome" );
      
        // tmp is whatever distance or position offset I want...
      sio2Vec3Add( _Object->_SIO2transform->loc,
               &tmp,
               sio2->_SIO2camera->_SIO2transform->loc ); 
      
      
      sio2Vec3Diff( _Object->_SIO2transform->loc,
                sio2->_SIO2camera->_SIO2transform->loc,
                sio2->_SIO2camera->_SIO2transform->dir );
      
      
      sio2Normalize( sio2->_SIO2camera->_SIO2transform->dir,
                 sio2->_SIO2camera->_SIO2transform->dir );
      
      
      glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
      
      sio2CameraUpdateFrustum( sio2->_SIO2camera );
      
      sio2ResourceCull( sio2->_SIO2resource,
                   sio2->_SIO2camera );         

Iīve tried without your code, traced execution and in sio2resourcecull the camera and all scene objects location and direction is the same as in my blender scene but the objectsīs dst value in sio2resourcerender is 0. sio2resourcecull is unreadable enough to stop me trying to trace it.

Lights are not enabled but as far I can see in tutorials thereīs no need of enabling it (just thinking about possible causes).

Iīm draining my brain but I donīt see why all objects have a dst value of 0.

Cheers.

iphoniac

Posts : 62
Join date : 2008-12-11

View user profile http://thecaveaniphonegame.blogspot.com/

Back to top Go down

Re: Attached objects?

Post  sio2interactive on Wed Mar 04, 2009 8:49 am

Ok send me your code by email I'll check it out...

_________________
SIO2 Interactive
Free Open Source 3D Game Engine for iPhone and iPod Touch
http://sio2interactive.com
avatar
sio2interactive

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

View user profile http://sio2interactive.com

Back to top Go down

Re: Attached objects?

Post  meteors on Wed Mar 04, 2009 10:25 am

Can you guys please make sure to paste the solution?


;-)


-joshua
avatar
meteors

Posts : 241
Join date : 2008-11-08
Location : Sunny Florida

View user profile

Back to top Go down

Re: Attached objects?

Post  meteors on Wed Mar 04, 2009 10:28 am

Ok, I'm confused. Where does SIO2player come from??

Is this only in the SVN version?


Thanks,
-j
avatar
meteors

Posts : 241
Join date : 2008-11-08
Location : Sunny Florida

View user profile

Back to top Go down

Re: Attached objects?

Post  iphoniac on Wed Mar 04, 2009 12:36 pm

I guess SIO2player itīs just a sample Smile

Iīm afraid, sio2interactive, I canīt send you the code Crying or Very sad but all the relevant part is just copied before.

iphoniac

Posts : 62
Join date : 2008-12-11

View user profile http://thecaveaniphonegame.blogspot.com/

Back to top Go down

Re: Attached objects?

Post  meteors on Wed Mar 04, 2009 12:48 pm

sample of what?

>_<
avatar
meteors

Posts : 241
Join date : 2008-11-08
Location : Sunny Florida

View user profile

Back to top Go down

Re: Attached objects?

Post  sio2interactive on Wed Mar 04, 2009 3:27 pm

iphoniac just create a simple project and copy paste the necessary blocks as well as the one that causes problem, for the model just create something quick with blender... cuz what you post is not enough for me to draw any conclusion...

_________________
SIO2 Interactive
Free Open Source 3D Game Engine for iPhone and iPod Touch
http://sio2interactive.com
avatar
sio2interactive

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

View user profile http://sio2interactive.com

Back to top Go down

Re: Attached objects?

Post  iphoniac on Thu Mar 05, 2009 2:33 am

I was doing just that Very Happy

Iīll send you later.

iphoniac

Posts : 62
Join date : 2008-12-11

View user profile http://thecaveaniphonegame.blogspot.com/

Back to top Go down

Re: Attached objects?

Post  basco on Mon Mar 09, 2009 7:21 am

Is there any support to make this parent-child-relationship a bit springy and use some physics?

basco

Posts : 12
Join date : 2009-02-01

View user profile

Back to top Go down

Re: Attached objects?

Post  sio2interactive on Mon Mar 09, 2009 10:03 pm

You have to use your own algorithm and affect it to the matrix...

_________________
SIO2 Interactive
Free Open Source 3D Game Engine for iPhone and iPod Touch
http://sio2interactive.com
avatar
sio2interactive

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

View user profile http://sio2interactive.com

Back to top Go down

Re: Attached objects?

Post  Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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