3D-game, but some problems

Advanced game related topics
Megaborsti
User
User
Posts: 35
Joined: Sat Aug 16, 2003 4:52 pm
Location: Germany

3D-game, but some problems

Post by Megaborsti »

Hi,
I had some free time and wrote this prototype for a thirdperson 3D-game
(If you want to test it, you have to insert some pictures and meshes - Controls are WASD and Arrow-Keys).

But I have still a problem and hope you can help me:
I usually use a 129x129 picture for the terrain and a 1024x1024 jpg as texture.
If I walk and turn the camera in different directions, the character walks at different speed. I think it is why the framerate is very ?small if you look to the opposite edge of the terrain, but I don´t know what to do.
I tried the Fog()-function but it seems it doesn´t work correct - I saw no fog. So I do not know how to ?increase the framerate.

Hope someone can fix the problem and tell me. It would be also nice to make the code better, I´m still not as good as I want in pb.


(When I wrote the code I noticed some strange individualities of pb: :?
1. If you use MoveCamera(?,KeyX,?,?), the camera moves always forward, the looking-direction does not care, but if you use MoveEntity(?,KeyX,?,?) the Entity is moved along the X-axis of the world.
2. There is no function to get the rotation-angle of an entity. If you rotated an entity an have not save somewhere how much, you have no chance to turn it looking along the x-axis for example. It is also very difficult to turn an entity once (in the gameloop) and let it look in this direction the following frames.
3. If have still no idea how to create a mesh or a world to load in pb. Hope someone can help me with this.)


Sorry for my bad english :) , here is the code:

Code: Select all


move_x.w = 0
move_y.w = 0
old_angle.l = 0
angle.l = 0
character_speed.w = 10
c_angle = 0
c_distance = 500
way.s = ""

