News:

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

Camera Movement Using GPU

Started by Farabi, November 12, 2011, 12:20:11 AM

Previous topic - Next topic

Farabi

#15
Here is the rotation matrix
Quote
RROTATE_X equ 0
RROTATE_Y equ 1
RROTATE_Z equ 2
LROTATE_X equ 3
LROTATE_Y equ 4
LROTATE_Z equ 5
fMat4fRotate proc uses esi edi lpfMat4f:dword,nOrder:dword,Degree:real4
   LOCAL mtmp[16]:dword
   LOCAL tmpx,tmpy,tmpz:dword
   LOCAL sin,cos,msin,mcos:dword
   
   invoke fMat4fLoadIdentity,addr mtmp
   
   fldpi
   fdiv FP4(180.)
   fmul Degree
   fsincos
   fstp cos
   fstp sin
   
   fld sin
   fchs
   fstp msin
   
   fld cos
   fchs
   fstp mcos
   
   .if nOrder==RROTATE_X
      invoke fFillMatrix4f,addr mtmp,5,cos
      invoke fFillMatrix4f,addr mtmp,6,sin
      invoke fFillMatrix4f,addr mtmp,9,msin
      invoke fFillMatrix4f,addr mtmp,10,cos
   .elseif nOrder==RROTATE_Y
      invoke fFillMatrix4f,addr mtmp,0,cos
      invoke fFillMatrix4f,addr mtmp,2,msin
      invoke fFillMatrix4f,addr mtmp,8,sin
      invoke fFillMatrix4f,addr mtmp,10,cos
   .elseif nOrder==RROTATE_Z
      invoke fFillMatrix4f,addr mtmp,0,cos
      invoke fFillMatrix4f,addr mtmp,1,sin
      invoke fFillMatrix4f,addr mtmp,4,msin
      invoke fFillMatrix4f,addr mtmp,5,cos
   .elseif nOrder==LROTATE_X
      invoke fFillMatrix4f,addr mtmp,5,cos
      invoke fFillMatrix4f,addr mtmp,6,msin
      invoke fFillMatrix4f,addr mtmp,9,sin
      invoke fFillMatrix4f,addr mtmp,10,cos
   .elseif nOrder==LROTATE_Y
      invoke fFillMatrix4f,addr mtmp,0,cos
      invoke fFillMatrix4f,addr mtmp,2,sin
      invoke fFillMatrix4f,addr mtmp,8,msin
      invoke fFillMatrix4f,addr mtmp,10,cos
   .elseif nOrder==LROTATE_Z
      invoke fFillMatrix4f,addr mtmp,0,cos
      invoke fFillMatrix4f,addr mtmp,1,msin
      invoke fFillMatrix4f,addr mtmp,4,sin
      invoke fFillMatrix4f,addr mtmp,5,cos
   .endif
   
   invoke MemCopy,addr mtmp,lpfMat4f,64
   invoke glMultMatrixf,addr mtmp
   
   ret
fMat4fRotate endp


Now I know I should change it to radian first.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

 :bdg

Never Thought Matrix is so easy, I guess I should claim that Im a Master of Computer Science  :cheekygreen:

fMat4fInverseRtoLHandMatrix proc uses esi lpMat4f:dword
LOCAL m[16]:dword

invoke fGetMatrix4f,lpMat4f,0
invoke fFillMatrix4f,addr m,0,eax
invoke fGetMatrix4f,lpMat4f,1
invoke fFillMatrix4f,addr m,4,eax
invoke fGetMatrix4f,lpMat4f,2
invoke fFillMatrix4f,addr m,8,eax
invoke fGetMatrix4f,lpMat4f,3
invoke fFillMatrix4f,addr m,12,FP4(0.0)

invoke fGetMatrix4f,lpMat4f,4
invoke fFillMatrix4f,addr m,1,eax
invoke fGetMatrix4f,lpMat4f,5
invoke fFillMatrix4f,addr m,5,eax
invoke fGetMatrix4f,lpMat4f,6
invoke fFillMatrix4f,addr m,9,eax
invoke fGetMatrix4f,lpMat4f,7
invoke fFillMatrix4f,addr m,13,FP4(0.0)

invoke fGetMatrix4f,lpMat4f,8
invoke fFillMatrix4f,addr m,2,eax
invoke fGetMatrix4f,lpMat4f,9
invoke fFillMatrix4f,addr m,6,eax
invoke fGetMatrix4f,lpMat4f,10
invoke fFillMatrix4f,addr m,10,eax
invoke fGetMatrix4f,lpMat4f,11
invoke fFillMatrix4f,addr m,14,FP4(0.0)

