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

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
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

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
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

qWord

hi,
what part is done by the GPU? - rotating and translating one vector?
FPU in a trice: SmplMath
It's that simple!

Farabi

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:
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

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.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

qWord

Using the GPU for some matrix multiplications doesn't sound plausible - but maybe I'm wrong.
FPU in a trice: SmplMath
It's that simple!

Farabi

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.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

http://ompldr.org/vYmFyaQ/OGLE.zip (5 MBytes, ouch)

Fixed the camera, I edited the code on the first post.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

dedndave

very cool, Farabi
how do i change my altitude ?

daydreamer

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

Farabi

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
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

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
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

#12
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.
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 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.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

daydreamer

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