Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


back again...

This topic is 6137 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

some of you may remember me... anyway, last year, I've been busy with university and real life, but I also continued my programming, and my little ISO project... and I'm still stuck at the same place: terrain rendering. here is where I've been able to come so far... (crappy JPEG compression...) I don't know why, but I get those strange slopes... but some of them appear to be drawn correctly. This thing is driving me crazy. and now, the code.
'Loads a Map from a RAW File. (c) JonnyQuest :D

Public Function LoadMap(HeightMapFile As String) As Boolean
    Dim nx As Integer, ny As Integer
    Dim ycurrent As Byte
    Dim xp As Integer, yp As Integer
    nFileNum = FreeFile

    Open HeightMapFile For Binary As nFileNum
        For ny = 1 To MAP_HEIGHT
            xp = (ny * TILE_WIDTH) '+ 60
            yp = (ny * (TILE_HEIGHT / 2)) ' + 120
            For nx = 1 To MAP_WIDTH
                Get nFileNum, , ycurrent
                Map(nx, ny).Altitude = ycurrent
                Map(nx, ny).TerrainType = ycurrent
                Map(nx, ny).Vertex(0).sx = xp
                Map(nx, ny).Vertex(0).sy = yp
                Map(nx, ny).Vertex(1).sx = xp + TILE_WIDTH
                Map(nx, ny).Vertex(1).sy = (yp -(TILE_HEIGHT /2))
                Map(nx, ny).Vertex(2).sx = xp + TILE_WIDTH
                Map(nx, ny).Vertex(2).sy = (yp +(TILE_HEIGHT /2))
                Map(nx, ny).Vertex(3).sx = xp +(TILE_WIDTH * 2)
                Map(nx, ny).Vertex(3).sy = yp
                xp = xp + TILE_WIDTH
                yp = yp - (TILE_HEIGHT / 2)
            Next nx
        Next ny
    Close nFileNum
End Function
and now the rendering one...
Public Sub DrawMap()
    Dim Vertice(4) As D3DTLVERTEX
    Dim ScreenX As Integer, ScreenY As Integer
    Dim xp As Integer, yp As Integer
    Select Case RenderState
        Case 0
            Device3D.SetRenderState D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID
        Case 1
        Case 2
            Device3D.SetRenderState D3DRENDERSTATE_FILLMODE, D3DFILL_POINT
    End Select
    Device3D.Clear 1, ViewportRect, D3DCLEAR_TARGET Or D3DCLEAR_ZBUFFER, 0, 1, 0
    Vertice(0).Color = vbWhite
    Vertice(1).Color = vbWhite
    Vertice(2).Color = vbWhite
    Vertice(3).Color = vbWhite
    Vertice(0).rhw = 1
    Vertice(1).rhw = 1
    Vertice(2).rhw = 1
    Vertice(3).rhw = 1
    Vertice(0).tu = 0
    Vertice(0).tv = 0
    Vertice(1).tu = 1
    Vertice(1).tv = 0
    Vertice(2).tu = 0
    Vertice(2).tv = 1
    Vertice(3).tu = 1
    Vertice(3).tv = 1
    For ScreenY = 1 To MAP_HEIGHT - 1
        xp = ((ScreenY * TILE_WIDTH)) '+ 60)
        yp = ((ScreenY * (TILE_HEIGHT / 2))) ' + 120)
        For ScreenX = 1 To MAP_WIDTH - 1
            If Not (xp < (-FormRect.Right * 2) Or xp > (FormRect.Right * 2) Or yp < (-FormRect.Bottom * 2) Or yp > (FormRect.Bottom * 2)) Then
                Vertice(0).sx = Map(ScreenX, ScreenY).Vertex(0).sx + OffsetX
                Vertice(0).sy = Map(ScreenX, ScreenY).Vertex(0).sy - Map(ScreenX, ScreenY).Altitude + OffsetY
                Vertice(1).sx = Map(ScreenX, ScreenY).Vertex(1).sx + OffsetX
                Vertice(1).sy = Map(ScreenX, ScreenY).Vertex(1).sy - Map(ScreenX + 1, ScreenY).Altitude + OffsetY
                Vertice(2).sx = Map(ScreenX, ScreenY).Vertex(2).sx + OffsetX
                Vertice(2).sy = Map(ScreenX, ScreenY).Vertex(2).sy - Map(ScreenX + 1, ScreenY + 1).Altitude + OffsetY
                Vertice(3).sx = Map(ScreenX, ScreenY).Vertex(3).sx + OffsetX
                Vertice(3).sy = Map(ScreenX, ScreenY).Vertex(3).sy - Map(ScreenX, ScreenY + 1).Altitude + OffsetY
                Device3D.DrawPrimitive D3DPT_TRIANGLESTRIP, D3DFVF_TLVERTEX, Vertice(0), 4, D3DDP_DEFAULT

                        Device3D.SetTexture 0, Default
            End If
            xp = xp + TILE_WIDTH
            yp = yp - (TILE_HEIGHT / 2)
        Next ScreenX
    Next ScreenY
    Select Case ShowInfo
        Case 0
            DisplayInfo (0)
        Case 1
            DisplayInfo (1)
    End Select
End Sub
Yes, I know it's VB code. I like it like this. Any help would be appreciated... ------------------------------------------- GTD Swiss Pride - Orion Class Swiss 1st Fleet, Sector 32 - Ore Belt - Sol ------------------------------------------- Edited by - CmdKewin on January 11, 2002 3:07:02 AM

Share this post

Link to post
Share on other sites
Hi there,

I''m not a programmer but from my observations, the height (or y-axis) for the point on the right of a square grid and the point on the bottom of a square grid had been wrongly assigned. Just switch the height values between the 2 points and they should be alright.

Share this post

Link to post
Share on other sites
Just now i see how i was stupid.... it worked....thank you guys, I owe you one

Edited by - CmdKewin on January 12, 2002 3:21:03 PM

Share this post

Link to post
Share on other sites
latest development screens, for your viewing pleasure (i hope...)

next step, rotation and zooming. Don''t know why, but all my trys until now didn''t work... the matWorld seems not to be changed by any calculations...

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!