[Gambas-devel] Interface of gb.opengl.sge

Benoît Minisini gambas at ...1...
Thu Mar 28 03:41:36 CET 2013


Hi Tomek,

I took a glance at your code, and I strongly suggest the following 
changes to the gb.opengl.gse interface before you go further.

Why these changes? Mainly because I try to make Gambas components have 
the most similar interfaces as possible, so that the learning curve is 
lower.

By the way, not that there is a design problem too : the MD2 model 
loading routine only works if the endianness of the CPU is the same as 
the endianness of the file. You should ensure that if the endianness is 
different, you swap the binary data accordingly.

Now the old interface :

GB_DESC Md2ModelDesc[] =
{
   GB_DECLARE("Md2Model", sizeof(MD2MODEL)),
   GB_NOT_CREATABLE(),
   GB_STATIC_METHOD("Load", "Md2Model" , Md2Model_Load, "(Name)s"),
   GB_METHOD("SetPosition", NULL, Md2Model_SetPosition, "(X)f(Y)f(Z)f" ),
   GB_METHOD("DrawFrame", NULL, Md2Model_DrawFrame, 
"(Frame_No)i(Texture)i" ),
   GB_METHOD("DrawInterFrame", NULL, Md2Model_DrawInterFrame, 
"(Frame_No)i(InterFrame)f(Texture)i" ),
   GB_METHOD("GetFramesNo", "i", Md2Model_GetNoFrames, NULL ),
   GB_METHOD("GetFrameName", "s", Md2Model_GetFrameName, "(FrameNumber)i" ),
   GB_METHOD("Scale", NULL, Md2Model_Scale, 
"(Scale_x)f(Scale_y)f(Scale_z)f" ),
   GB_METHOD("_free", NULL, Md2Model_free, NULL ),
   GB_END_DECLARE
};

The new one I suggest:

GB_DESC Md2ModelDesc[] =
{
   GB_DECLARE("Md2Model", sizeof(MD2MODEL)),
   GB_NOT_CREATABLE(),
   GB_STATIC_METHOD("Load", "Md2Model" , Md2Model_Load, "(Name)s"),
   // 'SetPosition' renamed to 'Move'
   GB_METHOD("Move", NULL, Md2Model_SetPosition, "(X)f(Y)f(Z)f" ),
   // Three properties to get/set the one coordinate
   GB_PROPERTY("X", "f", Md2Model_X),
   GB_PROPERTY("Y", "f", Md2Model_X),
   GB_PROPERTY("Z", "f", Md2Model_X),
   // A virtual object for accessing frame properties and count
   GB_PROPERTY_SELF("Frames", ".Md2Model.Frames"),
   GB_METHOD("Scale", NULL, Md2Model_Scale, "(ScaleX)f(ScaleY)f(ScaleZ)f" ),
   // Maybe you should add ScaleX, ScaleY and ScaleZ properties too.
   GB_METHOD("_free", NULL, Md2Model_free, NULL ),
   GB_END_DECLARE
};

GB_DESC Md2ModelFramesDesc[] =
{
   GB_DECLARE_VIRTUAL(".Md2Model.Frames"),
   // Was Md2Model_GetNoFrames
   GB_PROPERTY_READ("Count", "i", Md2Model_Frames_Count)
   GB_METHOD("_get", ".Md2Model.Frame", Md2Model_Frames_get, "(Frame)i"),
   GB_END_DECLARE
}

// The _get method of Md2Model_Frames is implemented that way:

BEGIN_METHOD(Md2Model_Frames_get, GB_INTEGER frame)

   // Store the frame number into the object, it will be used immediately
   // by the method called on the virtual .Md2Model.Frame object.
   // Maybe check that the frame number is valid now.
   // And don't forget to add the 'frame' field into the object
   // structure.
   THIS->frame = VARG(frame);

END_METHOD

GB_DESC Md2ModelFrameDesc[] =
{
   GB_DECLARE_VIRTUAL(".Md2Model.Frame"),
   // Was 'Md2Model.DrawFrame'
   GB_METHOD("Draw", NULL, Md2Model_Frame_Draw, "(Texture)i"),
   // Was 'Md2Model.DrawInterFrame'
   GB_METHOD("DrawInterFrame", NULL, Md2Model_Frame_DrawInterFrame, 
"(InterFrame)f(Texture)i"),
   GB_END_DECLARE
}

Tell me what you think about that and if you have questions!

Regards,

-- 
Benoît Minisini




More information about the Devel mailing list