If InitEngine3D()

  Add3DArchive("Data\", #PB_3DArchive_FileSystem)
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  OpenScreen(1024,768,32,"")
  
    CreateMaterial(0, LoadTexture(0, ""))
    CreateTerrain("", MaterialID(0), 400, 30, 400, 0)

    SkyBox("")
        
    LoadMesh(0,"")
    CreateMaterial(1,LoadTexture(1,""))
    CreateEntity(0, MeshID(0), MaterialID(1), 0, 0, 0)
    AnimateEntity(0,"")
            
    CreateCamera(0,0,0,100,100)  
       
    Repeat
      ExamineKeyboard()
      
      way = ""
      If KeyboardPushed(#pb_key_w)
        way + "w"
      EndIf
      If KeyboardPushed(#pb_key_s)
        way + "s"
      EndIf
      If KeyboardPushed(#pb_key_a)
        way + "a"
      EndIf
      If KeyboardPushed(#pb_key_d)
        way + "d"
      EndIf
      ReplaceString(way,"ws","")
      ReplaceString(way,"ad","")
      
      If KeyboardPushed(#pb_key_left) And KeyboardPushed(#pb_key_right)
      ElseIf KeyboardPushed(#pb_key_left)
        c_angle + 2
        angle + 2
        If c_angle > 360
          c_angle - 360
        EndIf 
      ElseIf KeyboardPushed(#pb_key_right)
        c_angle - 2
        angle - 2
        If c_angle < 0
          c_angle + 360
        EndIf 
      EndIf 
      
      If KeyboardPushed(#pb_key_up) And KeyboardPushed(#pb_key_down)
      ElseIf KeyboardPushed(#pb_key_up)
        c_distance - 10
      ElseIf KeyboardPushed(#pb_key_down)
        c_distance + 10
      EndIf
      If c_distance < 300
        c_distance = 300
      EndIf
      If c_distance > 1000
        c_distance = 1000
      EndIf 
      
                  
      old_angle = angle
      If way = "w"
        angle = 0
      ElseIf way = "wa"
        angle = 45
      ElseIf way = "a"
        angle = 90
      ElseIf way = "sa"
        angle = 135
      ElseIf way = "s"
        angle = 180
      ElseIf way = "sd"
        angle = 225
      ElseIf way = "d"
        angle = 270
      ElseIf way = "wd"
        angle = 315
      EndIf 
      RotateEntity(0,angle-old_angle,0,0)
      
      If way <> ""
        MoveEntity(0,character_speed*Cos(ASin(1)/90*(angle-c_angle)),0,character_speed*Sin(ASin(1)/90*(c_angle-angle)))

        EntityLocate(0,EntityX(0),TerrainHeight(EntityX(0),EntityZ(0)),EntityZ(0))
      EndIf 
      
      CameraLocate(0,EntityX(0)-c_distance*Cos(c_angle*ASin(1)/90),EntityY(0)+100+0.0003*Pow(c_distance,2),EntityZ(0)-c_distance*Sin(c_angle*ASin(1)/90))  

      CameraLookAt(0,EntityX(0),EntityY(0)+50*500/c_distance,EntityZ(0))
                          
      RenderWorld()     
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
        
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
  
End

I become better!!! :)
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

To increase your framerate you can use a few tricks, such as fog or maybe the Precision parameter of the CreateTerrain() function.
1. If you use MoveCamera(?,KeyX,?,?), the camera moves always forward, the looking-direction does not care, but if you use MoveEntity(?,KeyX,?,?) the Entity is moved along the X-axis of the world.
Look at the Terrain.pb example in the 'Examples' folder in the PB folder for an example on how to do this. (Wow! 3 examples in 1 sentence :D )
2. There is no function to get the rotation-angle of an entity. If you rotated an entity an have not save somewhere how much, you have no chance to turn it looking along the x-axis for example. It is also very difficult to turn an entity once (in the gameloop) and let it look in this direction the following frames.
PB's 3D stuff is still in progress, so with further updates it will be expanded upon. More commands are coming :)
3. If have still no idea how to create a mesh or a world to load in pb. Hope someone can help me with this.)
From the PB Help file:
Load a whole world. Currently, the Quake3 BSP format is the only one supported but more formats will follow. The Filename$ must be accessible in the 3D path, so the Add3DArchive() command should be used before. Such world can be easily created with third part tools like 'Quark'. A world can contain a sky, building, lights and more. Actually, all Quake 3 maps can be loaded out of the box with full details. If the 'Result' is 0, the world can't be loaded.

To create meshes use a 3D modeling program such as 3DStudio Max, LightWave or Milkshape and use an OGRE Mesh exporter to save out your file :D
--Kale

Image
Megaborsti
User
User
Posts: 35
Joined: Sat Aug 16, 2003 4:52 pm
Location: Germany

Ogre exporter

Post by Megaborsti »

To create meshes use a 3D modeling program such as 3DStudio Max, LightWave or Milkshape and use an OGRE Mesh exporter to save out your file
I already know that I need an exporter for 3D Studio Max or Lightwave, but my problem is that I do not know where to find one.
Can you tell me form where I can get one?
To increase your framerate you can use a few tricks, such as fog or maybe the Precision parameter of the CreateTerrain() function.
If I use the precision parameter, the terrain seems to live and the Fog() function does not work - try it.
Does someone know other methods or how to make the Fog() function work?
I become better!!! :)
CS2001
User
User
Posts: 14
Joined: Mon Jun 09, 2003 6:17 pm
Location: Germany
Contact:

Post by CS2001 »

Go to the Ogre Website (http://ogre.sourceforge.net). Select Downloads-->Exporters.

In German: Gehe zu der Ogre Webseite (http://ogre.sourceforge.net). Wähle Downloads aus und dann Exporter.

CS2001
chris_b
Enthusiast
Enthusiast
Posts: 103
Joined: Sun Apr 27, 2003 1:54 am

Post by chris_b »

Megaborsti wrote:the Fog() function does not work - try it.
Does someone know other methods or how to make the Fog() function work?
Fog works OK for me on a terrain - maybe it doesn't work with some graphics cards - but all it does is affect the colour of the terrain's polygons, it won't alter the framerate because the whole terrain is still displayed.

Hopefully future versions of Ogre will have a draw-distance parameter for the terrain.
mp303

Post by mp303 »

Ogre's own terrain engine will probably remain simple, since there are already at least four other terrain managers for Ogre with tons of advanced features - here's one:

http://ogre.sourceforge.net/phpBB2/view ... n+distance

here's another:

http://ogre.sourceforge.net/phpBB2/view ... n+distance

There is something called the Nature Plugin as well, and one other engine which supports tiled heightmaps - would be extremely cool for gigantic maps! :)

Just search the Ogre forums, there's plenty of plugin-ready terrain engines, and they're all far more advanced than Ogre's native terrain engine will be for a long while... I hope Fred's considering one of these terrain engines instead? otherwise it could be a loooooong time before we have a useful terrain engine in PB ... the current terrain engine simply isn't suitable for anything practical, just for testing - I mean, as long as you can't even set the drawing distance ... and it also doesn't seem to LODing very well, it looks choppy and bad when it reduces details in the distance... I think maybe the native terrain engine is there in Ogre mostly for testing, and to give other developers something to start off with - there are definitely other things in Ogre that have higher priorities for the developes, like actual rendering features, since terrain is already being handled very well by the community - in fact, the native terrain engine might NEVER reach any useful state, who knows... I wouldn't rely on it.
Johan_Haegg
User
User
Posts: 60
Joined: Wed Apr 30, 2003 2:25 pm
Location: Västerås
Contact:

Post by Johan_Haegg »

This is how i solved this in RasTank:

1.
turretrotate = way the turret i faceing
barpitch = how much the barrel is raised

The dual temps is to check so you dont see under the terrain.
This is QUITE unstable, the camera seems to jerk from side to side when moveing.

Code: Select all

    X.l = EntityX(3) + (40 * Cos((turretrotate.f+180)*(3.14/180)))
    Z.l = EntityZ(3) + (40 * -Sin((turretrotate.f+180)*(3.14/180)))
    Temp.l = TerrainHeight(X.l, Z.l) + 25 - barpitch.f
    Temp2.l = EntityY(3) + 20 - barpitch.f
    If Temp.l > Temp2.l
      Y.l = Temp.l
    Else
      Y.l = Temp2.l
    EndIf

    CameraLocate(0, X.l, Y.l, Z.l)
    CameraLookAt(0, EntityX(3), EntityY(3), EntityZ(3))

2.
tankrotate.f = total rotation since start (limited to 0-360 via code)
rotate = degrees to rotate now

Code: Select all

  RotateEntity(ent.w, rotate.f, 0, 0)

  movedirx.f = Cos(tankrotate.f*(3.14/180))
  movedirz.f = -Sin(tankrotate.f*(3.14/180))

  EntHeight.f = -EntityY(ent.w) + TerrainHeight(EntityX(ent.w), EntityZ(ent.w))
  MoveEntity(ent.w, x.f*movedirx.f,  EntHeight + 4, x.f*movedirz.f)
3.
Export as VRML97 from 3DS Max and use that converter, no trouble with inverting normals, no problems with mapping and the pivot point is correct.
Post Reply