Collision Sprite3d Alphablending

Advanced game related topics
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Collision Sprite3d Alphablending

Post by Truth_Seeker »

Anyone have any ideas how to do collision detection with sprite3d that use the alphablending tag? The only idea I can think of is to make 2 images. First one is the alphablended one and the second is the transparent one for the collision. But there has to be a better way ;).

Although this I guess is not that important, anyone know how to color a sprite3d object? Like for example I have a greyscale image and I can set it to what ever color I want. Kinda like what they do for 2d particle engines.

Or should we just not worry about the sprite3d and 2d and start focusing on Ogre and 3d? Since I am sure 3d (even if made to look 2d with billboards and stuff) is probably the future for games since computers and graphics cards are getting faster and faster.
Thanks
Truth Seeker
Fred
Administrator
Administrator
Posts: 18254
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

BTW, with the v4 you have an othographic mode which should work to display 3D meshes on a 2D screen (ie: without the camera deformation). It can be used for a 3D isometric game for example.
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

Sounds good. :)
Thanks
Truth Seeker
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Fred wrote:BTW, with the v4 you have an othographic mode which should work to display 3D meshes on a 2D screen (ie: without the camera deformation). It can be used for a 3D isometric game for example.
Uh :shock: ?

Please, tell more :lol:
Fred
Administrator
Administrator
Posts: 18254
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

You can test this, and move the robot with the up/down arrows. There is no deformations at all.

Code: Select all

;
; ------------------------------------------------------------
;
;  Orthographic example
;
; ------------------------------------------------------------
;

