Results 1 to 19 of 19

Thread: ZOrder - Own Engine

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636

    ZOrder - Own Engine

    Hi, Guys.

    Does anyone have a specified way of doing the ZOrder with BitBlt, with several objects?

    Thank you,
    Arie.

  2. #2
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    Put them in an array arranging them by zorder, then blit the array or something
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    I thought about it but I don't know how to use it.
    Does anyone has a ready code for this?
    Please help.

    Thank you,
    Arie.

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Just blit them in order from back to front, use an array like that if you want!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    My objects are not on an array, not like Object(1 to 10).
    I have the objects in different names. How do I get all ordered?

    Thank you,
    Arie.

  6. #6
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    You don't. Use an array.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    Ok. Got it. My objects are now in an array with no specific bound.
    Now how do I arrange the array in the ZOrder?

    Thank you so far,
    Arie.

  8. #8
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    Argggg, just add a zindex to your UDT and use this function

    VB Code:
    1. [edit]
    2. function missing
    3. [/edit]

    I wrote alot of code and im not sure that it works, ill post again later when i have more time to finish the quicksort function.

    Basically what you do is use some kind of a sorting algorythm, search google (vb sort function), and use that to sort your data. The easiest to implement is bubble sort, start from the begining and check every 2 objects and compare, untill entire array is sorted, there is more to this. Search google. I will post a complete function later.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  9. #9
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    Alright, im done.

    Here is the code, it took me a while to do it but im finally done. Hey Arie, Next time do a search here and if you cant come up with anything, do a search on google, and planet source code. It will give you all the code you want.

    VB Code:
    1. ' The type UDT needs to have a variable called ZIndex
    2. '  you can call it anything but you have to be sure to do
    3. '  a string replace of TheType to whatever you called yours
    4. ' - if you are having ptoblems with it, just reply
    5. Type TheType
    6.     ZIndex As Long
    7.     ' all other stuff goes here
    8. End Type
    9.  
    10.  
    11. ' swap objects
    12. Private Sub SwapObj(ByRef i1 As TheType, ByRef i2 As TheType)
    13.     Static i0 As TheType
    14.     i0 = i1
    15.     i1 = i2
    16.     i2 = i0
    17. End Sub
    18.  
    19. ' This is the function that you call, it will sort your array as you like
    20. Function ReArrange (ByRef TheArray() As TheType, Optional ByVal Asc As Boolean = True)
    21.     Dim iLBound As Integer
    22.     Dim iUBound As Integer
    23.    
    24.     iLBound = LBound(TheArray)
    25.     iUBound = UBound(TheArray)
    26.    
    27.     ' Quick sort first,
    28.     ' this is a highly rapid and recursive sort algorythm
    29.     ' *note* dont change the 4 here (i dont know why)
    30.     ' here is the original quote:
    31.     ' [quote]
    32.     ' *NOTE*  the value 4 is VERY important here !!!
    33.     ' DO NOT CHANGE 4 FOR A LOWER VALUE !!!
    34.     ' [/quote]
    35.     QuickSort TheArray, 4, iLBound, iUBound
    36.    
    37.     ' Insertion Sort next
    38.     ' This will finish up on the bounds
    39.     Dim iTemp As TheType
    40.     Dim i As Integer
    41.     Dim j As Integer
    42.    
    43.     For i = iLBound + 1 To iUBound
    44.         iTemp = TheArray(i)
    45.         j = i
    46.        
    47.         Do While j > iLBound
    48.             If TheArray(j - 1).ZIndex <= iTemp.ZIndex Then Exit Do
    49.            
    50.             TheArray(j) = TheArray(j - 1)
    51.             j = j - 1
    52.         Loop
    53.        
    54.         TheArray(j) = iTemp
    55.     Next i
    56.    
    57.     ' Now take care of the order
    58.     If Not Asc Then
    59.         ' Reverse the array
    60.         While iLBound < iUBound
    61.             SwapObj TheArray(iLBound), TheArray(iUBound)
    62.             iLBound = iLBound + 1
    63.             iUBound = iUBound - 1
    64.         Wend
    65.     End If
    66. End Function
    67.  
    68. ' Function Adapted from a modified version of TriQuickSort,
    69. ' by Philippe Lord, posted on PSC on 6/29/2001 2:36:08 AM
    70. ' All Props due to their rightful owners, I just put the
    71. ' ideas together :)
    72. Function QuickSort (ByRef iArray() As TheType, ByVal iSplit As Long, _
    73.                     ByVal iMin As Long, ByVal iMax As Long)
    74.    If (iMax - iMin) > iSplit Then
    75.       i = (iMax + iMin) / 2
    76.      
    77.       If iArray(iMin).ZIndex > iArray(i).ZIndex Then SwapObj iArray(iMin), iArray(i)
    78.       If iArray(iMin).ZIndex > iArray(iMax).ZIndex Then SwapObj iArray(iMin), iArray(iMax)
    79.       If iArray(i).ZIndex> iArray(iMax).ZIndex Then SwapObj iArray(i), iArray(iMax)
    80.      
    81.       j = iMax - 1
    82.       SwapObj iArray(i), iArray(j)
    83.       i = iMin
    84.       iTemp = iArray(j).ZIndex
    85.      
    86.       Do
    87.          Do
    88.             i = i + 1
    89.          Loop While iArray(i).ZIndex < iTemp
    90.          
    91.          Do
    92.             j = j - 1
    93.          Loop While iArray(j).ZIndex > iTemp
    94.          
    95.          If j < i Then Exit Do
    96.          SwapObj iArray(i), iArray(j)
    97.       Loop
    98.      
    99.       SwapObj iArray(i), iArray(iMax - 1)
    100.      
    101.       QuickSort iArray, iSplit, iMin, j
    102.       QuickSort iArray, iSplit, i + 1, iMax
    103.    End If
    104. End Function

    I havent tested this code but it should work if not, reply and we'll help ya
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    Oh Man! I will try it out...
    I hope it works...

    Thank you, MoMad!

    I'll reply when done checking.

    Thank you all,
    Arie.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    It works!! Thanks man...
    One only thing is wrong here: You create the TheType too much,
    to make the array, you should put only the index of every TheType.

    Thank you,
    Arie.

  12. #12
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    No, just do a string replace "TheType" to whatever you call your UDT. It HAS to be a UDT and just switching the zindexes wont work, you have to switch the entire udt.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    Ok...
    Now, does this code arrange the objects well?
    VB Code:
    1. Dim K as Integer, L as Integer, iMax as Integer
    2.  
    3.  For K = 1 To UBound(ObjOrder) - 1
    4.   iMax = K
    5.   For L = (K + 1) To UBound(ObjOrder)
    6.    If Object(L).oPosition.pY < _
    7.       Object(iMax).oPosition.pY Then iMax = L
    8.   Next L
    9.   'Swapping
    10.   Temp = ObjOrder(K)
    11.   ObjOrder(K) = ObjOrder(iMax)
    12.   ObjOrder(iMax) = Temp
    13.  Next K

    Thank you,
    Arie.

  14. #14
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    No and infact i have no idea what the purpose of this is!! Your variables dont match the things they do... you have ObjOrder but then you are using Object instead? You have iMax but then you are assigning it the min value? You are swapping K and iMax but why?

    Wait a minute, i remember this algorythm, insertion sort right? Well kindof.. anyways, it kind of makes sense and it kindo doesnt...

    ...
    1 min and copy/paste into vb and testing later....
    ...

    it works!! One problem though?? What is up with Object(k).oPosition?? Isnt it supposed to be ObjOrder(k).oPosition??
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    You See, iMax is ment to be iMin, and my objects are in the Object array that have all the properties of an object,
    and the ObjOrder array is an array of integer, that says the order of the objects by their number.

    I hope you understand it a little bit better now, exuse me for not explaining. Can you help me? it does not order my objects correctly...

    Please Help!

    Thank you,
    Arie.

  16. #16
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    I see, your problem here is that your array gets ordered correctly but that ordering has no effect whatsoever on your actual object array. Add a field called "ZIndex" to your object array and then order the objects according to the ZIndex...

    Actually try this: (you dont need objorder)
    VB Code:
    1. Dim K as Integer, L as Integer, iMin as Object
    2.  Dim Temp As Object
    3.  Dim size As Integer
    4.  
    5.  size = UBound(Object)
    6.  For K = LBound(Object) To size - 1
    7.   iMin = Object(K)
    8.   For L = (K + 1) To size
    9.    If Object(L).oPosition.pY < _
    10.       iMin.oPosition.pY Then iMin = Object(L)
    11.   Next L
    12.   'Swapping (the objects)
    13.   Temp = Object(K)
    14.   Object(K) = iMin
    15.   iMin = Temp
    16.  Next K
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    Thank you very much but I found the solution!
    Here's the corrected code:
    VB Code:
    1. Dim K As Integer, L As Integer, iMax As Integer, Temp As Integer
    2.  ReDim Preserve ObjOrder(1 To UBound(Object))
    3.  For K = 1 To UBound(ObjOrder)
    4.   ObjOrder(K) = K
    5.  Next K
    6.  
    7.  For K = 1 To UBound(ObjOrder) - 1
    8.   iMax = K
    9.   For L = (K + 1) To UBound(ObjOrder)
    10.    If Object(ObjOrder(L)).oPosition.pY < _
    11.       Object(ObjOrder(iMax)).oPosition.pY Then iMax = L
    12.   Next L
    13.   Temp = ObjOrder(K)
    14.   ObjOrder(K) = ObjOrder(iMax)
    15.   ObjOrder(iMax) = Temp
    16.  Next K

    Thank you anyway,
    Arie.

  18. #18
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    I dont understand, what are you trying to rearrange? The surfaces/objects or the arbitary numbers in objorder array?
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    My game isn't 2d from up view, it's a 2d game the objects can hide behind the other objects, including players.

    Later on, I'll upload my completed game, "Magical Operation".
    I hope I won't have any other problems.

    Thank you all for helping,
    Arie.

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