Page 2 of 8

Posted: Sat Jan 29, 2005 1:18 am
by Shannara
Same here :)

Posted: Fri Feb 11, 2005 5:21 pm
by S.M.
It seems that a few articles were erased. :cry:
Here is my old article:

@Shannara
Yes, I added 2 commands:(Not documented at the moment)

Code: Select all

S3DR_SetCameraRangeAndFOV(Near.f,Far.f,FOV.f) ;FOV is in degree 
S3DR_SetDiffuseColors(Color1,Color2,Color3,Color4) 
I hope it is useful for you. :wink:
Download: http://hometown.aol.de/Gastmailing/S3DR_1_0.zip (129 KB)

Here is a short example for the new commands:

Code: Select all

InitSprite() 
InitSprite3D() 
InitKeyboard() 

OpenScreen(800,600,16,"Example for S3DR_SetCameraRangeAndFOV() and S3DR_SetDiffuseColors()") 

S3DR_CreateZBuffer() 

CreateSprite(1,64,64,#PB_Sprite_Texture) 
StartDrawing(SpriteOutput(1)) 
Box(0,0,64,64,#white) 
StopDrawing() 

Start3D() 
S3DR_BeginReal3D() 
S3DR_SetCullMode(#S3DR_NONE) 
S3DR_MoveCamera(0,5,0) 
S3DR_EndReal3D() 
Stop3D() 

Repeat 
  
  ExamineKeyboard() 
  
  Start3D() 
  S3DR_BeginReal3D() 
  
  S3DR_ClearScreenAndZBuffer(RGB(220,220,255)) 
  S3DR_SetCameraRangeAndFOV(1,1000,120) ;FOV is in degree 
  
  S3DR_SelectTexture(1) 
  S3DR_SetDiffuseColors(#red,#green,#white,#blue) 
  
  For c=0 To 9;Draws a Cylinder 
    a1.f=c/10*ACos(-1)*2 
    a2.f=(c+1)/10*ACos(-1)*2 
    T1.f=c/10 
    T2.f=c/10+1/10 
    S3DR_SetTextureCoordinates(T1,0,T2,0,T1,1,T2,1) 
    
    X1.f=Sin(a1)*100 
    Y1.f=50 
    Z1.f=Cos(a1)*100 
    X2.f=Sin(a2)*100 
    Y2.f=50 
    Z2.f=Cos(a2)*100 
    
    X3.f=Sin(a1)*100 
    Y3.f=0 
    Z3.f=Cos(a1)*100 
    X4.f=Sin(a2)*100 
    Y4.f=0 
    Z4.f=Cos(a2)*100 
    
    S3DR_Draw3D(X1.f,Y1.f,Z1.f,X2.f,Y2.f,Z2.f,X3.f,Y3.f,Z3.f,X4.f,Y4.f,Z4.f) 
  Next 
  S3DR_SetTextureCoordinates(0,0,1,0,0,1,1,1) 
  
  If KeyboardPushed(#PB_Key_Left):S3DR_RotateCamera(-0.02,0,0):EndIf 
  If KeyboardPushed(#PB_Key_Right):S3DR_RotateCamera( 0.02,0,0):EndIf 
  
  If KeyboardPushed(#PB_Key_Up):S3DR_MoveCamera(0,0,1):EndIf 
  If KeyboardPushed(#PB_Key_Down):S3DR_MoveCamera(0,0,-1):EndIf 
  
  S3DR_SetDiffuseColors(#green,0,0,#green) 
  
  For x=-100 To 100 Step 20 
    For z=-100 To 100 Step 20      
      S3DR_Draw3D(-10+x, 0, 10+z, 10+x, 0, 10+z,-10+x, 0,-10+z, 10+x, 0,-10+z) 
    Next 
  Next 
  
  S3DR_EndReal3D() 
  Stop3D() 
  
  FlipBuffers() 
  
  ExamineKeyboard() 
Until KeyboardPushed(#PB_Key_Escape) 

S3DR_FreeZBuffer() 

//Edit:
@dracflamloc
Any possiblilty of a linux version?
Sorry, it is not intended for now.


regards
Stefan

Posted: Wed Feb 16, 2005 4:27 am
by Shannara
Hmm, thanks for the update, but ... how the heck do we translate pixel location values to your 0.0 and 1.0 calculations?

Posted: Wed Feb 16, 2005 8:37 pm
by S.M.
Hi Shannara

Do you mean the texture coordinates ? :?
The value of a texture coordinate is from 0.0 to 1.0.
You can calculate the texture coordinate with that formula:

Code: Select all

tu.f=X.l/SpriteWidth.l  
tv.f=Y.l/SpriteHeight.l
here is a short example:

Code: Select all


#SpriteWidth=256
#SpriteHeight=256

InitSprite()
InitSprite3D()
InitKeyboard()

OpenScreen(800,600,16,"Texture coordinates")

S3DR_CreateZBuffer()

CreateSprite(1,#SpriteWidth,#SpriteHeight,#PB_Sprite_Texture)

StartDrawing(SpriteOutput(1))
Box(0,0,256,256,#green)
Circle(128,128,128,#red)
StopDrawing()

Repeat

Start3D()

S3DR_BeginReal3D()

S3DR_ClearScreenAndZBuffer(#blue)

S3DR_SelectTexture(1)


X1=10
Y1=10

X2=256-10
Y2=10

X3=10
Y3=256-10

X4=256-10
Y4=256-10

;convert the pixel-coordinates to texture-coordinates.
TU1.f=X1/#SpriteWidth  
TV1.f=Y1/#SpriteHeight

TU2.f=X2/#SpriteWidth
TV2.f=Y2/#SpriteHeight

TU3.f=X3/#SpriteWidth
TV3.f=Y3/#SpriteHeight

TU4.f=X4/#SpriteWidth
TV4.f=Y4/#SpriteHeight


; tu1,tv1     tu2,tv2
;    +---------+
;    |         |
;    |         |
;    |         |
;    |         |
;    |         |
;    +---------+
; tu3,tv3     tu4,tv4
 

S3DR_SetTextureCoordinates(TU1.f,TV1.f,TU2.f,TV2.f,TU3.f,TV3.f,TU4.f,TV4.f)

;             X1  Y1  Z1  X2  Y2  Z2  X3  Y3  Z3  X4  Y4  Z4
S3DR_Draw3D(  -1,  1,  5,  1,  1,  5, -1, -1,  5,  1, -1,  5);draws the selected sprite
  
S3DR_EndReal3D()

Stop3D()

FlipBuffers()

ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)

S3DR_FreeZBuffer()


I hope I understood you right. :roll:

regards
Stefan

Posted: Thu Feb 17, 2005 1:58 am
by Shannara
I think this is correct, I merged the two codes above, the resulting code is pasted below. Had to change the #<color> values to the actual rgb values because this library would black out everything that was not green. So when I replaced those constants, the colors actually show on the texture :) However, when running the following code, you will notice the reg and blue values pixelate the texture horribly. making huge chunky blocks of different colors, instead of a smooth gradient :) I'm going to test it up against an actual textured picture to see how it looks ...

Also, I noticed that there is no need to create a 3Dsprite from a 2dsprite if using this library .... ... sweet!

Code: Select all

#SpriteWidth=256
#SpriteHeight=256

InitSprite()
InitSprite3D()
InitKeyboard()

OpenScreen(800,600,16,"Texture coordinates")

S3DR_CreateZBuffer()

CreateSprite(1,#SpriteWidth,#SpriteHeight,#PB_Sprite_Texture)

StartDrawing(SpriteOutput(1))
Box(0,0,256,256,RGB(255,255,255))
StopDrawing()

Repeat
  
  Start3D()
  
  S3DR_BeginReal3D()
  
  S3DR_ClearScreenAndZBuffer(#blue)
  
  S3DR_SelectTexture(1)
  S3DR_SetDiffuseColors(RGB(0,255,0),RGB(255,0,0),RGB(0,0,255),RGB(0,0,0))
  
  X1=10
  Y1=10
  
  X2=256-10
  Y2=10
  
  X3=10
  Y3=256-10
  
  X4=256-10
  Y4=256-10
  
  ;convert the pixel-coordinates to texture-coordinates.
  TU1.f=X1/#SpriteWidth 
  TV1.f=Y1/#SpriteHeight
  
  TU2.f=X2/#SpriteWidth
  TV2.f=Y2/#SpriteHeight
  
  TU3.f=X3/#SpriteWidth
  TV3.f=Y3/#SpriteHeight
  
  TU4.f=X4/#SpriteWidth
  TV4.f=Y4/#SpriteHeight
  
  
  ; tu1,tv1     tu2,tv2
  ;    +---------+
  ;    |         |
  ;    |         |
  ;    |         |
  ;    |         |
  ;    |         |
  ;    +---------+
  ; tu3,tv3     tu4,tv4
  
  
  S3DR_SetTextureCoordinates(TU1.f,TV1.f,TU2.f,TV2.f,TU3.f,TV3.f,TU4.f,TV4.f)
  
  ;             X1  Y1  Z1  X2  Y2  Z2  X3  Y3  Z3  X4  Y4  Z4
  S3DR_Draw3D(  -1,  1,  5,  1,  1,  5, -1, -1,  5,  1, -1,  5);draws the selected sprite
  
  S3DR_EndReal3D()
  
  Stop3D()
  
  FlipBuffers()
  
  ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)

S3DR_FreeZBuffer() 

Posted: Thu Feb 17, 2005 2:04 am
by Shannara
I can provide the textured image file I used, but it turns out the library stretches out the texture really wide (then the normal 256x256), and while doing this, it repeats existing pixels over, basically bleeding them. So a 32x32 tile on a 256x256 tileset, will be bled over a couple of tiles.

PM me if you want me to email you the texture used.

Posted: Thu Feb 17, 2005 7:08 pm
by S.M.
Hi Shannara
I think this is correct, I merged the two codes above, the resulting code is pasted below. Had to change the #<color> values to the actual rgb values because this library would black out everything that was not green. So when I replaced those constants, the colors actually show on the texture However, when running the following code, you will notice the reg and blue values pixelate the texture horribly. making huge chunky blocks of different colors, instead of a smooth gradient I'm going to test it up against an actual textured picture to see how it looks ...
You've right, it looks very ugly. :shock:
You can solve the problem by using a dither.

Code: Select all

S3DR_UseDither(#S3DR_TRUE)
Or you use the 32-Bit Screenmode... :wink:
Also, I noticed that there is no need to create a 3Dsprite from a 2dsprite if using this library .... ... sweet!
That's true, but you need to create the sprite with the flag #PB_Sprite_Texture. :)

regards
Stefan

Posted: Thu Feb 17, 2005 8:25 pm
by Psychophanta
Stefan,
I notice you add S3DR_FreeZBuffer() function at the end of all progs.
Can you do that it is made automatically when program ending is reached?

Posted: Fri Feb 18, 2005 8:10 pm
by S.M.
@Psychophanta
I notice you add S3DR_FreeZBuffer() function at the end of all progs.
Can you do that it is made automatically when program ending is reached?
Yes, i will add this feature. :D

@Shannara
Can you test this code:

Code: Select all

InitSprite()
InitSprite3D()
InitKeyboard()

OpenScreen(800,600,16,"Texture coordinates")

S3DR_CreateZBuffer()

LoadSprite(1,"base1.bmp",#PB_Sprite_Texture)

Repeat
  
  Start3D()
  S3DR_BeginReal3D()
  S3DR_ClearScreenAndZBuffer(#blue)
  
  S3DR_SelectTexture(1)  
  S3DR_Draw3D(  -1,  1,  5,  1,  1,  5, -1, -1,  5,  1, -1,  5)  
  S3DR_EndReal3D()
  
  Stop3D()
  
  FlipBuffers()
  
  ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)

S3DR_FreeZBuffer() 
Does it have the same result ?

regards
Stefan

Posted: Sat Feb 19, 2005 5:29 pm
by Shannara
Thanks for the sample, the results are still the same.

Posted: Sun Feb 20, 2005 5:53 pm
by S.M.
@Shannara
Can you send me a snapshot ?

regards
Stefan

Posted: Mon Feb 21, 2005 6:15 am
by Shannara
Hmm, do you know of a full screen screenshot program that works with windows xp, sp2? With SP2, microsoft was dumb enough to remove the ability to take screenshots of directx screens (both windows and full screen), so for those tons of screeshot programs (like fraps), that rely on the OS to take screenshots, are broken with SP2.

The PB grabsprite/savesprite only works for windowed and not fullscreen mode. (it only returns a blank black screen for full screen).

Posted: Mon Feb 21, 2005 8:30 pm
by S.M.
Hi Shannara
Hmm, do you know of a full screen screenshot program that works with windows xp, sp2? With SP2, microsoft was dumb enough to remove the ability to take screenshots of directx screens (both windows and full screen), so for those tons of screeshot programs (like fraps), that rely on the OS to take screenshots, are broken with SP2.
No , the most time I use the print-key for snapshots. :roll:

Why you don't use the windowed mode for the snapshot ?
It should have the same result as in fullscreenmode.

Code: Select all

InitSprite() 
InitSprite3D() 
InitKeyboard() 

OpenWindow(1,0,0,640,480,#PB_Window_ScreenCentered,"Snapshot")
OpenWindowedScreen(WindowID(),0,0,640,480,0,0,0)

S3DR_CreateZBuffer() 

LoadSprite(1,"base1.bmp",#PB_Sprite_Texture) 
  
Start3D() 
S3DR_BeginReal3D() 
S3DR_ClearScreenAndZBuffer(#blue) 
  
S3DR_SelectTexture(1)  
S3DR_Draw3D(  -1,  1,  5,  1,  1,  5, -1, -1,  5,  1, -1,  5)  
S3DR_EndReal3D() 
  
Stop3D() 

GrabSprite(2,0,0,640,480) 
SaveSprite(2,"snapshot.bmp")

S3DR_FreeZBuffer() 
The reason for the black image in fullscreenmode could be that you forgot to comment out FlipBuffers(). :?:

regards
Stefan

Posted: Mon Feb 21, 2005 9:11 pm
by Shannara
Heh, works great with flipbuffers w/o the library commands, aka w/ sprite/sprite3d, Anyways, here's the screenie :)

http://www.japbe.com/real3d.png

Posted: Tue Feb 22, 2005 6:14 pm
by Psychophanta
Stefan,
As a request, i ask for a collision detection function and documentation of it. Before you abandon this lib, please. :)