Page 1 of 1

Material rotate issue.

Posted: Sat Aug 24, 2013 10:21 pm
by Samuel
Hello everyone,

I have a 256 by 256 billboard with a rotating circle in it. When the circle has a radius greater than 75 you will notice parts of the circle appear in the corners of the billboard.
I'm not sure why this is happening, but I was hoping someone could explain this to me.
Any help is appreciated.

Code: Select all

;PRESS Escape to exit

#CameraSpeed = 1
Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
ExamineDesktops()
Width=DesktopWidth(0)
Height=DesktopHeight(0)

    OpenWindow(0, 0, 0, Width, Height, "Billboard Test")
    OpenWindowedScreen(WindowID(0), 0, 0, Width, Height, 0, 0, 0)
    
    CircleRadius=120
    
    Texture=CreateTexture(#PB_Any,256,256)
    StartDrawing(TextureOutput(Texture))
    DrawingMode(#PB_2DDrawing_AllChannels | #PB_2DDrawing_AlphaBlend)
      Circle(128,128,CircleRadius,RGBA(255,0,0,255))
    StopDrawing()
    
    Material=CreateMaterial(#PB_Any, TextureID(Texture))
    DisableMaterialLighting(Material, 1)
    MaterialBlendingMode(Material, #PB_Material_AlphaBlend)
    RotateMaterial(Material, 0.1, #PB_Material_Animated)
    
    BillboardGroup=CreateBillboardGroup(#PB_Any, MaterialID(Material), 256, 256,0,0,0)
    Billboard1=AddBillboard(#PB_Any, BillboardGroup, 50, 0, 0)
    
    Camera=CreateCamera(#PB_Any, 0, 0, 100, 100)
    MoveCamera(Camera, 0, 0, 500, #PB_Absolute)
    CameraBackColor(Camera,RGB(50,50,50))

    Repeat

      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf  
      
      If ExamineKeyboard()
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed 
        Else
          KeyX = 0
        EndIf
                  
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed 
        Else
          KeyY = 0
        EndIf
        
      EndIf
        
      RotateCamera(Camera, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera  (Camera, KeyX, 0, KeyY)
    
      RenderWorld()

      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape)

Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
  
End

Re: Material rotate issue.

Posted: Sat Aug 24, 2013 11:13 pm
by Comtois
Here is what happen, Imagine Sprite 0 is your BillBoard and Sprite 1 your texture. you can see triangle yellow, ogre will fill them with the texture

Code: Select all

InitSprite()
If OpenWindow(0, 100, 200, 600, 600, "Rotate Material")
  OpenWindowedScreen(WindowID(0), 0, 0, 600, 600)
  
  If CreateSprite(0, 256, 256)
    If StartDrawing(SpriteOutput(0))
      Box(0, 0, 256, 256, RGB(255, 255, 55))
      StopDrawing()
    EndIf
  EndIf
  If CreateSprite(1, 256, 256)
    If StartDrawing(SpriteOutput(1))
      Box(0, 0, 256, 256, RGB(55, 55, 255))
      Circle(128,128,120,RGB(255,0,0)) 
      StopDrawing()
    EndIf
  EndIf
  RotateSprite(1, 45, #PB_Absolute)
  
  
  
  Repeat
    
    Repeat 
      Event = WindowEvent() 
      If Event = #PB_Event_CloseWindow  
        End
      EndIf  
    Until Event = 0
    
    ClearScreen(0)
    DisplaySprite(0, 150, 150)
    DisplaySprite(1, 150, 150)
    RotateSprite(1, 1, #PB_Relative)
    FlipBuffers()
  ForEver
  
EndIf

End 

Re: Material rotate issue.

Posted: Sat Aug 24, 2013 11:35 pm
by Samuel
Thanks Comtois,

So, is there anyway to fix this? Like always making my texture smaller than the billboard?

If not do you think a two triangle plane or something like TransformSprite() would be better for this job?
I think both would work, but I'm unsure of which one would be faster when dealing with many at one time.

Re: Material rotate issue.

Posted: Sat Aug 24, 2013 11:58 pm
by Olby
Samuel wrote:Thanks Comtois,

So, is there anyway to fix this? Like always making my texture smaller than the billboard?

If not do you think a two triangle plane or something like TransformSprite() would be better for this job?
I think both would work, but I'm unsure of which one would be faster when dealing with many at one time.
When you write your material script just set it to use clamp as the texture address mode. This will use the last pixel from the texture (in your case a black border) to fill the rest of the material. It "should" also work when rotated.

See here: http://www.ogre3d.org/docs/manual/manua ... s_005fmode

Edit: Border will also do the job.

Re: Material rotate issue.

Posted: Sun Aug 25, 2013 2:04 am
by Samuel
Thanks Olby,

I'll give that a try later on, but it sounds like it will take care of my problem.