How To Work With Objects
This section tries to explain how to move and rotate objects directly in SIO2.
Object Movement, Rotation, Scaling
(not using physics)
Get the handle of the object:
SIO2object * WHATEVERNAMEYOUWANT = ( SIO2object * )sio2ResourceGet( sio2->_SIO2resource, SIO2_OBJECT, "object/SkiL" );
To translate the object
WHATEVERNAMEYOUWANT->_SIO2transform->loc->x = 124.0f;
To rotate the object
WHATEVERNAMEYOUWANT->_SIO2transform->rot->x = 100.0f;
To scale the object
WHATEVERNAMEYOUWANT->_SIO2transform->scl->x = 2.0f;
After changing any of these parameters, YOU MUST CALL THIS FUNCTION IN ORDER TO MAKE THE CHANGES HAPPEN
sio2TransformBindMatrix( WHATEVERNAMEYOUWANT->_SIO2transform );
Object Duplication
SIO2object *selection = NULL;
User code must set "selection" to point to the object to be duplicated, then…
Create a name for our new object
static unsigned int i = 0;
char name[ SIO2_MAX_CHAR ];
sprintf( name, "%s_%d", selection->name, i );
Give a little offset so it'll be duplicated right on top of the current selection
selection->_SIO2transform->loc->z += ( selection->rad * 1.5f );
selection = sio2ObjectDuplicate( selection, selection->_SIO2transform, name, 1 );
Note that the above sio2ObjectDuplicate is deprecated - use this instead:
//
// Clone an object
//
SIO2object* templateClone(char* original_name, float x, float y, float z) {
static unsigned int unique_name_id = 0;
char unique_name[ SIO2_MAX_CHAR ];
SIO2object *parent = NULL;
SIO2object *duplicate = NULL;
// find object in resource list by name
SIO2object *selection = ( SIO2object * )sio2ResourceGetObject( sio2->_SIO2resource,original_name);
if(!selection) {
return NULL;
}
// actually make a copy with a unique name
parent = selection->_SIO2instance ? ( SIO2object * )selection->_SIO2instance : selection;
sprintf( unique_name, "%s_%d", parent->name, unique_name_id );
if( selection->_SIO2objectphysic && selection->_SIO2objectphysic->bounds == SIO2_PHYSIC_CONVEXHULL ) {
duplicate = sio2ObjectHardCopy( parent, unique_name );
} else {
duplicate = sio2ObjectSoftCopy( parent, unique_name );
}
// copy the transform matrix again (may not be needed) and update its position
sio2TransformCopy( duplicate->_SIO2transform, selection->_SIO2transform );
duplicate->_SIO2transform->rot->x = 0;
duplicate->_SIO2transform->rot->y = 0;
duplicate->_SIO2transform->rot->z = 0;
duplicate->_SIO2transform->loc->x = x;
duplicate->_SIO2transform->loc->y = y;
duplicate->_SIO2transform->loc->z = z;
// bind matrix basically builds an opengl model view matrix and store this into the duplicate
sio2TransformBindMatrix( duplicate->_SIO2transform );
// this does some game physics related stuff - depends on if you have physics on
// sio2PhysicAddObject( sio2->_SIO2physic, duplicate );
// build an ordinary opengl display list for the object
if( selection->_SIO2objectphysic && selection->_SIO2objectphysic->bounds == SIO2_PHYSIC_CONVEXHULL ) {
sio2ObjectGenId( duplicate );
}
unique_name_id++;
return duplicate;
}
[[/code]]
[[/code]]
Tutorial06 implements object duplication, see template.mm, search on "sio2ObjectDuplicate".
page revision: 6, last edited: 18 Nov 2009 00:07





