Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 31692
  • Last Modified:

C#, DirectX - 3D programming (500 points)

Hello,

Firstly, I've done several programs using Visual C#.net with miminal difficulties.  Awhile ago, I started to play around abit with 3D game design.  I've read a fair amount of tutorials, and I've also purchased a book (though, being at work, the name escapes me - I'll post the title when I get home, if you need to know), but I'm currently getting pretty frusterated with this.

Put basically, I have a 3D character and a 3D room (both modelled in 3D Studio Max), and I would like to make a simple game whereby that character walks around the room.  Ignore collision detection, ignore AI, ignore triggers and stuff like that.  I've read abit about needing to convert the 3D Studio Max files to .x format (which you can apparently do using the DirectX SDK), but that isn't really my hurdle at the moment.  I'm more focused towards the code that will accomplish this (presumably) simple procedure.

I don't really need you guys to point me towards websites or more tutorials.  Ideally, I need code.  If I could take the points of this question above 500, I would (I've got 800 more points to spare).  If there's a way for me to do this that doesn't go against the rules of EE, I'm all for it.

Thanks in advance
0
Sebastion
Asked:
Sebastion
  • 9
  • 7
  • 2
2 Solutions
 
davebytesCommented:
I'm missing what you're having problems with, or more specifically what solution you are looking for.

Do you need a full fledged engine?  Are you just stumbling on the concept of user input and translation into moving an object in the world?  Can you handle the loading and rendering otherwise?  What's the 'simple procedure'?

I mean, handling WM_KEYDOWN/KEYUP events, or DirectInput, for user input, then translating inputs into some kind of movement for the 'character', is pretty simple, and most any tutorial site you'd have looked at should have an example of doing most of that work.  I guess the concept of accelerations and velocities (if that's the route to go) can be confusing to translate from user input... but the rest of the work is harder. ;)  Collision, AI, Animation, heck, camera intelligence...  Those are the tough nuts.

So, if you can describe better what you are looking for a 'solution' for, maybe we can whip something up, or point you to existing sample code/tutorial that already does exactly what you are looking for.  I know you say "I need code", but when it comes to this type of Q/A, usually there's something in existance that will lead you down the right path, and trying to offer any large base of code (beyond some workable pseudo-code) might be a bit difficult. ;)

-d
0
 
SebastionAuthor Commented:
Hey dave,

I'm not really looking for an engine.  I'm under the impression that it would be more difficulty to go from using an engine to creating a full fledge 3D game/world on your own.  Am I wrong with this?  In any case, I did take a brief look awhile ago for some C# engines, but the few I found were for 2D games.

I've completed several 2D game tutorials (for example, a tennis game), but I'm mosting have difficulties with creating and nagivating a 3D world.  For the tennis example I mentioned, the "world" was just a form though Visual C# and the characters were just sprites.  Unfortunatly, this doesn't help me much on 3D game programming (at least, not as far as I can tell).

From the few tutorials that I could find that were actually for C# (and not C++), none detailed how to create a 3D room, let alone use a room you built through a program like 3D studio max (ie, instead of drawing the 'room' manually through the C# code).

With that said, there were several times that I came away from a tutorial (after finishing it) and learnt nothing new.  Maybe I'm jumping ahead too far, but I also couldn't find anywhere that mentioned abit more informatoin about how 3D games work.  By this, I mean, 2D games use tiles and flipping (?), but what about 3D?

What I'm basically looking for is how to use a room that I have created in 3D studio Max as the world, then to put a character into that world, and then move him around.

If you do know of some existing code/tutorial that can do this, it would be appreciated.  You mention that the movement of a character is pretty simple;  can I get some code (or a website with some) for moving a 3D character around both the X and Z axis (lets ignore the Y axis for now).

