Problems with down scaling a entity.

Everything related to 3D programming
box_80
Enthusiast
Enthusiast
Posts: 117
Joined: Mon Sep 03, 2012 8:52 pm

Problems with down scaling a entity.

Post by box_80 »

Don't know if it's a bug or me just not knowing what I'll doing. Here I'm having trouble with scaling down a entity with a variable. It works fine if I use values instead. Some code below to help. Use the keys 1-6 to change the scale of the entity. Tested with PB 5.30 Beta 7 on Win XP(x86). Thanks for any help.

Key 1 use scale of 0.5 with variable with results of scale of 1.0?

Key 2 use scale of 0.5 with values with good results.

Key 3 use scale of 1.0 with variable return to original scale.

Key 4 use scale of 1.5 with variable with good results.

Key 5 use scale of 0.09 with variable with the entity going in hiding.

Key 6 use scale of 0.09 with value with good results.

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Entity
;
;    (c) 2002 - Fantaisie Software
;
; ------------------------------------------------------------
;

#CameraSpeed = 1

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY, RollZ

pp = 1.0

If InitEngine3D()
  
  Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Models", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Packs/skybox.zip", #PB_3DArchive_Zip)
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    LoadMesh(0, "robot.mesh")
    
    CreateMaterial(1, LoadTexture(0, "clouds.jpg"))
    
    CreateEntity(1, MeshID(0), MaterialID(1), 0, 0, 0)
    
    StartEntityAnimation(1, "Walk")
    
    SkyBox("stevecube.jpg")
    
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0, 40, 150, #PB_Absolute)
    
    Repeat
      Screen3DEvents()
      
      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    
        
        If KeyboardPushed(#PB_Key_1)
          pp = 0.5
          ScaleEntity(1, pp, pp, pp, #PB_Absolute)
          
        ElseIf KeyboardPushed(#PB_Key_2)
          ScaleEntity(1, 0.5, 0.5, 0.5, #PB_Absolute)
          
        ElseIf KeyboardPushed(#PB_Key_3)
          pp = 1.0
          ScaleEntity(1, pp, pp, pp, #PB_Absolute)
          
        ElseIf KeyboardPushed(#PB_Key_4)
          pp = 1.5
          ScaleEntity(1, pp, pp, pp, #PB_Absolute)
          
        ElseIf KeyboardPushed(#PB_Key_5)
          pp = 0.09
          ScaleEntity(1, pp, pp, pp, #PB_Absolute)
          
        ElseIf KeyboardPushed(#PB_Key_6)
          ScaleEntity(1, 0.09, 0.09, 0.09, #PB_Absolute)
          
        EndIf
        
      EndIf
      
      RotateEntity(1, 0, 1, 0, #PB_Relative)
      
      RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera  (0, KeyX, 0, KeyY)
      
      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
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Problems with down scaling a entity.

Post by applePi »

in line 16 change " pp = 1.0" to " pp.f = 1.0 " so it will accept later the fractional values ,
i have faced this trap many times before and it took me sometimes too long to find.
regards
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Problems with down scaling a entity.

Post by DK_PETER »

Boil your ScaleEntity() conditions down to this:

Code: Select all

        
        If KeyboardReleased(#PB_Key_Subtract) And GetEntityAttribute(1, #PB_Entity_ScaleY) > 0.1
          pp = GetEntityAttribute(1, #PB_Entity_ScaleY) - 0.1
          ScaleEntity(1,pp,pp,pp,#PB_Absolute)
        EndIf
        If KeyboardReleased(#PB_Key_Add) And GetEntityAttribute(1, #PB_Entity_ScaleY) < 5.0
          pp = GetEntityAttribute(1, #PB_Entity_ScaleY) + 0.1
          ScaleEntity(1,pp,pp,pp,#PB_Absolute)
        EndIf
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
box_80
Enthusiast
Enthusiast
Posts: 117
Joined: Mon Sep 03, 2012 8:52 pm

Re: Problems with down scaling a entity.

Post by box_80 »

Thanks for the advice guys. Both is just what I needed. Now I can continue my project. Hope I'll have something to show for it someday.
Post Reply