Results 1 to 22 of 22

Thread: Easy way to create an entire level in direct x 7 and use of bounding boxes

  1. #1

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172

    Easy way to create an entire level in direct x 7 and use of bounding boxes

    Hey people. i am wondering if there is an easy way to create a level in with direct x 7 i have made some objects in a world but every model has about 4 lines of code only to create it. i am wondering if there is a easier way of creating a level by making it a little bit more automated, or with a better easier code.
    Last edited by Ultimasnake; Sep 2nd, 2002 at 10:44 AM.
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  2. #2
    Junior Member
    Join Date
    Aug 2002
    Posts
    16
    You have to load the world from an file. I'm working on an Q3 BSP loader, but it's an very big task! You should check out my X-File loading tutorial at www.matrixvb.da.ru, it should show a simple way of loading 3D geometry (But keep in mind that X files are slow, they are only good for little games)

  3. #3

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    well i know how to insert a .x file allready . anyway will read it right now. but if i want to create a big city i shouldnt make it out of one big model right?
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    If you're making a big city you have to worry about culling and all that. And it CAN be one big model, for the things that WON'T change, like in a BSP or UNR file (quake and unreal respectively). Basically, loading the file is the least of your worries
    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
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    So if i just create 1 gigantic map (wel not gigantic but big) it wouldnt really stress the computer and slow down the app. well now that i know that that is atleast one worry less because then i dont have to load each building , part of the road , traffic lights etc etc. ofcourse as soon as the player should be able to interact with something (like a hitting a traffic light will make it fall) i should make it seperate (thus not like unreal tournament). Does any of you have an example on how to make bounding boxes for collision? because that would also make it a bit easier for me to make such a thing.
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  6. #6
    Junior Member
    Join Date
    Aug 2002
    Posts
    16
    If you fully understand the X-File format (reading out the subset information etc.) you could load your world out of one file, but I would use seperate x-files. You simply have to get the bounding box-volumes of each object and check if the 4 edge points are in the players frustum, here is the code for checking if an box is in frustum, you could easily change the code to be used with single points or something else.

    Public Sub CalculateFrustum()
    D3Ddevice.GetTransform D3DTS_VIEW, matView
    D3Ddevice.GetTransform D3DTS_PROJECTION, matProj

    D3DXMatrixMultiply matClip, matView, matProj

    'Right
    Frustum(FS_RIGHT).a = matClip.m14 - matClip.m11
    Frustum(FS_RIGHT).b = matClip.m24 - matClip.m21
    Frustum(FS_RIGHT).c = matClip.m34 - matClip.m31
    Frustum(FS_RIGHT).d = matClip.m44 - matClip.m41
    NormalizePlane Frustum(), FS_RIGHT
    'Left
    Frustum(FS_LEFT).a = matClip.m14 + matClip.m11
    Frustum(FS_LEFT).b = matClip.m24 + matClip.m21
    Frustum(FS_LEFT).c = matClip.m34 + matClip.m31
    Frustum(FS_LEFT).d = matClip.m44 + matClip.m41
    NormalizePlane Frustum(), FS_LEFT
    'Bottom
    Frustum(FS_BOTTOM).a = matClip.m14 + matClip.m12
    Frustum(FS_BOTTOM).b = matClip.m24 + matClip.m22
    Frustum(FS_BOTTOM).c = matClip.m34 + matClip.m32
    Frustum(FS_BOTTOM).d = matClip.m44 + matClip.m42
    NormalizePlane Frustum(), FS_BOTTOM
    'Top
    Frustum(FS_TOP).a = matClip.m14 - matClip.m12
    Frustum(FS_TOP).b = matClip.m24 - matClip.m22
    Frustum(FS_TOP).c = matClip.m34 - matClip.m32
    Frustum(FS_TOP).d = matClip.m44 - matClip.m42
    NormalizePlane Frustum(), FS_TOP
    'Back
    Frustum(FS_BACK).a = matClip.m14 - matClip.m13
    Frustum(FS_BACK).b = matClip.m24 - matClip.m23
    Frustum(FS_BACK).c = matClip.m34 - matClip.m33
    Frustum(FS_BACK).d = matClip.m44 - matClip.m43
    NormalizePlane Frustum(), FS_BACK
    'Front
    Frustum(FS_FRONT).a = matClip.m14 + matClip.m13
    Frustum(FS_FRONT).b = matClip.m24 + matClip.m23
    Frustum(FS_FRONT).c = matClip.m34 + matClip.m33
    Frustum(FS_FRONT).d = matClip.m44 + matClip.m43
    NormalizePlane Frustum(), FS_FRONT

    End Sub

    Private Function NormalizePlane(aFrustum() As D3DPLANE, Side As Long)
    magnitude = Sqr(aFrustum(Side).a * aFrustum(Side).a + _
    aFrustum(Side).b * aFrustum(Side).b + _
    aFrustum(Side).c * aFrustum(Side).c)

    'Then we divide the plane's values by it's magnitude.
    'This makes it easier to work with.
    aFrustum(Side).a = aFrustum(Side).a / magnitude
    aFrustum(Side).b = aFrustum(Side).b / magnitude
    aFrustum(Side).c = aFrustum(Side).c / magnitude
    aFrustum(Side).d = aFrustum(Side).d / magnitude
    End Function

    Public Function BoxInFrustum(max As D3DVECTOR, min As D3DVECTOR) As Boolean
    'Go through all of the corners of the box and check then again each plane
    'in the frustum. If all of them are behind one of the planes, then it most
    'like is not in the frustum.
    For ic = 0 To 5
    If (Frustum(ic).a * max.x + Frustum(ic).b * max.y + Frustum(ic).c * max.Z + Frustum(ic).d > 0) Then GoTo NextSide:
    If (Frustum(ic).a * min.x + Frustum(ic).b * max.y + Frustum(ic).c * max.Z + Frustum(ic).d > 0) Then GoTo NextSide:
    If (Frustum(ic).a * max.x + Frustum(ic).b * min.y + Frustum(ic).c * max.Z + Frustum(ic).d > 0) Then GoTo NextSide:
    If (Frustum(ic).a * min.x + Frustum(ic).b * min.y + Frustum(ic).c * max.Z + Frustum(ic).d > 0) Then GoTo NextSide:
    If (Frustum(ic).a * max.x + Frustum(ic).b * max.y + Frustum(ic).c * min.Z + Frustum(ic).d > 0) Then GoTo NextSide:
    If (Frustum(ic).a * min.x + Frustum(ic).b * max.y + Frustum(ic).c * min.Z + Frustum(ic).d > 0) Then GoTo NextSide:
    If (Frustum(ic).a * max.x + Frustum(ic).b * min.y + Frustum(ic).c * min.Z + Frustum(ic).d > 0) Then GoTo NextSide:
    If (Frustum(ic).a * min.x + Frustum(ic).b * min.y + Frustum(ic).c * min.Z + Frustum(ic).d > 0) Then GoTo NextSide:
    BoxInFrustum = False: Exit Function
    NextSide:
    Next ic
    BoxInFrustum = True
    End Function


    I think it should work very good, but don't use it with too big objects (because it's only checking 4 points and sometimes it's posible that no point is infrustum but the object is visible), it should work very good with small objects and if you use smaller objects more objects are culled and not rendered -> faster rendering

    Perhaps you should write an very small level editor, where you could load the x-files and set the position of them

    I don't really know how to get the bounding box volumes of the X-Files, the only way I could tell you is to loop through the geometry and check for max or min x/y/z-values

    I hope that helped you a little bit

  7. #7

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    hmm well i dont really understand .x files completly i create them with Cinema 4d and than export them to a .x file. i know how to import them and how to texture them (but i use the .mestuxture or something option) anyway i will try to add this to my source soon. first i will mess around with some easier things like making diffrent views to view at the car.
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  8. #8

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    Does anybody have a minor example of using BOUNDING BOXES ?it cant really make sence out of this example
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  9. #9
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202
    Perhaps this is what you are looking for? This sample uses the "RMcontrol.cox" - this is what I perfer to use when making 3DRM progrmas. It is easier to use and you can "Create" meshes as well. This demostrates Bounding Box collision detection with Ray Pick.
    Attached Files Attached Files

  10. #10
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202

    Wink

    Oh by the way, if you are serious about making quality 3D games than I suggest you don't stick with the "RM mode" and start learning the "IM mode" - this is what all commercial quality 3D games use. The IM mode is way more powerful then the RM mode.

  11. #11

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    im? RM? i currently am just trying stuff with it.. whats the diffrence? dont even know what i am using at the moment :P
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  12. #12

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    i guess i am using IM MODE because my code is far more complicated and with initializing of the direct 3d etc etc. anyway have an example with usage in IM mode than? with out a OCX? i am wondering how microsoft did it in Midtown madness, i had to create the model with a bounding box model in it call it bounding box and save it. cant i somehow do something like that?
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  13. #13
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202
    No, your using the RM mode (Retained Mode). From what I believe, when M$ was making D3D, there was a "test" 3D API which was supposed to be removed in the release version of DX7, but they decided to keep it for some reason. The RM mode is way easier then IM(Immedieate mode), but it can't do a lot of complicated stuff. Here is what the IM 3d initialization looks like:

    Public Sub Initialize_DX(Optional Width As Integer = 640, Optional Height As Integer = 480, Optional BPP As Byte = 16)
    Dim ddsd As DDSURFACEDESC2
    Dim caps As DDSCAPS2
    Dim DEnum As Direct3DEnumDevices
    Dim Guid As String

    'Create the DirectDraw object and set the application
    'cooperative level.
    Set DX = New DirectX7
    Set DD = DX.DirectDrawCreate("")

    'Make a fullscreen, exclusive application
    DD.SetCooperativeLevel frmMain.hWnd, DDSCL_EXCLUSIVE Or DDSCL_FULLSCREEN Or DDSCL_ALLOWREBOOT
    DD.SetDisplayMode Width, Height, BPP, 0, DDSDM_DEFAULT

    'Prepare and create the primary surface.
    ddsd.lFlags = DDSD_BACKBUFFERCOUNT Or DDSD_CAPS
    ddsd.ddsCaps.lCaps = DDSCAPS_COMPLEX Or DDSCAPS_FLIP Or DDSCAPS_3DDEVICE Or DDSCAPS_PRIMARYSURFACE
    ddsd.lBackBufferCount = 1

    Set Primary = DD.CreateSurface(ddsd)

    'Attach the backbuffer. the DDSCAPS_3DDEVICE tells the
    'backbuffer that its to be used for 3D stuff
    caps.lCaps = DDSCAPS_BACKBUFFER Or DDSCAPS_3DDEVICE
    Set BackBuffer = Primary.GetAttachedSurface(caps)


    Set Direct3D = DD.GetDirect3D

    'Get the last device driver (last one is usually the best one)
    'you could specify or search for a particular device, eg RGB or HAL device
    Set DEnum = Direct3D.GetDevicesEnum
    Guid = DEnum.GetGuid(DEnum.GetCount)

    'Set the Device
    Set Device = Direct3D.CreateDevice(Guid, BackBuffer)

    End Sub

    Check out www.directx4vb.com for IM tutorials.

    "i had to create the model with a bounding box model in it call it bounding box and save it. cant i somehow do something like that?"

    Say wha? you confused me here, sorry can you rephrase.

  14. #14

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    So i am using im mode i have those lines too ...

    anyway what i mean is that in a game like midtown madness when creating a car model you create a mesh in it wich is the bounding box (see picture the grey box around the model would be the bounding box ), midtown madness used that mesh for checking for collisions. i am wondering if i either can do this through the model itself or with a separate model for usage as bounding box.
    Attached Images Attached Images  
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  15. #15
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202
    You have some of those lines.... and you have this:

    Dim D3D_Main As Direct3DRM3 - this is RM Mode

    You can do either, a box around a car, or use the car itself for collision detection.

    VB-World should make a seprate topic on D3D LOL

  16. #16

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    So i am using RM mode :S what is the real diffrence about it then? and yeah they should i cant really find good tutorials on the net about DIRECT 3d combined with VB :S gamedev.net looks great but is all C++ .

    are you able to do this (the bounding boxes) without a seperate ocx or something? i am willing to send you what i have at the moment if you can provide me with an example inside my program (really asking much lately )
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  17. #17
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202
    The differece is that with RM you can't do all the goodies like: Terrain Generation, Shadows, Bump Mapping, etc. All the complicated topics, but they are still required for a commercial quality 3D game.

    Sorry, I can't help you here, the farthest I got in RM Collision Detection is the cheap way I showed you the first time, you know where you detect the positions of objects and stuff. I'm going to continue to learn DX8 cause DX9 is coming out soon!

  18. #18

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    aha to bad, hard to find a tutorial about that, well the problem with your technique is that i want to create it for my entire city :S and it will be big once i get any better thus i should create loads of objects to check its collision and getting a code wich is to big to get good FPS :s

    i did find this board http://www.visualbasicforum.com/ with a special DIRECT X section maybe they can also help me there
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  19. #19
    Junior Member
    Join Date
    Aug 2002
    Posts
    16
    RM mode bad!
    IM mode good!
    -------------------
    BEST: DirectX8

    DX8 is an crossover between RM and IM, it has all the good stuff of RM (like simple X-file loading) and all the good stuff from IM (e.g. vertex buffers [I think they were only avaible in IM])

    You should use DX8, because it's much easier and faster

  20. #20

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    well i heard the oposite once anyway i found a dll library called TRUE VISION it allready has allot of options in it (more than i can ever make) with use of direct x 8. i guess i will try that too. it is not really professionall but it looks great lets hope it is easy to use, anyway a good tutorial on direct x 8 would be nice (And not the directx4vb site because it is not explaining it good enough (not good voor beginners )
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  21. #21
    Junior Member
    Join Date
    Aug 2002
    Posts
    16
    Perhaps my site could help you a little bit (most of the source is heavily commented)

    www.matrixvb.da.ru

  22. #22
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The real thing about RM is this:
    When the first D3D was released, it was simply a piece of sh*t. It was so complicated that it was nearly impossible to use. So MS put together RM as a sort of high level layer for the old IM. But then they completly redesigned IM so that it is easier to use (relatively speaking) which made the slow RM obsolete. RM is NOT capable of drawing primitives!
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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