News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

[Help]New Approach on OpenGL camera

Started by Farabi, July 30, 2009, 04:06:33 PM

Previous topic - Next topic

Farabi

Here is the code so far,
Something was wrong but I cant see it.

Quote
.data
;   m fMat4 <?>
   mat_arr real4 0 dup (16)
.code

; ------------------------------------------------------------------------------------------------
; Originally wrote by Alexander Festini

fSetCamera proc uses esi lpX:dword,lpY:dword,lpZ:dword
   
   invoke memfill,addr mat_arr,64,0
   lea esi,mat_arr
   
   fld1
   fstp dword ptr [esi+0*4]
   fld1
   fstp dword ptr[esi+5*4]
   fld1
   fchs
   fstp dword ptr[esi+10*4]
   fld1
   fstp dword ptr[esi+15*4]
   
   fld lpX
   fstp dword ptr[esi+12*4]
   fld lpY
   fstp dword ptr[esi+13*4]
   fld lpZ
   fstp dword ptr[esi+14*4]
   
   
   ret
fSetCamera endp

fSetView proc uses esi edi
   LOCAL v_mat[16]:dword
   LOCAL tmp:dword
   
   lea esi,mat_arr
   invoke glMatrixMode,GL_MODELVIEW
   invoke glLoadIdentity
   
   invoke memfill,addr v_mat,64,0
   
   lea edi,v_mat
   fld dword ptr[esi+0*4]
   fstp dword ptr [edi+0*4]
   fld dword ptr [esi+4*4]
   fstp dword ptr [edi+1*4]
   fld dword ptr [esi+8*4]
   fchs
   fstp dword ptr [edi+2*4]
   fldz
   fstp dword ptr [edi+3*4]
   
   fld dword ptr[esi+1*4]
   fstp dword ptr [edi+4*4]
   fld dword ptr [esi+5*4]
   fstp dword ptr [edi+5*4]
   fld dword ptr [esi+9*4]
   fchs
   fstp dword ptr [edi+6*4]
   fldz
   fstp dword ptr [edi+7*4]

   fld dword ptr[esi+2*4]
   fstp dword ptr [edi+8*4]
   fld dword ptr [esi+6*4]
   fstp dword ptr [edi+9*4]
   fld dword ptr [esi+10*4]
   fchs
   fstp dword ptr [edi+10*4]
   fldz
   fstp dword ptr [edi+11*4]
   
   
   
   
   fld dword ptr [esi+12*4]
   fmul dword ptr [esi]
   fstp tmp
   fld dword ptr[esi+13*4]
   fmul dword ptr[esi+1*4]
   fadd tmp
   fstp tmp
   fld dword ptr[esi+14*4]
   fmul dword ptr[esi+2*4]
   fadd tmp
   fstp dword ptr [edi+12*4]
   
   fld dword ptr [esi+12*4]
   fmul dword ptr [esi+4*4]
   fstp tmp
   fld dword ptr[esi+13*4]
   fmul dword ptr[esi+5*4]
   fadd tmp
   fstp tmp
   fld dword ptr[esi+14*4]
   fmul dword ptr[esi+6*4]
   fadd tmp
   fstp dword ptr [edi+13*4]

   fld dword ptr [esi+12*4]
   fmul dword ptr [esi+8*4]
   fstp tmp
   fld dword ptr[esi+13*4]
   fmul dword ptr[esi+9*4]
   fadd tmp
   fstp tmp
   fld dword ptr[esi+14*4]
   fmul dword ptr[esi+10*4]
   fadd tmp
   fstp dword ptr [edi+14*4]
   
   fld1
   fstp dword ptr [edi+15*4]
   invoke glLoadMatrixf,addr v_mat
   
   ret
fSetView endp

fMovGlobal proc uses esi lpfX:dword,lpfY:dword,lpfZ:dword,lpfDistance:dword
   
   lea esi,mat_arr
   
   fld lpfX
   fmul lpfDistance
   fadd dword ptr[esi+12*4]
   fstp dword ptr[esi+12*4]
   
   fld lpfY
   fmul lpfDistance
   fadd dword ptr[esi+13*4]
   fstp dword ptr[esi+13*4]
   
   fld lpfZ
   fmul lpfDistance
   fadd dword ptr[esi+14*4]
   fstp dword ptr[esi+14*4]
   
   
   ret
fMovGlobal endp

