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.
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)
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?
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)
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.
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
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
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.
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.
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.
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?
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)
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.
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 )
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!
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
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
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 )
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.