How to turn in a sd terrain.

Everything related to 3D programming
pfaber11
Enthusiast
Enthusiast
Posts: 149
Joined: Sat Apr 13, 2019 12:17 pm

How to turn in a sd terrain.

Post by pfaber11 »

I created my terrain and added my camera to it . Now if I try to lean left then camera turns to the right but the camera keeps going in the original direction . I'm gonna put some code up and maybe you'll spot something wrong . I'm currently using PB 6.00 and DirectX9 . Thanks for reading.

Code: Select all

  ExamineKeyboard()
    If KeyboardPushed(#PB_Key_W)
     
      MoveCamera(0,0,0,2,#PB_Relative)
      
    EndIf
    ExamineKeyboard()
    If KeyboardPushed(#PB_Key_A) 
      zt=zt+2
      RotateCamera(0,0,zt,0,#PB_Absolute) 
      ;MoveCamera(0,0,0,2,#PB_Relative)
    ;  MoveCamera(0, CameraX(0), TerrainHeight(0, CameraX(0), CameraZ(0))+10 , CameraZ(0), #PB_Absolute)  
      EndIf
      jump61:
    ExamineKeyboard()
    If KeyboardPushed(#PB_Key_D) 
      zt=zt-2
      RotateCamera(0,0,zt,0,#PB_Absolute)
    ; MoveCamera(0, CameraX(0), TerrainHeight(0, CameraX(0), CameraZ(0))+10 , CameraZ(0), #PB_Absolute)   
     ; MoveCamera(0,0,0,-2,#PB_Relative)
    EndIf 
 MoveCamera(0, CameraX(0), TerrainHeight(0, CameraX(0), CameraZ(0))+10 , CameraZ(0)+2, #PB_Absolute)  
  RenderWorld()   
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: How to turn in a sd terrain.

Post by Caronte3D »

Better if you post a working example
pfaber11
Enthusiast
Enthusiast
Posts: 149
Joined: Sat Apr 13, 2019 12:17 pm

Re: How to turn in a sd terrain.

Post by pfaber11 »

OK I'll post what I got
pfaber11
Enthusiast
Enthusiast
Posts: 149
Joined: Sat Apr 13, 2019 12:17 pm

Re: How to turn in a sd terrain.

Post by pfaber11 »

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()

UsePNGImageDecoder()
UsePNGImageEncoder()

Add3DArchive("3darchive",#PB_3DArchive_FileSystem)

ExamineDesktops()
OpenScreen(DesktopWidth(0),DesktopHeight(0),32,"pf555",#PB_Screen_SmartSynchronization,60)

 light = CreateLight(#PB_Any ,RGB(0,0,0))   
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0,500, 50, #PB_Absolute) 
    ;CameraBackColor(0,#Blue)
    SetupTerrains(LightID(Light), 15000, #PB_Terrain_NormalMapping)
    CreateTerrain(0, 1025, 30000, 500, 1, "TerrainGroup", "dat") 
    AddTerrainTexture(0,  0, 500, "paul6.png","paul6.png")
   ; AddTerrainTexture(0,  1, 500, "paul6.png","paul6.png")
   ; AddTerrainTexture(0,  2, 500, "paul3.png", "paul3.png")
    
       DefineTerrainTile(0,0,0, "paul3.png", FlipCoordinatesX,FlipCoordinatesY )  
    
    BuildTerrain(0)     
   SkyBox("box08.png")
   
  
    LoadSprite(3,"sprite3.png")
    
LoadSprite(1,"sprite1.png")
LoadSprite(2,"sprite2.png")
LoadSprite(6,"sprite6.png")
LoadSprite(4,"sprite4.png")
LoadSprite(7,"sprite7.png")
CreateCube(25,10)
LoadTexture(2,"paul3.png")
CreateMaterial(2,TextureID(2))
CreateEntity(25,MeshID(25),MaterialID(2),0,500,500)   
  ScaleEntity(25,10,10,10)  
    
; CameraBackColor(0,RGB(0,250,0))
 MoveCamera(0,500,500,500,#PB_Absolute)
 CameraLookAt(0,500,500,600)
FlipBuffers()

a1=1
;CreateLight(1,RGB(255,255,255),0,5,1)
LoadFont(1,"sans",60)
z=-2
d=1
e=1
cx = 1 
speedy=0 
LoadMesh(1,"pfwindow_dae.mesh")
LoadTexture(1,"pfwindowtexture.png")
CreateMaterial(1,TextureID(1))
CreateEntity(1,MeshID(1),MaterialID(1),0,500,1000,#PB_Absolute)
ScaleEntity(1,10,10,10)

RenderWorld()
FlipBuffers()

Repeat
  maincode:
   ExamineKeyboard()
    If KeyboardPushed(#PB_Key_W)
      MoveEntity(25,0,0,2)
      MoveCamera(0,0,0,2)
      
    EndIf
    ExamineKeyboard()
    If KeyboardPushed(#PB_Key_A) 
      RotateEntity(25,0,1,0,#PB_Relative)
      RotateCamera(0,0,1,0,#PB_Relative) 
     
      EndIf
      jump61:
    ExamineKeyboard()
    If KeyboardPushed(#PB_Key_D) 
      RotateEntity(25,0,-1,0,#PB_Relative)
      RotateCamera(0,0,-1,0,#PB_Relative) 
      
    EndIf 
    ar=ar+2
  
 MoveCamera(0, EntityX(25), TerrainHeight(0, EntityX(25), EntityZ(25))+10 , EntityZ(25)+ar, #PB_Absolute)  
  RenderWorld()  
  jump62:
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_P)
    Goto pf279
    EndIf
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
  End
EndIf
a=a+1
If a >= 2290
  a=1
  EndIf
e=e+5
If e >= 2000
  e=1
 EndIf 
 f=f+6
 If f >= 2200
   f=1
 EndIf
 d=d+3
 If d >= 2175
   d=1
 EndIf
 c=c+7
 If c >= 2200
   c=1
 EndIf
 xt=xt+1
 If xt >= 2
   xt=0
   Goto jump5
   EndIf
 b=b+1
 If b >= 1080 
   b=1
 EndIf
 jump5:
  
 ; remark

 
 
 If KeyboardPushed(#PB_Key_B)
   
   RotateEntity(1,0,1,0,#PB_Relative)
   EndIf
 
; CameraBackColor(0,RGB(100,100,100))
  DisplaySprite(7,-360+a,100) 
 DisplayTransparentSprite(2,-280+d,200)
 DisplayTransparentSprite(1,-280+f,650)
 DisplayTransparentSprite(3,-100+e,580)
 DisplayTransparentSprite(6,-180+c,0+b)
   

lt12:

 FlipBuffers()
 
ForEver
 
pf279:
RenderWorld()
DisplaySprite(4,0,0)
FlipBuffers()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_R)
  RenderWorld()
  DisplaySprite(4,1921,1081)
  FlipBuffers()
  Goto maincode
EndIf
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
  End 
  EndIf
Goto pf279
End
pfaber11
Enthusiast
Enthusiast
Posts: 149
Joined: Sat Apr 13, 2019 12:17 pm

Re: How to turn in a sd terrain.

Post by pfaber11 »

Thanks for reading.
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: How to turn in a sd terrain.

Post by Caronte3D »

Uff!... no offense, but your code is a total mess :?
You should learn some programming, I recommend that you see examples of other programmers (here in the forum there are quite a few).
And do yourself a favor and don't use "GoTo" or things get even more complicated.

Your example is still not functional because it lacks images, mesh...
but anyway, I think that what you are looking for to solve your problem is to add "#PB_Absolute|#PB_Local" to the movement of the camera.
pfaber11
Enthusiast
Enthusiast
Posts: 149
Joined: Sat Apr 13, 2019 12:17 pm

Re: How to turn in a sd terrain.

Post by pfaber11 »

Well I solved the problem by moving the code for the key input to the end of the main loop and all is good. Played with the code a fair bit too. The reason my code was such a mess is I was experimenting and trying out different stuff and it did get messy . I use goto but sparingly and would be pissed if it was not available . Goto is your friend and must be respected. It is very useful.
pfaber11
Enthusiast
Enthusiast
Posts: 149
Joined: Sat Apr 13, 2019 12:17 pm

Re: How to turn in a sd terrain.

Post by pfaber11 »

Well my entity is still going in the wrong direction instead of where it is pointing . I have no idea why this should happen although I can think of a few case scenarios where it could be useful. Could some nice person please explain where I'm going wrong . Thankyou.
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: How to turn in a sd terrain.

Post by Caronte3D »

Hi, I already answered your question on my last post: ("#PB_Absolute|#PB_Local").
I encourage you to publish a minimal and really functional example so that someone can help you without having to do a lot of work.
pfaber11
Enthusiast
Enthusiast
Posts: 149
Joined: Sat Apr 13, 2019 12:17 pm

Re: How to turn in a sd terrain.

Post by pfaber11 »

I'm sorry but I just don't get it . I'll work it out eventually but if you have the answer I would appreciate it thankyou.
Krix
User
User
Posts: 70
Joined: Fri Mar 11, 2005 6:24 pm
Location: Toronto

Re: How to turn in a sd terrain.

Post by Krix »

What Caronte3D says is that use MoveEntity with mode "absolute" and value "local" like this:

MoveEntity(1,0,0,z,#PB_Absolute|#PB_Local).

Check the help file it's all there at MoveEntity.
pfaber11
Enthusiast
Enthusiast
Posts: 149
Joined: Sat Apr 13, 2019 12:17 pm

Re: How to turn in a sd terrain.

Post by pfaber11 »

Hi Caronte3D and Krix. Now I get it . I was on this for a few days although I took a break and with some help got camera follow nailed . Anyway thanks for your time and help. I was so annoyed to be stuck on something I'd done many times in a different system.
pfaber11
Enthusiast
Enthusiast
Posts: 149
Joined: Sat Apr 13, 2019 12:17 pm

Re: How to turn in a sd terrain.

Post by pfaber11 »

I'm using this time to make a program to use as my own reference in the future. Not detailed but the basics to jog my memory and I am just about done . just checked and it's 168 lines of code . I did look but could not find a cheat sheet on the web .
Have a nice day.
pfaber11
Enthusiast
Enthusiast
Posts: 149
Joined: Sat Apr 13, 2019 12:17 pm

Re: How to turn in a sd terrain.

Post by pfaber11 »

I thought I should show you the code that you guys helped me with for reference in the future.

Code: Select all

  ExamineKeyboard()
    If KeyboardPushed(#PB_Key_W)
      MoveEntity(1,0,0,-2,#PB_Absolute|#PB_Local)
      EndIf
    ExamineKeyboard()
    If KeyboardPushed(#PB_Key_S)
      MoveEntity(1,0,0,2,#PB_Absolute|#PB_Local) 
    EndIf   

So glad I now know how to do this .
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: How to turn in a sd terrain.

Post by Caronte3D »

Nice! :D
BTW: In the future, if you post a minimal working example showing the probleme, more users can help you an faster you get a solution :wink:
Post Reply