fMovLoc proc uses esi lpfX:dword,lpfY:dword,lpfZ:dword,lpfDistance:dword
   LOCAL _dx,_dy,_dz:real4
   
   lea esi,mat_arr
   fld dword ptr [esi]
   fmul lpfX
   fstp _dx
   fld dword ptr [esi+4*4]
   fmul lpfY
   fadd _dx
   fstp _dx
   fld dword ptr [esi+8*4]
   fmul lpfZ
   fadd _dx
   fstp _dx
   
   fld dword ptr [esi+1*4]
   fmul lpfX
   fstp _dy
   fld dword ptr [esi+5*4]
   fmul lpfY
   fadd _dy
   fstp _dy
   fld dword ptr [esi+9*4]
   fmul lpfZ
   fadd _dy
   fstp _dy
   
   fld dword ptr [esi+2*4]
   fmul lpfX
   fstp _dz
   fld dword ptr [esi+6*4]
   fmul lpfY
   fadd _dz
   fstp _dz
   fld dword ptr [esi+10*4]
   fmul lpfZ
   fadd _dz
   fstp _dz
   
   fld _dx
   fmul lpfDistance
   fadd dword ptr [esi+12*4]
   fstp dword ptr [esi+12*4]
   
   fld _dy
   fmul lpfDistance
   fadd dword ptr [esi+13*4]
   fstp dword ptr [esi+13*4]
   
   fld _dz
   fmul lpfDistance
   fadd dword ptr [esi+14*4]
   fstp dword ptr [esi+14*4]

   
   ret
fMovLoc endp

fRotateLoc proc uses esi lpDegree:dword,lpfX:dword,lpfY:dword,lpfZ:dword
   
   invoke glMatrixMode,GL_MODELVIEW
   invoke glPushMatrix
   invoke glLoadMatrixf,addr mat_arr
   invoke glRotatef,lpDegree,lpfX,lpfY,lpfZ
   invoke glGetFloatv,GL_MODELVIEW_MATRIX,addr mat_arr
   invoke glPopMatrix
   
   ret
fRotateLoc endp

fRotateGlobal proc uses esi lpDegree:dword,lpfX:dword,lpfY:dword,lpfZ:dword
   LOCAL _dx:real4
   LOCAL _dy:real4
   LOCAL _dz:real4
   
   lea esi,mat_arr
   fld dword ptr [esi]
   fmul lpfX
   fstp _dx
   fld dword ptr [esi+1*4]
   fmul lpfY
   fadd _dx
   fstp _dx
   fld dword ptr [esi+2*4]
   fmul lpfZ
   fadd _dx
   fstp _dx
   
   fld dword ptr [esi+4*4]
   fmul lpfX
   fstp _dy
   fld dword ptr [esi+5*4]
   fmul lpfY
   fadd _dy
   fstp _dy
   fld dword ptr [esi+6*4]
   fmul lpfZ
   fadd _dy
   fstp _dy
   
   fld dword ptr [esi+8*4]
   fmul lpfX
   fstp _dz
   fld dword ptr [esi+9*4]
   fmul lpfY
   fadd _dz
   fstp _dz
   fld dword ptr [esi+10*4]
   fmul lpfZ
   fadd _dz
   fstp _dz
   
   invoke glMatrixMode,GL_MODELVIEW
   invoke glPushMatrix
   invoke glLoadMatrixf,esi
;   lea ecx,_dx
;   lea edx,_dy
;   lea eax,_dz
   invoke glRotatef,lpDegree,_dx,_dy,_dz
   invoke glGetFloatv,GL_MODELVIEW_MATRIX,addr mat_arr
   invoke glPopMatrix
   
   ret
fRotateGlobal endp

fFillMatrix4f proc uses esi lpfMat4:dword,nIndex:dword,lpValueReal4:dword
   
   mov esi,lpfMat4
   mov ecx,nIndex
   mov eax,lpValueReal4
   mov eax,[eax]
   mov [esi+ecx*4],eax
   
   ret
fFillMatrix4f endp
;----------------------------------------------------------------------------------------------------

It seems I missed multiplying it. But dont know where it is.
Anyone can help?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

vanjast

Hey Farabi.. try psuedo (english) code first  :bg  makes it easier to understand  :wink

It helps one see through the mess...
I'm doing  bit of DSP stuff that calculates filters and other 'junk'  and after 2 weeks I was tearing my hair out.
I scribbled the whole lot out in psuedo code and got it running this morning after a week... :wink

Farabi

Nevermind it, I took frank charlet code and its working. I guess I will stick to it from now. Vector is a real mess.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"