Results 1 to 7 of 7

Thread: RTS-like scrolling screen

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    33

    RTS-like scrolling screen

    I'm planning on making a simple (very) RTS-like game, and atm I'm stumped on displaying a scrollable screen, such as one in any RTS game, where not the whole "world" is displayed at the same time, just a smallish area of it.

    My thoughts would be that everything is done before being rendered (normal i think), and each unit in my RTS game (prob based on a real simple 2D grid) would be given world co-ords, not screen co-ords, and when the game renders, it...

    and here i am stuck :S i guess you need some conversations from world co-ords to screen co-ords, and the position of the users screen in the world - which work together sort of... basicly, i don't know where to start! so any help is welcome! and i would prefer the screen to "move" when the cursor nears the edge of the map, although i think i know how to do this.


    and one small question, from another thread which was never answered about vbScript:
    i've added some scripting support to my basic game, and so far have this:

    With frmMain.SC
    .Reset
    .AddObject "Game", Game
    .AddObject "User", User
    .AddCode LoadedItem(Item(ID).intLoadedItemOrigin).strEffect
    .Run "Effect"
    End With

    This works fine, and I am able to "use" all public members in both of these arrays. But I would like to add another class object that is an array, how can you do this? or is this even possible?

    i mean something like this : .addobject "Item", Item(), althoughthis doesn't work
    Thanks

  2. #2
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: RTS-like scrolling screen

    You use D3DXVec3Project to convert world coordinates to screen coordinates. The VOut result, although it says D3DVECTOR, it's actually a vertex it's returning, which would be your screen coordinates.

    VB Code:
    1. Function D3DXVec3Project(VOut As D3DVECTOR, v As D3DVECTOR, viewport As D3DVIEWPORT8, Projection As D3DMATRIX, view As D3DMATRIX, World As D3DMATRIX) As Long

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    33

    Re: RTS-like scrolling screen

    ok, so i need viewport, matrixworlds and projectoring thingys to do this (properly)?

    ill get on it then tutorials here we come

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    33

    Re: RTS-like scrolling screen

    erm can anyone link me to tutorial dealing with this stuff, as I don't really know what to search for!

    thanks

  5. #5
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    294

    Re: RTS-like scrolling screen

    http://externalweb.exhedra.com/Direc...Lesson05.asp#5

    If in 2d, ScreenPos=WorldPos-CameraPos

  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    33

    Re: RTS-like scrolling screen

    right, i'm having mighty trouble with this D3DXMatrixLookAtLH thingy for the viewport!

    atm, i have a basic cube, and am currently trying to make it so that when you press vbKeyLeft, the "camera" moves left, vbKeyRight moves it "right", vbKeyUp moves it closer to the cube, and vbKeyDown moves it further away from it.

    like so:


    Code:
                    [cube]
    
    		  vbkeyup
    		  |
                  \   |   /
    	       \_____/
    		|   |
    vbkeyleft<--	|Cam|	--> vbKeyRight
    		|___|
    
                      |
                      |  
    		 vbkeydown
    if that makes any sense

    it says makevector(), and so i think this means you dont tell the camera where to go, you tell it how far to move, is that correct?

    also, i am using :
    VB Code:
    1. D3DXMatrixLookAtLH matView, MakeVector(whtX, whtY, whtZ), MakeVector(0, 0, 0), MakeVector(0, 0, 1)

    to move the camera, can someone explain what all the MakeVectors mean? this is what I think: 1st MakeVector tell the camera where to move, 2nd MV tells the camera what to point at, and the last one does.... ? what does it do?

    anyways, i am rather stuck with this thing :S if anyone can guide my through then id be most grateful! one last thing, is Z up/down?

  7. #7

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    33

    Re: RTS-like scrolling screen

    ok, sorry, solved my own question!

    it does just what i wanted it to do, and i understand why it wasnt working before, its because the camera always faced 0,0,0, meaning it would "spiral" around the shape, so here is the code that does what I wanted to do

    VB Code:
    1. If KeyCode = vbKeyUp Then
    2.   intX = intX - 0.5
    3.  
    4.   D3DXMatrixLookAtLH matView, MakeVector(intX, intY, intZ), MakeVector(intX - 5, intY, intZ), MakeVector(0, 0, 1)
    5.   D3DDevice.SetTransform D3DTS_VIEW, matView
    6. End If
    7.  
    8. If KeyCode = vbKeyDown Then
    9.   intX = intX + 0.5
    10.  
    11.   D3DXMatrixLookAtLH matView, MakeVector(intX, intY, intZ), MakeVector(intX - 5, intY, intZ), MakeVector(0, 0, 1)
    12.   D3DDevice.SetTransform D3DTS_VIEW, matView
    13. End If
    14.  
    15.  
    16. If KeyCode = vbKeyLeft Then
    17.   intY = intY + 0.5
    18.  
    19.   D3DXMatrixLookAtLH matView, MakeVector(intX, intY, intZ), MakeVector(intX - 5, intY, intZ), MakeVector(0, 0, 1)
    20.   D3DDevice.SetTransform D3DTS_VIEW, matView
    21. End If
    22.  
    23. If KeyCode = vbKeyRight Then
    24.   intY = intY - 0.5
    25.  
    26.   D3DXMatrixLookAtLH matView, MakeVector(intX, intY, intZ), MakeVector(intX - 5, intY, intZ), MakeVector(0, 0, 1)
    27.   D3DDevice.SetTransform D3DTS_VIEW, matView
    28. End If

    one question, why is Y the "wrong way" round? shouldn't increasing Y move the camera right? or am i doing something wrong :S thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width