Page 4 of 8

Posted: Sun May 15, 2005 1:10 pm
by Psychophanta
Shanara, perhaps the matter is the zoom parameters for S3DR_Draw3D(), i don't know :?

I rebuilt my S3DR_RotateAndZoom routine. I made it in ASM because my programs are usually speed-critical.
Here it is, it could be useful :)

Code: Select all

InitSprite()
InitSprite3D()
InitKeyboard()
#PI=3.14159265
OpenScreen(1024,768,32,"Example 3")

S3DR_CreateZBuffer();must be called before Start3D() and S3DR_BeginReal3D()

LoadSprite(1,"yourspritehere.BMP",#PB_Sprite_Texture)

!extrn PB_S3DR_SelectTexture
!extrn PB_S3DR_Draw3D
x.f:y.f:mx.f:my.f
!macro S3DR_RotateAndZoom SpriteID,rad,z{
  !fld dword[v_#rad]
  !fchs; -radians
  !fldpi; PI
  !fld1  ; 1
  !fadd st0,st0; 2
  !fmul st0,st0; 4
  !fdivp st1,st0; PI/4
  !fsubp st1,st0; -radians-PI/4
  !fsincos;   cos(-radians-PI/4) and sin(-radians-PI/4)
  !fst dword[v_x]
  !fchs
  !fstp dword[v_mx]
  !fst dword[v_y]
  !fchs
  !fstp dword[v_my]
  !mov eax,SpriteID
  !call PB_S3DR_SelectTexture
  !push dword[v_#z] dword[v_mx] dword[v_y] dword[v_#z] dword[v_my] dword[v_mx] dword[v_#z] dword[v_y] dword[v_x] dword[v_#z] dword[v_x]
  !fld dword[v_my]
  !call PB_S3DR_Draw3D
  !}

zoom.f=5
Repeat  
  Start3D()
  S3DR_BeginReal3D()
  S3DR_ClearScreenAndZBuffer(#black)
  S3DR_UseTransparency(#S3DR_TRUE)

  radians.f+0.01:If radians>=2*#PI:radians=0:EndIf
  If zoom>=50:zi.b=0:ElseIf zoom<=1:zi.b=1:EndIf
  If zi.b:zoom+0.1:Else:zoom-0.1:EndIf
  
  !S3DR_RotateAndZoom 1,radians,zoom

  S3DR_EndReal3D()
  Stop3D()
  FlipBuffers():Delay(16)
  ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
I will test S3DR_TestCollision() hardly for accuracy and speed behaviour when i have a little time :)

Posted: Sun May 15, 2005 5:26 pm
by Shannara
Ah I see, i think. So if I set zoom to 0, so it will not zoom (which it shouldnt by default anyways), then it'll show the texture properly? Another funny thing is that the x,y values for placing the texture doesnt work. Ah well.

Posted: Sun May 15, 2005 7:01 pm
by Psychophanta
Shannara wrote:Ah I see, i think. So if I set zoom to 0, so it will not zoom (which it shouldnt by default anyways), then it'll show the texture properly? Another funny thing is that the x,y values for placing the texture doesnt work. Ah well.
Right, this is very simple done, and in fact not useful since S3DR_DrawMesh() existence. :?
I'd try to complete it, but i don't like to reinvent wheel, we can use S3DR_DrawMesh() to positionate, zoom, and rotate in 3D space a figure now :)

BTW, i think there is a bug in S3DR_DrawMesh(), because RotateX.f and RotateY.f seem to be swapped :!:

Posted: Mon May 16, 2005 6:22 pm
by benny
@S.M.:

I really do like this lib and your work in general. Nice to see that you are
sitll on it :!: Well done 8)

Posted: Mon May 16, 2005 7:04 pm
by S.M.
@Psychophanta
Psychophanta wrote:BTW, i think there is a bug in S3DR_DrawMesh(), because RotateX.f and RotateY.f seem to be swapped
Are you sure ? According to my opinion it works correctly. :?

@benny
Thanks benny, nice to hear :D

regards
Stefan

Posted: Mon May 16, 2005 7:13 pm
by Psychophanta
S.M. wrote:
Psychophanta wrote:BTW, i think there is a bug in S3DR_DrawMesh(), because RotateX.f and RotateY.f seem to be swapped
Are you sure ? According to my opinion it works correctly. :?
Lets see, in your mesh2.pb example, if replaced the line
S3DR_DrawMesh(Cube,0,0,0,angle,angle,angle)
by
S3DR_DrawMesh(Cube,0,0,0,0,0,angle)
then it rotates around Z axis, it's ok.
then replace it by
S3DR_DrawMesh(Cube,0,0,0,0,angle,0)
the cube rotates around X axis, Is this the correct?
and if replaced by
S3DR_DrawMesh(Cube,0,0,0,angle,0,0)
then the cube rotates around Y axis, so is it a bug or it is correct?

Posted: Mon May 16, 2005 8:07 pm
by S.M.
Hi
You are right Psychophanta.(At least If DirectX makes it correct :lol: )
Thank you very much Psychophanta, you're great ! :D

Code: Select all

Procedure RotatePoint3DX(X.f,Y.f,Z.f,RotX.f,OutX,OutY,OutZ)
  PokeF(OutX,X)
  PokeF(OutY,Y * Cos(RotX) + Z * -Sin(RotX))
  PokeF(OutZ,Y * Sin(RotX) + Z *  Cos(RotX))
EndProcedure

InitSprite()
InitSprite3D()
InitKeyboard()

OpenScreen(800,600,16,"Rotate around the x-axis")

S3DR_CreateZBuffer() ;must be called before Start3D() and S3DR_BeginReal3D()

CreateSprite(1,256,256,#PB_Sprite_Texture)

StartDrawing(SpriteOutput(1))
Circle(128,128,128,#blue)
DrawingMode(1)
DrawingFont(LoadFont(1,"Arial Black",24))
FrontColor(255,255,0)
Locate(5,90)
DrawText("Rotate around")
Locate(30,130)
DrawText("the x-axis")
StopDrawing()

Start3D()
S3DR_BeginReal3D()
S3DR_MoveCamera(0,0,-5)
S3DR_EndReal3D()
Stop3D()



Repeat
  
  Start3D()
  
  S3DR_BeginReal3D()
  S3DR_ClearScreenAndZBuffer(#black)
  
  S3DR_SelectTexture(1)
  S3DR_SetCullMode(#S3DR_NONE)
  
  If KeyboardPushed(#PB_Key_Left):S3DR_RotateCamera(-0.05,0,0):EndIf
  If KeyboardPushed(#PB_Key_Right):S3DR_RotateCamera( 0.05,0,0):EndIf
  
  If KeyboardPushed(#PB_Key_Up):S3DR_MoveCamera(0,0,0.1):EndIf
  If KeyboardPushed(#PB_Key_Down):S3DR_MoveCamera(0,0,-0.1):EndIf
  
  Angle.f+0.01
  
  RotatePoint3DX(-1, 1,0,Angle,@X1.f,@Y1.f,@Z1.f)
  RotatePoint3DX( 1, 1,0,Angle,@X2.f,@Y2.f,@Z2.f)
  RotatePoint3DX(-1,-1,0,Angle,@X3.f,@Y3.f,@Z3.f)
  RotatePoint3DX( 1,-1,0,Angle,@X4.f,@Y4.f,@Z4.f)
  
  S3DR_Draw3D(X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3,X4,Y4,Z4);draws the selected sprite
  
  S3DR_EndReal3D()
  Stop3D()
  
  FlipBuffers()
  
  ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
BTW, The OGRE-Engine does it also wrong. :roll:

regards
Stefan

Posted: Mon May 16, 2005 8:14 pm
by Psychophanta
:wink: :arrow: as a reward i request you to continue allowing me using and enjoing Direct3D without directly touching DirectX stuff :)

Posted: Wed May 18, 2005 7:42 am
by S.M.
Hi
Psychophanta wrote: :wink: :arrow: as a reward i request you to continue allowing me using and enjoing Direct3D without directly touching DirectX stuff :)
:lol:
What's DirectX ? :wink:

The example above is now DirectX free. 8)
regards
Stefan

Posted: Wed May 18, 2005 8:47 am
by Psychophanta
S.M. wrote:Hi
lol:
What's DirectX ? :wink:
The example above is now DirectX free. 8)
Yeah! how must be :wink: :D

Posted: Sat Jun 04, 2005 5:00 pm
by S.M.
Hi
@Psychophanta
The bug is now corrected and a few other things are improved.
Link:S3DR v1.3b

A few screenshots of the Library: :D
ImageImageImageImage

regards
Stefan

Posted: Sat Jun 04, 2005 5:36 pm
by Psychophanta
S.M. wrote:Hi
@Psychophanta
The bug is now corrected and a few other things are improved.
Link:S3DR v1.3b
regards
Stefan
Wow :!: :D
Thanx! Just now i was on it, and verifying in your web for a possible newer revision. 8)
eehm! how can I create s3dr meshes? or how can i create .x files (just ones which you use to convert to .s3dr) ?

S3DR help says S3DR_FreeMesh(Mesh) must be inside of a S3DR_BeginReal3D()...S3DR_EndReal3D() block but in your examples it is after S3DR_EndReal3D() :!:
By the way, i've noticed there is necessary to free the meshes in reverse order how it was created, so; can you remove this need and so then remove S3DR_FreeMesh(Mesh) function from lib ??

Posted: Sun Jun 05, 2005 11:18 am
by S.M.
Hi
Psychophanta wrote:Just now i was on it, and verifying in your web for a possible newer revision.
Funny, i updated the page only 5 minutes before you wrote this post :D
Psychophanta wrote: eehm! how can I create s3dr meshes? or how can i create .x files (just ones which you use to convert to .s3dr) ?
I use the Conv3ds.exe tool from the DirectX SDK to convert .3ds Models into .x format.
The problem with my CONV2S3DR.EXE tool is that it fails with some models.
There is also the new BlockCretor tool in the package for creating primitve models.However, there is no exporter for the .s3dr format at the moment.
Psychophanta wrote: S3DR help says S3DR_FreeMesh(Mesh) must be inside of a S3DR_BeginReal3D()...S3DR_EndReal3D() block but in your examples it is after S3DR_EndReal3D()
You're right, it don't need to be in a S3DR_BeginReal3D()...S3DR_EndReal3D() block.I will correct this. :wink:
Psychophanta wrote: By the way, i've noticed there is necessary to free the meshes in reverse order how it was created
How do you noticed that ?
It should make no difference, but I read already the same somewhere on msdn.com.
Psychophanta wrote: can you remove this need and so then remove S3DR_FreeMesh(Mesh) function from lib ??
I will try.(It's not as easy as it sounds, because it would create new problems :roll: )

regards
Stefan

Posted: Sun Jun 05, 2005 11:24 am
by Psychophanta
S.M. wrote:Psychophanta wrote:

By the way, i've noticed there is necessary to free the meshes in reverse order how it was created

How do you noticed that ?
Here, the system halts when i create 2 meshes and free them in the same order than i created them. But if I do it in reversed (LIFO) order all works fine.

Posted: Sun Jun 05, 2005 11:38 am
by Psychophanta
Sorry, dunno why, but today it works disregarding the order. Yesterday was too late, maybe there was something i didn't watch. :oops:
By the way, please: Are there a way to increase/decrease the size of a created mesh on runtime? I mean no zoom or camera movs, but mesh size.