It just seems that the more I try and do research into this, the less I learn :(
0
 
SebastionAuthor Commented:
davebytes, are you still there?  You mentioned that you could point me towards some sample code/tutorial that already does exactly what I am looking for, and I was wondering if you could provide those links.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
davebytesCommented:
I'm still here, just busy with things.

I said I might be able to point you to some links... let me think about what might be useful given what you've described (and with C# in the equation, the potential sites shrinks dramatically...).

Let me quickly also try to make you feel like you ARE learning something about all this.

You've made a 2D game.  I assume you had user input of some sort?  That translated into moving a sprite around?  Did you use velocities to move the sprites?

If so, you've got all the basis you need for the move to 3D.  Imagine if you will you are looking DOWN on your room from the top, and instead of perspective we use a orthogonal view.  Hmmm, all of a sudden, we're really kinda talking about a 2D view.  Translating keyboard input to move the player around?  Well, up/down arrow could be forward/backward velocity, right/left turns the 'front' orientation or angle of movement for the velocity, and angle * velocity = motion vector.  That make some sense?  If you were animating a tennis ball moving around the screen, you've got some similar things to pull from your experience there as well.

I'll try to think a bit about potential tutorial sources... If I can't come up with some, I'll try to feed you some more useful pseudo code.  But I generally like to help people 'take the next logic jump' when I can... ;)

-d
0
 
SebastionAuthor Commented:
I know that there isn't many C# tutorial sites, which is the main reason I've posted this question, because I've been looking around for awhile now :)  A tutorial would be great, even if it just showed me how to load up a 3D area (even if I only get a single perspective view of it, but can't move around), it would be a nice start.

In the 2D table tennis game that I created, sprites were moved by incrementing and decrementing the y and x position.  Basically, I had to unload the sprite, and re-load it at it's new position depending on which key the user pressed (pretty basic game, I know).  The main problem I have with this, is I don't know if this is used in 3D programming.  I mean, presuming I could get a 3D room loaded, would I be unloading the 3D character and reload it for each animation, or is it handled differently than in 2D?  I thought I heard somewhere that the animation was done in the 3D modelling program (in this case, 3D studio max), and that it was just 'played' in the 3D game each time it was needed.

Also, in the 2D game, the background was an image loaded onto the form.  I didn't need to do any manipulation of the image (as the "tennis court" in the game was static), but in a 3D environment, how would you go about loading up each room as a character walked from one area to the next?  Also, alot of the tutorials I've found don't really give any information on what I need to do if I want to use my own 3D environment created through another program.  Is it that you can't do this, and that you need to re-draw the areas through the C#?

As a note, I did a little searching around for some other books.  What do you think of "Introduction to 3D Game Engine Design Using DirectX 9 and C#", by Lynn Thomas Harrison?  It seems to be one of the few that come up for me :/
0
 
SebastionAuthor Commented:
I did find what looks like a pretty useful tutorial that could start me off abit, though it doesn't seem to indicate anything about loading my own environment (it looks like it draws the areas manually)

If you wanna check it out and let me know what you think, it's http://66.102.7.104/search?q=cache:6M33MRM6f_wJ:www.exocortex.org/ben/IntroTo3DGraphcsWithDirect3D.ppt+%22C%23%22+%22managed+direct+X%22+%223d%22+%22tutorial%22&hl=en

