Sprite3DReal Userlibrary

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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 :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post 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.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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 :!:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
benny
Enthusiast
Enthusiast
Posts: 465
Joined: Fri Apr 25, 2003 7:44 pm
Location: end of www
Contact:

Post 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)
regards,
benny!
-
pe0ple ar3 str4nge!!!
S.M.
Enthusiast
Enthusiast
Posts: 118
Joined: Sat Apr 24, 2004 1:11 pm
Contact:

Post 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
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
S.M.
Enthusiast
Enthusiast
Posts: 118
Joined: Sat Apr 24, 2004 1:11 pm
Contact:

Post 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
Last edited by S.M. on Wed May 18, 2005 7:35 am, edited 1 time in total.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

:wink: :arrow: as a reward i request you to continue allowing me using and enjoing Direct3D without directly touching DirectX stuff :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
S.M.
Enthusiast
Enthusiast
Posts: 118
Joined: Sat Apr 24, 2004 1:11 pm
Contact:

Post 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
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
S.M.
Enthusiast
Enthusiast
Posts: 118
Joined: Sat Apr 24, 2004 1:11 pm
Contact:

Post 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
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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 ??
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
S.M.
Enthusiast
Enthusiast
Posts: 118
Joined: Sat Apr 24, 2004 1:11 pm
Contact:

Post 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
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply