I wrote a small 3D-Engine.It is called Sprite3DReal.
Download:
http://hometown.aol.de/Gastmailing/S3DR_1_0.zip (92 kb)
I hope it is useful for somebody.

Sorry for my bad english.

regards
Stefan
Code: Select all
InitSprite()
InitSprite3D()
InitKeyboard()
OpenScreen(800,600,16,"Example 3")
S3DR_CreateZBuffer();must be called before Start3D() and S3DR_BeginReal3D()
LoadSprite(1,"box.bmp",#PB_Sprite_Texture)
Procedure S3DR_RotateAndZoom(radians.f,zoom.f)
x.f=Cos(radians)
y.f=Sin(radians)
S3DR_Draw3D(-y,x,zoom,x,y,zoom,-x,-y,zoom,y,-x,zoom)
EndProcedure
zoom.f=1
Repeat
Start3D()
S3DR_BeginReal3D()
S3DR_ClearScreenAndZBuffer(#black)
S3DR_UseTransparency(#S3DR_TRUE)
S3DR_SelectTexture(1)
radians.f+0.01:If radians>=2*3.14159265: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(radians,zoom)
S3DR_EndReal3D()
Stop3D()
FlipBuffers():Delay(15)
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
S3DR_FreeZBuffer()
It is possible but i think it is not very useful.Is it possible to add a collision check function?
Good idea, I will add a few commands for rotate/scale/translateAnd Rotate and Zoom ones?
Code: Select all
S3DR_TestCollision(O1X1.f,O1Y1.f,O1Z1.f,O1X2.f,O1Y2.f,O1Z2.f,O1X3.f,O1Y3.f,O1Z3.f,O1X4.f,O1Y4
,O1Z4.f,O2X1.f,O2Y1.f,O2Z1.f,O2X2.f,O2Y2.f,O2Z2.f,O2X3.f,O2Y3.f,O2Z3.f,O2X4.f,O2Y4,O2Z4.f)
Code: Select all
InitSprite()
InitSprite3D()
InitKeyboard()
OpenScreen(800,600,16,"TestCollision")
S3DR_CreateZBuffer()
LoadSprite(1,"Texture2.bmp",#PB_Sprite_Texture)
LoadSprite(2,"house.bmp",#PB_Sprite_Texture)
Start3D()
S3DR_BeginReal3D()
S3DR_SetCullMode(#S3DR_NONE)
S3DR_MoveCamera(-20,3,0)
S3DR_RotateCamera(ACos(-1)/2,0,0)
S3DR_UseFog(1,0,100,RGB(220,220,255))
S3DR_EndReal3D()
Stop3D()
Repeat
ExamineKeyboard()
Start3D()
S3DR_BeginReal3D()
S3DR_ClearScreenAndZBuffer(RGB(220,220,255))
If KeyboardPushed(#PB_Key_Left):S3DR_RotateCamera(-0.025,0,0):EndIf
If KeyboardPushed(#PB_Key_Right):S3DR_RotateCamera(0.025,0,0):EndIf
If KeyboardPushed(#PB_Key_Up):S3DR_MoveCamera(0,0,0.5):EndIf
If KeyboardPushed(#PB_Key_Down):S3DR_MoveCamera(0,0,-0.5):EndIf
DX.f+0.01
;Untergrung zeichen:
S3DR_SelectTexture(1)
S3DR_Draw3D(-20,0,20,20,0,20,-20,0,-20,20,0,-20)
S3DR_SelectTexture(2)
S3DR_Draw3D(5,5*Sin(DX),5,-5,5*Sin(DX),5,5,5,-5,-5,5,-5)
Result=S3DR_TestCollision(-20,0,20,20,0,20,-20,0,-20,20,0,-20,5,5*Sin(DX),5,-5,5*Sin(DX),5,5,5,-5,-
5,5,-5)
S3DR_EndReal3D()
Stop3D()
StartDrawing(ScreenOutput())
DrawingMode(1)
DrawingFont(GetStockObject_(#ANSI_FIXED_FONT))
If Result
DrawText("Collision: YES")
Else
DrawText("Collision: NO")
EndIf
StopDrawing()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()
Yes, i do.S.M. wrote:If you want an example code for an pixel-exact collision-detection for 3D Sprites, then just ask me.![]()
Code: Select all
- Commands for rotate/scale and translate the World-Matrix
- diffuse-color support
- Commands for changing FOV near- and far plane
- more Camera-functions
- extended fog-functions (EXP,EXP2,Intensity)
- VertexBuffer support (for faster rendering)
- A command for render triangles
- optimize commands (the commands S3DR_DrawBillboard(),S3DR_RotateCamera() and S3DR_MoveCamera() are slow)
- Antialiasing ?
- Lights ?
Nice to hear, Thanks.I know, you are the author of SpriteEx lib too.
I use your libs, because it are really fast, and seem well done.
Code: Select all
Structure DDPIXELFORMAT
dwSize.l
dwFlags.l
dwFourCC.l
dwRGBBitCount.l
dwRBitMask.l
dwGBitMask.l
dwBBitMask.l
dwRGBAlphaBitMask.l
EndStructure
Structure DDCOLORKEY
dwColorSpaceLowValue.l
dwColorSpaceHighValue.l
EndStructure
Structure DDSCAPS2
dwCaps.l
dwCaps2.l
dwCaps3.l
dwCaps4.l
EndStructure
Structure DDSURFACEDESC2
dwSize.l
dwFlags.l
dwHeight.l
dwWidth.l
lPitch.l
dwBackBufferCount.l
dwRefreshRate.l
dwAlphaBitDepth.l
dwReserved.l
lpSurface.l
ddckCKDestOverlay.DDCOLORKEY
ddckCKDestBlt.DDCOLORKEY
ddckCKSrcOverlay.DDCOLORKEY
ddckCKSrcBlt.DDCOLORKEY
ddpfPixelFormat.DDPIXELFORMAT
ddsCaps.DDSCAPS2
dwTextureStage.l
EndStructure
Structure PB_Sprite
Sprite.l
Width.w
Height.w
Depth.w
Mode.w
FileName.l
RealWidth.w
RealHeight.w
ClipX.w
ClipY.w
EndStructure
#DDSD_WIDTH=4
#DDSD_HEIGHT=2
#DDSD_CAPS=1
#DDSCAPS_3DDEVICE=8192
#DDSCAPS_OFFSCREENPLAIN=64
Global *D3DDevice.IDirect3DDevice7
Global *BackBuffer.IDirectDrawSurface7
Procedure CreateRenderSprite(Sprite,Width,Height)
Result=CreateSprite(Sprite,Width,Height)
If Result=0:ProcedureReturn 0:EndIf
*PBSprite.PB_Sprite=IsSprite(Sprite)
*DDS.IDirectDrawSurface7=*PBSprite\Sprite
*DDS\GetDDInterface(@*DD.IDirectDraw7)
*DDS\Release()
DDSD.DDSURFACEDESC2
DDSD\dwSize=SizeOf(DDSURFACEDESC2)
DDSD\dwFlags=#DDSD_WIDTH|#DDSD_HEIGHT|#DDSD_CAPS
DDSD\dwWidth=Width
DDSD\dwHeight=Height
DDSD\ddsCaps\dwCaps=#DDSCAPS_3DDEVICE|#DDSCAPS_OFFSCREENPLAIN
Result=*DD\CreateSurface(DDSD,*PBSprite,0)
If Result:ProcedureReturn 0:EndIf
ProcedureReturn *PBSprite\Sprite
EndProcedure
Procedure SelectRenderSprite(Sprite)
!extrn _PB_Direct3D_Device
!MOV Eax,[_PB_Direct3D_Device]
!MOV [p_D3DDevice],Eax
!extrn _PB_DirectX_BackBuffer
!MOV Eax,[_PB_DirectX_BackBuffer]
!MOV [p_BackBuffer],Eax
*D3DDevice\EndScene()
Select Sprite
Case -1
*D3DDevice\SetRenderTarget(*BackBuffer,2)
Default
*D3DDevice\SetRenderTarget(PeekL(IsSprite(Sprite)),2)
EndSelect
*D3DDevice\BeginScene()
EndProcedure
;Example:
InitSprite()
InitSprite3D()
InitKeyboard()
InitMouse()
OpenScreen(640,480,16,"Collision detection with 3D-Sprites")
CreateRenderSprite(0,181,181)
CreateRenderSprite(1,181,181)
TransparentSpriteColor(0,255,0,255)
TransparentSpriteColor(1,255,0,255)
LoadSprite(5,"C:\PureBASIC2\Examples\Sources\Data\GeeBee2.bmp",#PB_Sprite_Texture)
CreateSprite3D(5,5)
Repeat
ExamineKeyboard()
ExamineMouse()
ClearScreen(0,0,0)
UseBuffer(0)
ClearScreen(255,0,255);Clear Sprite 0
UseBuffer(1)
ClearScreen(255,0,255);Clear Sprite 1
UseBuffer(-1)
Start3D()
SelectRenderSprite(0);Draw the 3D-Sprite on Sprite 0
Angle1+2
RotateSprite3D(5,Angle1,0)
DisplaySprite3D(5,27,27)
SelectRenderSprite(1);Draw the 3D-Sprite on Sprite 1
Angle2-2
RotateSprite3D(5,Angle2,0)
DisplaySprite3D(5,27,27)
SelectRenderSprite(-1);Draw on Backbuffer
Stop3D()
DisplayTransparentSprite(0,MouseX(),MouseY())
DisplayTransparentSprite(1,200,100)
If SpritePixelCollision(0,MouseX(),MouseY(),1,200,100)
StartDrawing(ScreenOutput())
FrontColor(255,255,0)
DrawingMode(1)
DrawingFont(GetStockObject_(#ANSI_FIXED_FONT))
DrawText("Collision !")
StopDrawing()
EndIf
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
Wow ... 8O ... that sounds quite cool - good luck and I am looking forwardS.M. wrote:@benny
My To-Do-List:![]()
Code: Select all
- Commands for rotate/scale and translate the World-Matrix - diffuse-color support - Commands for changing FOV near- and far plane - more Camera-functions - extended fog-functions (EXP,EXP2,Intensity) - VertexBuffer support (for faster rendering) - A command for render triangles - optimize commands (the commands S3DR_DrawBillboard(),S3DR_RotateCamera() and S3DR_MoveCamera() are slow) - Antialiasing ? - Lights ?