Now it's not possible to detect rotated sprites3d collision

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Now it's not possible to detect rotated sprites3d collision

Post by Psychophanta »

Code: Select all

bitplanes.b=32:RX.w=1024:RY.w=768:#PI=3.14159265
InitMouse():InitSprite():InitKeyboard():InitSprite3D()
OpenScreen(RX.w,RY.w,bitplanes.b,"Balls")

CreateSprite(0,64,64,#PB_Sprite_Texture)
StartDrawing(SpriteOutput(0))
BackColor(0,0,0)
Box(0,0,64,64,$AAAAAA)
StopDrawing()
CreateSprite3D(0,0):ZoomSprite3D(0,64,64)
CreateSprite(1,128,128,#PB_Sprite_Texture)
StartDrawing(SpriteOutput(1))
BackColor(0,0,0)
Box(0,0,128,128,$AA88AA)
StopDrawing()
CreateSprite3D(1,1):ZoomSprite3D(1,128,128)

;-MAIN:
Repeat
  ExamineKeyboard()
  ExamineMouse()
  ClearScreen(0,0,0)
  s0x.f=MouseX():s0y.f=MouseY()
  s1x.f=400:s1y.f=400
  If SpritePixelCollision(0,s0x,s0y,1,s1x,s1y)
    Beep_(600,10)
  EndIf
  If MouseButton(1):s0angle.f+1:RotateSprite3D(0,s0angle,0):EndIf
  If MouseButton(2):s1angle.f+1:RotateSprite3D(1,s1angle,0):EndIf
  Start3D()
  DisplaySprite3D(0,s0x,s0y,255)
  DisplaySprite3D(1,s1x,s1y,255)
  Stop3D()
  FlipBuffers():Delay(15)
Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()
Return
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
MadMax
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Oct 06, 2003 11:56 am

Post by MadMax »

It is posible to detect collisions, although you need to use a trick, same as always.

Code: Select all

If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
  MessageRequester("Error", "Can't open DirectX 7 Or later", 0)
  End
EndIf

InitSprite3D()

pi.f=3.14159265
ra.f=(2*pi)/360

fps.f=85
gfps.f=85
rfps.f=1

infoon=1

x=0
y=0

ang3d=0

hit=0
  
If OpenScreen(640,480,16,"Dabidu")

CatchSprite(0,?gcursor)
CatchSprite(1,?gflecha,#PB_Sprite_Texture)
CreateSprite3D(1,1)

    fpss=GetTickCount_()
 

 Repeat
    
    FlipBuffers(1)
    
    ClearScreen(0,0,0)
     Start3D()
 
      DisplaySprite3D(1, 250, 200, 255)
      RotateSprite3D(1,ang3d,0)
       
    Stop3D()
     
GrabSprite(5,250,200,128,128,0)

ClearScreen(0,80,0)   
;========================================================================================
;                 FPS
;======================================================================================== 
    conta=conta+1
    ;fpsss=gettickcount_()

  If GetTickCount_()=>fpss+1000
   fpss=GetTickCount_()
   fps=conta
   rfps=gfps/fps
   conta=0
  EndIf
;=========================================================================================
;=========================================================================================

 
   
    Start3D()
 
      DisplaySprite3D(1, 250, 200, 255)
      RotateSprite3D(1,ang3d,0)
       
    Stop3D()
     
;GrabSprite(5,250,200,128,128,0)

ExamineMouse()
mx=MouseX()
my=MouseY()

DisplayTransparentSprite(0,mx,my)

If SpritePixelCollision(0,mx,my,5,250,200)
hit=1
Else
hit=0
EndIf

;=========================================================================================
;                 PRINT TEXT
;========================================================================================= 

If infoon=1
pepeID=ScreenOutput()
  
 StartDrawing(pepeID)
 
   FrontColor(255,255,255)
   DrawingMode(1)
   Locate(20,20)
   DrawText("Image: "+StrF(fps))
   FrontColor(255,0,0)
   ;Locate(20,40)
   ;DrawText("Angulo: "+StrF(ang3d))
   Locate(20,60)
   If hit
   DrawText("HIT!!!")
   EndIf 
   
 StopDrawing()
EndIf

;=========================================================================================
;=========================================================================================   
     

;=========================================================================================
;               KEYBOARD INPUT
;=========================================================================================     
    ExamineKeyboard()
    
If KeyboardPushed(#PB_Key_right)
ang3d=(ang3d+1) % 360 
EndIf

If KeyboardPushed(#PB_Key_left)
ang3d=(ang3d-1) % 360
EndIf

    
    
If KeyboardReleased(#PB_Key_F1)

  Select infoon
  
    Case 0
    
    infoon=1
    
    Case 1
    
    infoon=0
    
  EndSelect
  
EndIf


;=========================================================================================
;=========================================================================================    
 Until KeyboardPushed(#PB_Key_Escape)
  
Else
  MessageRequester("Error", "Can't open a 640*480 - 16 bit screen !", 0)
EndIf

End   

gflecha:IncludeBinary "flecha.bmp"
gcursor:IncludeBinary "Data\cursor.bmp"
here links to the graphics

http://personal.telefonica.terra.es/web ... flecha.bmp
http://personal.telefonica.terra.es/web ... cursor.bmp

Hope this helps
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Thanks, it helps at the moment. I'll use SpriteEx lib from S. Moebious. It is faster copying graph info from a screen zone to a sprite. :wink:

However, this is not a clean way :?
http://www.zeitgeistmovie.com

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