#CameraSpeed = 10

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()

  Add3DArchive("Data\", #PB_3DArchive_FileSystem)
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    WorldShadows(#PB_Shadow_Additive) ; Set the shadow mode for the world
    
    AmbientColor(RGB(128,128,128))
    
    ; Create a plan, manually
    ;
    CreateMesh(1,100)
    SetMeshData(1, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate, ?PlanVertices, 4)
    SetMeshData(1, #PB_Mesh_Face, ?PlanFaces, 2)
    
    LoadMesh   (0, "Robot.mesh")
    LoadTexture(0, "r2skin.jpg")
    
    CreateEntity (0, MeshID(0), CreateMaterial(0, TextureID(0)))
    AnimateEntity(0, "Walk")

    CreateMaterial(1, LoadTexture(1, "Background.png"))
    CreateEntity (1, MeshID(1), MaterialID(1))
    
    EntityRenderMode(1, 0) ; Disable shadow casting for this entity as it's our plan
    ScaleEntity(1, 1000, 1, 1000)
    MoveEntity(1, -500, 0, -500)
    DisableMaterialLighting(1, #False)
    
    CreateLight(0, RGB(255,255,255))
    
    CreateCamera(0, 0, 0, 100, 100)
    CameraLocate(0, 2000, 2000, 2000) ; 3D iso view
    CameraLookAt(0, 0, 0, 0)
    
    ResizeEntity(0, 4, 4, 4)
    
    CameraProjection(0, #PB_Camera_Orthographic)
    
    LightLocate(0, CameraX(0), CameraY(0), CameraZ(0))
      
    Repeat
      Screen3DEvents()
      
      ClearScreen(RGB(0, 0, 0))
            
      If ExamineKeyboard()
        
        If KeyboardPushed(#PB_Key_Up)
          EntityLocate(0, ex, 0, 0)
          ex+3
        EndIf
        
        If KeyboardPushed(#PB_Key_Down)
          EntityLocate(0, ex, 0, 0)
          ex-3
        EndIf


      EndIf
      
      If ExamineMouse()
        MouseX = -(MouseDeltaX()/10)*#CameraSpeed/2
        MouseY = -(MouseDeltaY()/10)*#CameraSpeed/2
      EndIf
            
      RenderWorld()      
        
      Screen3DStats()
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
    
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
  
End

DataSection

  PlanVertices:
    
    ; Note normals are important component to allow correct light support (and therefore shadow)
    ;
    Data.f 0, 0, 0    ; Vertex 0
    Data.f 1, 1, 1    ; Normals (perpendicular to the plan)
    Data.f 0   , 0.33 ; UVCoordinate
    
    Data.f 1, 0, 0    ; Vertex 1
    Data.f 1,1,1      ; Normals
    Data.f 0.33, 0.33 ; UVCoordinate
    
    Data.f 1, 0, 1    ; Vertex 2
    Data.f 1,1,1      ; Normals
    Data.f 0.33, 0    ; UVCoordinate
    
    Data.f 0, 0, 1    ; Vertex 3
    Data.f 1,1,1      ; Normals
    Data.f 0,    0    ; UVCoordinate

  PlanFaces:
    Data.w 2, 1, 0 ; bottom face (clockwise as it's reversed...)
    Data.w 0, 3, 2 

EndDataSection
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

I noticed you had to make a plane for the robot to "walk on". Does ogre not have primitive objects built in? If ogre does not could you make it so it does? Example of primitives would be a Sphere, Box, Plane, Pyramid, and stuff like that.

Standard Primitives
Image
Thanks
Truth Seeker
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

@Fred, your example only works with the debugger disabled here. This line always throws an error:

Code: Select all

CreateMaterial(1, LoadTexture(1, "Background.png"))
Texture is null.
--Kale

Image
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

Kale I had that problem too. Here is how you fix it: open up your image editor and save the background.bmp to a background.png.

Remove this code:

Code: Select all

        If KeyboardPushed(#PB_Key_Up)
          EntityLocate(0, ex, 0, 0)
          ex+3
        EndIf
       
        If KeyboardPushed(#PB_Key_Down)
          EntityLocate(0, ex, 0, 0)
          ex-3
        EndIf 
Add this code to make the robot be able to walk all over the plane:

Code: Select all

        If KeyboardPushed(#PB_Key_Up)
          EntityLocate(0, ex, 0, ey)
          ex+3
        EndIf
       
        If KeyboardPushed(#PB_Key_Down)
          EntityLocate(0, ex, 0, ey)
          ex-3
        EndIf
        
        If KeyboardPushed(#PB_Key_Left)
          EntityLocate(0, ex, 0, ey)
          ey-3
        EndIf
       
        If KeyboardPushed(#PB_Key_Right)
          EntityLocate(0, ex, 0, ey)
          ey+3
        EndIf
Thanks
Truth Seeker
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Truth_Seeker wrote:Kale I had that problem too. Here is how you fix it: open up your image editor and save the background.bmp to a background.png.
Aha! of course 'background.png' doesn't exist! :oops:
--Kale

Image
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

Back to the collision detection with Sprite3d alphablended sprites, all you have to do is make 2 images. First one is for blending and the second one is used for collision checking. Second one is basicly a transparent sprite which we dont display but use it kinda like a mask (dont know how else to explain it). Probably this is too slow if anyone else has any ideas please let me know.
Thanks
Truth Seeker
Fred
Administrator
Administrator
Posts: 18254
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

if you don't zoom nor rotate the sprite, you could use the regular spritecollision routine which should work.
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

Well it does not work with alphablending. When I save the png with transparency in photoshop it looks like this:
Image

By the way if your using firefox it supports alphablending so the image will look perfect as it should. But if you open it with paint you will see it is messed up looking. As far as I understand, SpritePixelCollision() will not work, the normal SpriteCollision() will because it just uses the whole image. See what I mean or am I not explaining this correctly?
Thanks
Truth Seeker
Fred
Administrator
Administrator
Posts: 18254
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

No, you're right. A new collision based on the alpha component would be better in this case (for example with a defined level above the which it collides).
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

Well I do not know how to do that, so using the way I said ealier is my only option for doing what I want. Unless maybe after you release v4 of PB you might make a collision procedure that can handle alpha sprites.
Thanks
Truth Seeker
Preludian
User
User
Posts: 17
Joined: Thu Apr 27, 2006 7:01 pm
Location: lovely Bonn

Post by Preludian »

Fred wrote:No, you're right. A new collision based on the alpha component would be better in this case (for example with a defined level above the which it collides).
Hi Fred, I had hoped this would have been implemented in PB4, helas nogo yet. This is very annoying as not all sprites are simply square. I'm trying to do a project I wanted to do in GameMaker first but thought suitable for a first try in PB. Of course I can do a workaround in this case but I would greatly appreciate if you would implement this as this is how it should have worked from the start and wich is logical.
Post Reply