invoke fFillMatrix4f,addr m,3,FP4(0.0)
invoke fFillMatrix4f,addr m,7,FP4(0.0)
invoke fFillMatrix4f,addr m,11,FP4(0.0)
invoke fFillMatrix4f,addr m,15,FP4(1.0)

invoke MemCopy,addr m,lpMat4f,16*4

ret
fMat4fInverseRtoLHandMatrix endp


This was to inverse from the right to Left hand.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

dedndave

we bow to you, oh great graphics master 

Farabi

Quote from: dedndave on November 19, 2011, 04:26:19 AM
we bow to you, oh great graphics master 
Im just joking dave  :green
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

This is funny, on Indonesian Science Forum, every people said Im a genious, smart, super inteligent, but in here, Im just look stupid. But hey, I fix it someday, well at least, even it will not be happened, you all wont live forever dont you, so do I, I could be dead tommorow. SHIT. I want to feel the sensation beeing the smartest person on the universe  :cheekygreen:
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Now I got this working.


R2C equ 0 ; Row to Column
C2R equ 1 ; Column To Row
; The weird thing is, When I used R2C on the Right hand coordinate, sudenly it become OpenGL Left Coordinate, I dont really get it.
;But Ill figure it out late or soon.


fMat4fTranspose proc uses esi edi lpMat4fDest:dword,lpMat4fSource:dword,nMode:dword
LOCAL m[16]:dword

invoke fMat4fLoadIdentity,addr m
mov esi,lpMat4fSource
lea edi,m
cmp nMode,R2C
jz @f
invoke fGetMatrix4f,esi,0
invoke fFillMatrix4f,edi,0,eax
invoke fGetMatrix4f,esi,1
invoke fFillMatrix4f,edi,4,eax
invoke fGetMatrix4f,esi,2
invoke fFillMatrix4f,edi,8,eax
invoke fGetMatrix4f,esi,3
invoke fFillMatrix4f,edi,12,eax

invoke fGetMatrix4f,esi,4
invoke fFillMatrix4f,edi,1,eax
invoke fGetMatrix4f,esi,5
invoke fFillMatrix4f,edi,5,eax
invoke fGetMatrix4f,esi,6
invoke fFillMatrix4f,edi,9,eax
invoke fGetMatrix4f,esi,7
invoke fFillMatrix4f,edi,13,eax

invoke fGetMatrix4f,esi,8
invoke fFillMatrix4f,edi,2,eax
invoke fGetMatrix4f,esi,9
invoke fFillMatrix4f,edi,6,eax
invoke fGetMatrix4f,esi,10
invoke fFillMatrix4f,edi,10,eax
invoke fGetMatrix4f,esi,11
invoke fFillMatrix4f,edi,14,eax

invoke fGetMatrix4f,esi,12
invoke fFillMatrix4f,edi,3,eax
invoke fGetMatrix4f,esi,13
invoke fFillMatrix4f,edi,7,eax
invoke fGetMatrix4f,esi,14
invoke fFillMatrix4f,edi,11,eax
invoke fGetMatrix4f,esi,15
invoke fFillMatrix4f,edi,15,eax
invoke MemCopy,addr m,lpMat4fDest,16*4
ret
@@:

invoke fGetMatrix4f,esi,0
invoke fFillMatrix4f,edi,0,eax
invoke fGetMatrix4f,esi,4
invoke fFillMatrix4f,edi,1,eax
invoke fGetMatrix4f,esi,8
invoke fFillMatrix4f,edi,2,eax
invoke fGetMatrix4f,esi,12
invoke fFillMatrix4f,edi,3,eax

invoke fGetMatrix4f,esi,1
invoke fFillMatrix4f,edi,4,eax
invoke fGetMatrix4f,esi,5
invoke fFillMatrix4f,edi,5,eax
invoke fGetMatrix4f,esi,9
invoke fFillMatrix4f,edi,6,eax
invoke fGetMatrix4f,esi,13
invoke fFillMatrix4f,edi,7,eax

invoke fGetMatrix4f,esi,2
invoke fFillMatrix4f,edi,8,eax
invoke fGetMatrix4f,esi,6
invoke fFillMatrix4f,edi,9,eax
invoke fGetMatrix4f,esi,10
invoke fFillMatrix4f,edi,10,eax
invoke fGetMatrix4f,esi,14
invoke fFillMatrix4f,edi,11,eax

invoke fGetMatrix4f,esi,3
invoke fFillMatrix4f,edi,12,eax
invoke fGetMatrix4f,esi,7
invoke fFillMatrix4f,edi,13,eax
invoke fGetMatrix4f,esi,11
invoke fFillMatrix4f,edi,14,eax
invoke fGetMatrix4f,esi,15
invoke fFillMatrix4f,edi,15,eax
invoke MemCopy,addr m,lpMat4fDest,16*4