(it's the HTML version of IntroTo3DGraphcsWithDirect3D.ppt)
0
 
SebastionAuthor Commented:
davebytes, I haven't heard back from you in awhile.  How are things coming along?

You mentioned that some of the stuff I need are pretty simple and that you could find a tutorial.  I was wondering if you've found some yet.

Although I've finally managed to make a 3D cube rotate in a window with one of the tutorials I found, I'm still unable to locate anything relating to importing a *.x file into a scene.

Thanks in advance
0
 
davebytesCommented:
Sorry, I'm just EXTREMELY busy!  Haven't been able to keep up with EE stuff.  Lemme give this a quick shot.

MSDN is my usual place when trying to find tutorials on DirectX.  A DX9 tutorial dealing simply with .X loading and rendering is in the SDK, and referenced at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/tutorialsandsamples/tutorials/direct3dtutorials/6/tutorial6.asp

That shows how to load a Mesh, parse through and load textures, etc., and how to call to render the mesh object.

Now loading 'into a scene' is a confusing statement... If you have the concept of a 'world', you can load 'objects' that are IN the world, or pieces that ARE the world (i.e., the character versus the room).  In the long run, room geometry might be best stored and loaded in formats other than .X, but I'll leave that for a later discussion.  For the moment, you should be able to load both room and character as separate .X objects, and only apply movement to the 'player' object (the 'room' object remains static).

-d
0
 
SebastionAuthor Commented:
Sounds good, I'll give it a go this weekend and let you know how I end up.

If you get time, could you list a few formats that room geometry would be better stored as?  You don't need to really talk about then, I can do a search through google and see how they operate, I just need some 'good' format name :).  I presume characters/monsters are fine in .X format?
0
 
davebytesCommented:
Generally, I use custom formats when it comes to more static geometry.  Every engine I've worked on has used something different.

You may want to look at Quake, Torque, Unreal, etc. for the types of file formats they use.  Each is very different.  The Quake BSP format was popular for a while -- I never used it, so don't know its limitations.

In theory, everything could be stored in .X -- it's just that you might eventually find it limiting, not storing all the data you want, not allowing the extra features you want, platform/dx dependence, etc.

-d
0
 
skeid21Commented:
Yo sebastion,

depending on your version of 3ds check out a plugin called Panda, it converts to .x file format.  There are a few other options out there.  I currently use conv3ds comandline app from an old dx sdk.  I don't think they have included it in the newer sdks.  I would say that it is good to start working with the x file format. I havn't found it limiting yet although i'm sure it is in other aspects, but once you get a bit of code up and running to load a mesh you can put in a different model, or add more etc. with relative ease.  But I would say you are right on about staying in 2d for the movement aound your room.  It is good to get 2d computational geometry and physics(or psuedo physics) down before moving into 3d.
skeid
0
 
SebastionAuthor Commented:
skeid21,

I actually have the conv3ds that came with Direct X 8 (if I remember correctly).  Someone linked to it in another question, and I'll be using that to convert the 3D Studio max models to .x format.  So no hassles there :)


davebytes,

I didn't have much time recently to check out the link you gave (because of a annual conference, which is now over), but I took a look at it on the weekend.  It seems to be for C++, not C#.  I'm not sure if that's what I'm looking for, since I was under the impression that because C# uses Managed Direct X, it would be different to what you would do in C++.

I did, however, attempt to navigate to the C# section (which I had previous looked at before posting this question), but had trouble finding a tutorial relation to what I needed.

It would be greatly appreciated if I could get a hold of some code that would allow me to load a 3D mesh in a window.  

I think I would prefer something other than pseudo code, as (in my opinion) I learn alot faster if I actually watch what a program does, based on it's code, rather than imagining how it works.

Thanks
0
 
davebytesCommented:
sebastion -

You looking for something like this?
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_m/directx/direct3d/tutorials/tutorial6.asp

(Hint on how I found it, go to msdn site, typed in "managed directx tutorial", and it was in the top few results... ;) )

-d
0
 
SebastionAuthor Commented:
davebytes:

Sorry for the late reply, I've been really caught up with work which doesn't look like it's going to end sometime soon.

As mentioned above, I've already been to that tutorial (as I did navigate to the "managed" part), however it seems that the only way I'll get that code compiled is to go through all the previous tutorials to make sure I have all the required parts.  This is what I didn't want to do and why I started this question.

I've noticed that in the past I have learnt better by watching the program compile, setting breakpoints, commenting out lines and basically just experimenting with and expanding on the code.

I was hoping for a someone to post some code from start to finish that compiles and loads a room, as opposed to linking to tutorials (see the problem mentioned above).  I guess I was expecting a little bit more for 500 points (max available per question) than simply "go here".

When I first started this question, I only expected it to last about a week or so.  Unfortunately though, if this keeps up I'll probably need to close the question as I'll run out of time.
0
 
skeid21Commented:
O.k. there Sebastion,

I have got a little code for you... first off i'm using the december dx release and I used a sample from the sample browser's managed code called CustumUI. I changed it around a bit and I have a room that the camera can move around in.  I hope this will help.. Also, i'm not that hip on the Manged Directx or managed C# code, but I will try my best.

First off i'm assuming that you where able to load the X files fine and retreive a mesh interface.  Within the managed code the type is FrameworkMesh  I don't know if this matches to the  normal mesh interface in the unmanaged code or not.

mesh = new FrameworkMesh(e.Device, "misc\\cell.x");

