5 Years Im figuring it out, and this day I understanding it. Im so stupid
[edited]
Sorry I misscalculating the Z position, it fixed
;Use Plus fp4distance for advancing forwar, and negatifve for backward
Move3D proc uses esi edi lppos:dword,fp4distance:dword,rotX:dword,rotY:dword,rotZ:dword
LOCAL x[16]:real4
LOCAL buff[256]:dword
LOCAL q:qword
LOCAL py,px:dword
invoke glPushMatrix
invoke glMatrixMode,GL_MODELVIEW
invoke glLoadIdentity
invoke glRotatef,rotX,FP4(1.0),FP4(0.0),FP4(0.0)
invoke glRotatef,rotY,FP4(0.0),FP4(1.0),FP4(0.0)
invoke glRotatef,rotZ,FP4(0.0),FP4(0.0),FP4(1.0)
; invoke glTranslatef,FP4(0.0),FP4(0.0),fp4distance
invoke glGetFloatv,GL_MODELVIEW_MATRIX,addr x
lea edi,x
;--------------------------------------------------------------------------------
; Only for debugging process
xor ecx,ecx
mov px,ecx
mov py,200
lea edi,x
loop_print:
push ecx
fld dword ptr[edi+ecx*4]
fstp q
invoke FloatToStr,q,addr buff
invoke fShowText,px,py,addr buff
add px,70
.if px>270
mov px,0
add py,12
.endif
pop ecx
inc ecx
cmp ecx,16
jl loop_print
;--------------------------------------------------------------------------------
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]
mov esi,lppos
fld [esi].VERTEX.X
fadd dword ptr[edi+2*4]
fstp [esi].VERTEX.X
fld [esi].VERTEX.Y
fadd dword ptr[edi+6*4]
fstp [esi].VERTEX.Y
fld [esi].VERTEX.Z
fadd dword ptr[edi+10*4]
fstp [esi].VERTEX.Z
ret
Move3D endp
How to use
invoke IsPressed,"W"
.if eax==1
invoke Move3D,addr cpos,FP4(10.0),cam_ang.X,cam_ang.Y,cam_ang.Z
.endif
invoke IsPressed,"S"
.if eax==1
invoke Move3D,addr cpos,FP4(-10.0),cam_ang.X,cam_ang.Y,cam_ang.Z
.endif
How to use it
; cpos is the VERTEX determine your current position. distance is the speed you want each movement, the rest is self explain. This camera system is easier than Charles Frank created one.
invoke Move3D,addr cpos,FP4(1.0),cam_ang.X,cam_ang.Y,cam_ang.Z
hi,
what part is done by the GPU? - rotating and translating one vector?
Quote
invoke glLoadIdentity
invoke glRotatef,rotX,FP4(1.0),FP4(0.0),FP4(0.0)
invoke glRotatef,rotY,FP4(0.0),FP4(1.0),FP4(0.0)
invoke glRotatef,rotZ,FP4(0.0),FP4(0.0),FP4(1.0)
invoke glTranslatef,FP4(0.0),FP4(0.0),fp4distance
This one. The manual said, OpenGL used GPU to calculating it, obviusly, a CPU wont match to calculate such a thing.
Dif I missunderstood again? :cheekygreen:
Quote from: qWord on November 12, 2011, 12:46:24 AM
hi,
what part is done by the GPU? - rotating and translating one vector?
:red
Errr, yes, ONE VECTOR.
Using the GPU for some matrix multiplications doesn't sound plausible - but maybe I'm wrong.
This camera movement is better than the Raydium One, and also it really efficient. Well, the CPU version could be faster, but, youll waste your time to reuploading the matrix or even sometime transpose it first, but this, nothing to be done, just use the result which is already calculated.
http://ompldr.org/vYjh3Zw/OGLE.zip
This is the camera I wanted from a long time ago, not like what hitchkr did. The movemnt is faster, but the drawing is slower than it should I dont know where the mstake is. I guess the polygon on the human is bigger. I tried to use OBJ format, the indices makes it 7 times slower. But mayne, it was just my method which is sucked, OpenGL rendered it fast.
http://ompldr.org/vYmFyaQ/OGLE.zip (5 MBytes, ouch)
Fixed the camera, I edited the code on the first post.
(http://ompldr.org/vYmFyZQ/FRB.jpg)
very cool, Farabi
how do i change my altitude ?
why dont you try out SSE instruction for this Farabi, thats why they added them and xmm regs to hold matrices in
this is an example of rotating in parallel
Quote from: dedndave on November 16, 2011, 02:01:44 AM
very cool, Farabi
how do i change my altitude ?
Altitude? You can just press W and point the Mouse Above
Quote from: daydreamer on November 16, 2011, 07:45:14 PM
why dont you try out SSE instruction for this Farabi, thats why they added them and xmm regs to hold matrices in
this is an example of rotating in parallel
Thanks, I'll try it out.
Hey, did you just use plain CPU? Not using DirectX or OpenGL? Looks cool, I can felt the depth illusion
I tried many thing to optimized it, but I cant reach below 25%. With or without light or texture. Canth help it.
I think the main problem on 3D programming is scaling and floodfilling. If CPU acceleration for 2D processing fast enough, I think I cant make a 3D graphic engine using only CPU.
This is the CPU Version, Dont know which is faster
fFillMatrix4f proc uses esi lpfMat4:dword,nIndex:dword,value:dword
mov esi,lpfMat4
mov ecx,nIndex
mov eax,value
mov [esi+ecx*4],eax
ret
fFillMatrix4f endp
fGetMatrix4f proc uses esi lpfMat4:dword,nIndex:dword
mov esi,lpfMat4
mov ecx,nIndex
mov eax,[esi+ecx*4]
ret
fGetMatrix4f endp
fLoadMatrix4fToFPU proc uses esi lpfMat4f:dword,nIndex:dword
mov esi,lpfMat4f
mov ecx,nIndex
fld dword ptr[esi+ecx*4]
ret
fLoadMatrix4fToFPU endp
fMat4fLoadZero proc uses esi lpfMat4f:dword
mov esi,lpfMat4f
xor ecx,ecx
loop_fill:
pushad
invoke fFillMatrix4f,esi,ecx,FP4(0.0)
popad
inc ecx
cmp ecx,16
jl loop_fill
ret
fMat4fLoadZero endp
fMat4fLoadIdentity proc uses esi lpfMat4f:dword
invoke fFillMatrix4f,lpfMat4f,0,FP4(1.0)
invoke fFillMatrix4f,lpfMat4f,1,FP4(0.0)
invoke fFillMatrix4f,lpfMat4f,2,FP4(0.0)
invoke fFillMatrix4f,lpfMat4f,3,FP4(0.0)
invoke fFillMatrix4f,lpfMat4f,4,FP4(0.0)
invoke fFillMatrix4f,lpfMat4f,5,FP4(1.0)
invoke fFillMatrix4f,lpfMat4f,6,FP4(0.0)
invoke fFillMatrix4f,lpfMat4f,7,FP4(0.0)
invoke fFillMatrix4f,lpfMat4f,8,FP4(0.0)
invoke fFillMatrix4f,lpfMat4f,9,FP4(0.0)
invoke fFillMatrix4f,lpfMat4f,10,FP4(1.0)
invoke fFillMatrix4f,lpfMat4f,11,FP4(0.0)
invoke fFillMatrix4f,lpfMat4f,12,FP4(0.0)
invoke fFillMatrix4f,lpfMat4f,13,FP4(0.0)
invoke fFillMatrix4f,lpfMat4f,14,FP4(0.0)
invoke fFillMatrix4f,lpfMat4f,15,FP4(1.0)
ret
fMat4fLoadIdentity endp
fMat4fTranslate proc uses esi lpfMat:dword,x:real4,y:real4,z:real4
LOCAL ftmp:real4
;this->matrix[12]=(this->matrix[0]*x)+(this->matrix[4]*y)+(this->matrix[8] *z)+(this->matrix[12]);
invoke fLoadMatrix4fToFPU,lpfMat,0
push x
fmul dword ptr[esp]
fstp dword ptr[esp]
pop ftmp
invoke fLoadMatrix4fToFPU,lpfMat,1
push y
fmul dword ptr[esp]
fadd ftmp
fstp dword ptr[esp]
pop ftmp
invoke fLoadMatrix4fToFPU,lpfMat,2
push z
fmul dword ptr[esp]
fadd ftmp
fstp dword ptr[esp]
pop ftmp
invoke fLoadMatrix4fToFPU,lpfMat,3
push ftmp
fadd dword ptr[esp]
fstp dword ptr[esp]
pop ftmp
invoke fFillMatrix4f,lpfMat,12,ftmp
;this->matrix[13]=(this->matrix[1]*x)+(this->matrix[5]*y)+(this->matrix[9] *z)+(this->matrix[13]);
invoke fLoadMatrix4fToFPU,lpfMat,4
push x
fmul dword ptr[esp]
fstp dword ptr[esp]
pop ftmp
invoke fLoadMatrix4fToFPU,lpfMat,5
push y
fmul dword ptr[esp]
fadd ftmp
fstp dword ptr[esp]
pop ftmp
invoke fLoadMatrix4fToFPU,lpfMat,6
push z
fmul dword ptr[esp]
fadd ftmp
fstp dword ptr[esp]
pop ftmp
invoke fLoadMatrix4fToFPU,lpfMat,7
push ftmp
fadd dword ptr[esp]
fstp dword ptr[esp]
pop ftmp
invoke fFillMatrix4f,lpfMat,13,ftmp
;this->matrix[14]=(this->matrix[2]*x)+(this->matrix[6]*y)+(this->matrix[10]*z)+(this->matrix[14]);
invoke fLoadMatrix4fToFPU,lpfMat,8
push x
fmul dword ptr[esp]
fstp dword ptr[esp]
pop ftmp
invoke fLoadMatrix4fToFPU,lpfMat,9
push y
fmul dword ptr[esp]
fadd ftmp
fstp dword ptr[esp]
pop ftmp
invoke fLoadMatrix4fToFPU,lpfMat,10
push z
fmul dword ptr[esp]
fadd ftmp
fstp dword ptr[esp]
pop ftmp
invoke fLoadMatrix4fToFPU,lpfMat,11
push ftmp
fadd dword ptr[esp]
fstp dword ptr[esp]
pop ftmp
invoke fFillMatrix4f,lpfMat,14,ftmp
ret
fMat4fTranslate endp
Finally I understood it. Thanks God. Its been 5 Years.
Quote from: Farabi on November 17, 2011, 01:41:02 AM
Quote from: daydreamer on November 16, 2011, 07:45:14 PM
why dont you try out SSE instruction for this Farabi, thats why they added them and xmm regs to hold matrices in
this is an example of rotating in parallel
Thanks, I'll try it out.
Hey, did you just use plain CPU? Not using DirectX or OpenGL? Looks cool, I can felt the depth illusion
its actually directdraw part of directx I use
but it can be combined with d3d also
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.
: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.
we bow to you, oh great graphics master (http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/77.gif)
Quote from: dedndave on November 19, 2011, 04:26:19 AM
we bow to you, oh great graphics master (http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/77.gif)
Im just joking dave :green
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:
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
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
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.
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
Im correcting some wrong formula. Most of the code above just tested and proven to be worked.