ret
fMat4fTranspose endp
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

#21
Simplification of camera



fCam struct
Position VERTEX <0.0>
Rotation VERTEX <0.0>
fCam ends


.code
[edited]
; Now we can render multiple frame using multiple camera, and could be used for the Lights Point of View.
fCameraLook proc uses esi lpcamera:dword

invoke glClearColor,FP4(0.0),FP4(0.0),FP4(0.0),FP4(0.0)
invoke glClear,GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT
invoke glEnable,GL_DEPTH_TEST
invoke glMatrixMode,GL_MODELVIEW;
invoke glLoadIdentity
invoke glColor3f,FP4(1.0),FP4(1.0),FP4(1.0)
invoke gluPerspective,FP8(45.0),FP8(1.33333333333333),FP8(1.0),FP8(1000000000.0)

mov esi,lpcamera
invoke glRotatef,[esi].fCam.Rotation.X,FP4(1.0),FP4(0.0),FP4(0.0)
invoke glRotatef,[esi].fCam.Rotation.Y,FP4(0.0),FP4(1.0),FP4(0.0)
invoke glRotatef,[esi].fCam.Rotation.Z,FP4(0.0),FP4(0.0),FP4(1.0)
invoke glTranslatef,[esi].fCam.Position.X,[esi].fCam.Position.Y,[esi].fCam.Position.Z

ret
fCameraLook endp

fCameraMove proc uses esi edi lpcamera:dword,fp4distance:dword
LOCAL x[16]:real4
LOCAL buff[256]:dword
LOCAL q:qword
LOCAL py,px:dword

mov esi,lpcamera

invoke glPushMatrix
invoke glMatrixMode,GL_MODELVIEW
invoke glLoadIdentity

invoke glRotatef,[esi].fCam.Rotation.X,FP4(1.0),FP4(0.0),FP4(0.0)
invoke glRotatef,[esi].fCam.Rotation.Y,FP4(0.0),FP4(1.0),FP4(0.0)
invoke glRotatef,[esi].fCam.Rotation.Z,FP4(0.0),FP4(0.0),FP4(1.0)
invoke glGetFloatv,GL_MODELVIEW_MATRIX,addr x
lea edi,x
invoke glPopMatrix

fld dword ptr[edi+2*4]
fmul fp4distance
fstp dword ptr[edi+2*4]
fld dword ptr[edi+6*4]
fmul fp4distance
fstp dword ptr[edi+6*4]
fld dword ptr[edi+10*4]
fmul fp4distance
fstp dword ptr[edi+10*4]

fld  [esi].fCam.Position.X
fadd dword ptr[edi+2*4]
fstp [esi].fCam.Position.X

fld [esi].fCam.Position.Y
fadd dword ptr[edi+6*4]
fstp [esi].fCam.Position.Y

fld [esi].fCam.Position.Z
fadd dword ptr[edi+10*4]
fstp [esi].fCam.Position.Z
ret
fCameraMove endp


How to use it


invoke fCameraLook,addr CurrCam
; Replcaing GLULookAt
invoke IsPressed,"W"
.if eax==1
invoke fCameraMove,addr CurrCam,FP4(10.0) ; Moving forward
.endif
invoke IsPressed,"S"
.if eax==1
invoke fCameraMove,addr CurrCam,FP4(-10.0) ; Moving backward
.endif
; Create the rotation viewer changer somewhere, and let the fCameraMove handle the rest
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

http://www.flounder.com/gradientfiller.htm

:lol Sounds like this website making fun of me because Im too lazy to type a new structure. I think now I know why C++ always yield a wrong error message, they want to follow the human grammar standard, where I just follow my "native" standard of OPCODE.  :lol
Okay, I got it, I'll change the structure name, Im so ashamed when reading that website.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Here is the last thing we will need to invent our own 3D renderer function.

Quote
3DTo2DF proc uses esi edi X:real4,Y:real4,Z:real4,F:real4,intScreenW:dword,intScreenH:dword
   
   shr intScreenW,1
   shr intScreenh,1
   ;X:= ((X/Z) * F) + intScreenW/2
   ;Y:= ((Y/Z) * F) + intScreenH/2
   
   fld X
   fdiv Z
   fmul F
   fiadd intScreenW
   
   fld Y
   fdiv Z
   fmul F
   fiadd intScreenH
   
   
   ret
3DTo2DF endp
; Result at FPU stack
; ST(1):= X
; ST(0):= Y
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Im correcting some wrong formula. Most of the code above just tested and proven to be worked.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"