Yes, u r right Tom! Hurray!
But am now stucked with another challenge. It doesn't morph correctly.
I inserted 2 segments of code just to check if both objects are loaded and assigned properly and it seems correct. The object went out of shaping during the morphing.
These are the changes I've made:-
(1) alloc the 4 pointers before "goto Start"
alloc Model
alloc ModelStart
alloc ModelEnd
alloc ModelDelta
' Subroutines
goto Start
(2) Created these below the " ' Allocate vertices and polygons" section.
(done so as well for the other pointers: ModelEnd, ModelDelta, Model)
alloc ModelStart.vertex#, theModel.vertexCount - 1, 2
alloc ModelStart.norm#, theModel.normCount - 1, 2
alloc ModelStart.poly, theModel.polyCount - 1
alloc ModelStart.polyVertex, theModel.polyVertexCount - 1
(3) And added these routines and changes to the main loop section.
DrawObj_Morph:
' Render obj model
' Expects: theModel = Points to model to render
for i = 0 to theModel.polyCount - 1
&thePoly = &theModel.poly (i)
'glShadeModel(GL_SMOOTH)
glBegin (GL_TRIANGLE_FAN)
for i2 = 0 to thePoly.vertexCount - 1
&thePolyVertex = &theModel.polyVertex (thePoly.firstVertex + i2)
glNormal3fv (theModel.norm# (thePolyVertex.normIndex))
glVertex3fv (ModelStart.vertex# (thePolyVertex.vertexIndex))
next
glEnd ()
next
return
CalcMorphDeltaForEachVertex:
' Render obj model
' Expects: theModel = Points to model to render
for i = 0 to theModel.polyCount - 1
&thePoly = &theModel.poly (i)
for i2 = 0 to thePoly.vertexCount - 1
&thePolyVertex = &theModel.polyVertex (thePoly.firstVertex + i2)
ModelDelta.vertex# (thePolyVertex.vertexIndex) = (ModelEnd.vertex# (thePolyVertex.vertexIndex) - ModelStart.vertex# (thePolyVertex.vertexIndex))/tweening#
next
next
return
MorphObj_updateDelta:
for i = 0 to theModel.polyCount - 1
&thePoly = &theModel.poly (i)
for i2 = 0 to thePoly.vertexCount - 1
&thePolyVertex = &theModel.polyVertex (thePoly.firstVertex + i2)
ModelStart.vertex# (thePolyVertex.vertexIndex) = ModelStart.vertex# (thePolyVertex.vertexIndex) + ModelDelta.vertex# (thePolyVertex.vertexIndex)
next
next
return
Copy_theModel_to_ModelStart:
for i = 0 to theModel.polyCount - 1
&thePoly = &theModel.poly (i)
for i2 = 0 to thePoly.vertexCount - 1
&thePolyVertex = &theModel.polyVertex (thePoly.firstVertex + i2)
ModelStart.vertex# (thePolyVertex.vertexIndex) = theModel.vertex# (thePolyVertex.vertexIndex)
next
next
return
Copy_ModelStart_to_ModelDelta:
for i = 0 to theModel.polyCount - 1
&thePoly = &theModel.poly (i)
for i2 = 0 to thePoly.vertexCount - 1
&thePolyVertex = &theModel.polyVertex (thePoly.firstVertex + i2)
ModelDelta.vertex# (thePolyVertex.vertexIndex) = ModelStart.vertex# (thePolyVertex.vertexIndex)
next
next
return
Copy_theModel_to_ModelEnd:
for i = 0 to theModel.polyCount - 1
&thePoly = &theModel.poly (i)
for i2 = 0 to thePoly.vertexCount - 1
&thePolyVertex = &theModel.polyVertex (thePoly.firstVertex + i2)
ModelEnd.vertex# (thePolyVertex.vertexIndex) = theModel.vertex# (thePolyVertex.vertexIndex)
next
next
return
' Main program
Start:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Test by loading a sample model
dim xang#, yang#, zoom#, list, key$, saveFileName$
dim list2
zoom# = 150
yang# = 90
xang# = 25
ResizeText (80, 60)
' Lighting
glEnable (GL_LIGHTING)
glEnable (GL_LIGHT0)
glEnable (GL_COLOR_MATERIAL)
glClearColor (.2, .2, .2, 1)
theDir$ = "Files\"
'sphere with 4 extrusions
theFileName$ = "sphere_start.obj"
gosub LoadObj
gosub Copy_theModel_to_ModelStart
gosub Copy_ModelStart_to_ModelDelta
' temporary check on start object
glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
glLoadIdentity ()
glTranslatef (0, 0, -zoom#)
glRotatef (xang#, 1, 0, 0)
glRotatef (yang#, 0, 1, 0)
gosub DrawObj_Morph
gosub MorphObj_updateDelta
SwapBuffers ()
while not scankeydown(vk_space):wend
' Models can have several thousand vertices and polygons, which can cause our
' virtual machine based language to chug a little bit.
' Therefore we render the frame once into a display list, which will usually speed things up dramatically
'sphere with the same size as start but with 4 longer extrusions
theFileName$ = "sphere_end.obj"
gosub LoadObj
gosub Copy_theModel_to_ModelEnd
&Model=&ModelStart 'store pointer temporarily to Model
&ModelStart=&ModelEnd
' temporary check on end object
glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
glLoadIdentity ()
glTranslatef (0, 0, -zoom#)
glRotatef (xang#, 1, 0, 0)
glRotatef (yang#, 0, 1, 0)
gosub DrawObj_Morph
gosub MorphObj_updateDelta
SwapBuffers ()
while not scankeydown(vk_space):wend
&ModelStart=&Model ' restore pointer to ModelStart
gosub Instructions
gosub CalcMorphDeltaForEachVertex
' Draw model
while true
'for i3=0 to 100 'tweening
glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
glLoadIdentity ()
glTranslatef (0, 0, -zoom#)
glRotatef (xang#, 1, 0, 0)
glRotatef (yang#, 0, 1, 0)
gosub DrawObj_Morph
gosub MorphObj_updateDelta
DrawText ()
SwapBuffers ()
'next 'i3
' User interface
while SyncTimer (10)
:
:
Thanks!
-Lucas Tan-