Apparently for the e.Device the e is passed into the function where this is called.  It is a specific "toolkit sampl" type that has a member that is the curent device that the mesh interface will be bound to.

Before the mesh is used to render the triangles this line is used

Mesh localMesh = mesh.LocalMesh;

My guess is that the pevious FrameworkMesh type is not the normal Mesh type so the normal type is extracted.  Next the mesh is rendered

for(int i = 0; i < mesh.NumberMaterials; i++)
{
      localMesh.DrawSubset(i);
}

As far as I can tell it seems simple enough. Also don't forget to set the texture before you render.  That I don't know how to do in managed code, but the DX help should have a programming section on Texture etc. that will show you how.

As far as displaying a room that will do it. I highly recomend that you start out using the sample framwork, and when you feel comfurtable and have a few weeks to plan out a framwork of your own move on.

O.k. if you want to have a simple camera moving around the room Use the FisrtPersonCamera class that is within the sample framwork.  There are two key things that you need to make sure are included to get the movement funcitonality with the camera first

OnMsgProc(IntPtr hWnd,......
.
.
camera.HandleMessages(hWnd, msg, wParam, lParam);

This will handle the keyboad and mouse input for the camera to function

Next you must put in
FrameMove(..
.
.
camera.FrameMove(elapsedTime);

This will actually change the lookAt and eyePoint of the camera.  And last you need to set the new view projection matrix before you render every frame

Matrix m = new Matrix();
effect.SetValue("worldViewProjection", camera.ViewMatrix  * camera.ProjectionMatrix);
effect.SetValue("worldMatrix", m);

Sorry about the effect use, but the example used it and like i said i don't know all the Manged DirectX, but if you use the same sample framwork you wont have to worry about the effects file etc, just change the lines of code in the OnFrameRender function to the above form and it should work o.k. i'm sure i've left a bit out because i'm a bit shattered, but I hope this will help.  If you would like me to explain how you can perform your own movement calculations on the camera (minus me understanding how to get the input in managed code) please drop a quick line I will keep an eye on the posts for the next few days
skeid
0
 
davebytesCommented:
All I can say is if you don't know anything about 3D, and don't know anything about Managed DX, I see it as a bit silly to NOT go through the simple 6-step tutorial that gets you all the way from scratch to loading and displaying .X models -- which is what you want to do.

I'm not going to go through the tutorials to try and pull a sample together, as you could do that as quickly yourself.

If you want to close the question, please do so.  No harm, no foul.

-d
0
 
SebastionAuthor Commented:
davebytes:
I guess I should give you a little bit more information.  I never intended to become a professional game designer.  In fact, I never intended to make a full game.  Beyond the project mentioned below, its highly unlikely that I'll be using this code (or knowledge) for any future projects.

My aim with this question was to quickly take a 3d modeled building (our office, which I've already created) and allow the user to move around it.  The initial plan was to make a movie, but I started thinking about something a little more interactive.  This was going to be used with our franchises and clients inter-state.

Regardless, this is taking longer then I originally planned and it looks as though I won't have enough time as needed to finish this idea.

skeid21:
I appreciate the effort, but as requested I would have preferred complete code without me having to fill in the gaps.



I'm going to close the question as I don't think I'll have the time to explore this any further.  I have posted in the community forum asking that the points be dropped to 300, with 200 going to davebytes and 100 going to skeid21 for their efforts (I appreciate the intent).
0
 
davebytesCommented:
Thanks Sebastion.  In the future, when asking a Q on EE, it would help the experts if you give a more detailed backgrounder.  Yeah, I could have probed more, but it sounded like you had a direction in mind already, and when someone starts off that detailed I try to assume they 'know where they are headed'.  Oh, and I say that for others who may read this and ask questions of their own.

I wouldn't have had you even think about coding it up yourself.  I would have pointed to one of the opensource 3D engines, which could already easily handle what you wanted to do -- all you'd need is to import the building in and use one of the engines with a basic FPS system, and they'd take care of all the rendering and movement around the world.  They also have exporters from modelling apps, and importers for more formats. ;)  You could have something up and running pretty quickly, though whether it requires a little VB or C# or C or C++ or custom-scripting-language would depend on the engine, of course!

best, -d
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 9
  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now