Sign in to follow this  

C# & OpenGL - 2d mouse clicks in a 3d world

This topic is 3592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have just begun my journey into 3d gaming. I choose C# and OpenGL because I am very familiar with C# and development is faster and I hear OpenGL is a good place to start. I am shooting for a sort of turn-based game, so my decision for C# instead of C/C++ and OpenGL instead of DirectX will do just fine for my game. (I'm also using the CsGL wrapper for OpenGL in C#). I messed with terrains, skins, camera, and networking. I am currently trying to just detect mouse-clicks on my floating terrain in this 3d world and then return the coordinates you clicked on the terrain. I am interested in anything that would shed some light on the subject; Math theory, 3D mechanics, source code, anything. Off Topic a bit: I am still very new to opengl and I need to find a good tutorial website or book to walk me through the basics of OpenGl and its components. Any help would be most appreciated. I could use resources (including source code, tutorials, theory, anything) on my problem or anything else related to game development: Math related to gaming Networking in gaming OpenGL Basics Etc

Share this post


Link to post
Share on other sites
http://gpwiki.org/index.php/OpenGL:Tutorials:Picking
I have gone over this for hours implementing what he did into my project. The picking is accurate on the y axis of the mouse(I THINK) but it seems to be inaccurate on the x axis of the mouse(I THINK). I have set my perspective, checked that x and y values are proper from the mouse. I am unsure of what else I can do to debug this.

Edit: And some objects it just doesn't detect :/

[Edited by - Keweedsmo on February 12, 2008 12:18:20 AM]

Share this post


Link to post
Share on other sites
Now my advice is that if your serious about 3d game programming forget abut opengl picking, find a physics or collision middle ware, you can easily do picking and so much more. im using c# and opengl and tao.ode has saved me a ton of time fiddling with things like this.

[Edited by - Kaze on February 12, 2008 12:22:52 AM]

Share this post


Link to post
Share on other sites
the advantage has nothing to do with OpenGL really, although the Tao framework a is nice, yet lightweight OpenGL wrapper for C#. The difference is that C# has faster development time than C++. Especially if you develop in a test-driven development environment. Also, I am a fan of the chaos model of development for projects with 1-2 developers and a faster development language really complements this model. As for the disadvantages, C# is slower, has less control on the low-level processes, and is much newer than C++. Why is newer a disadvantage? Because there is less documentation on it, fewer proven Best Practices, etc. I am very familiar with C#, I program in it for my company, and speed isn't really a factor for my game because it is turn-based so I'm sure with decent code I can keep the fps above 50 with no problem. 50FPS on the client and 5-10FPS for information transfer from the server should be more than enough to accomidate a turn-based game.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kaze
Now my advice is that if your serious about 3d game programming forget abut opengl picking, find a physics or collision middle ware, you can easily do picking and so much more. im using c# and opengl and tao.ode has saved me a ton of time fiddling with things like this.


I use the CsGL and CsGL.Basecode from thr Tao framework for my OpenGL, I haven't seen anything called Tao.ode. Thats very interesting I will take a look at it when I get home. What exactly does it do? And would you be willing to share a snippet of source code that involves selection with tao.ode? Just to give me an idea of what I'll be attempting.

Share this post


Link to post
Share on other sites
I don't mean to derail your project or anything, but I heavily suggest that you at least look into the XNA framework. It comes with a great suite of tools that you may find very useful as a beginner to games and 3D graphics. OpenGL on the other hand...you're getting the API and that's it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Keweedsmo
I use the CsGL and CsGL.Basecode from thr Tao framework for my OpenGL, I haven't seen anything called Tao.ode. Thats very interesting I will take a look at it when I get home. What exactly does it do? And would you be willing to share a snippet of source code that involves selection with tao.ode? Just to give me an idea of what I'll be attempting.


ode manual

ode has two parts, physics (world) and collision detection (space)

I'm only using the collision detection part, with it i can test for collision between spheres, boxes cylinders and rays (lines)

Using it this way and that its a c library is a little bit cumbersome but unfortunately the selection of middle ware available for .net is still a bit limited (still waiting for irrlitch or ogre3d to have a decent/stable .net port)


//create space
IntPtr space;
space = Ode.dSimpleSpaceCreate((IntPtr)0);

//add box
IntPtr box;
box = Ode.dCreateBox(space, 5.0f, 5.0f, 5.0f);
Ode.dGeomSetPosition(box, x, y, z);

//test for hits
Ode.dSpaceCollide(space, (IntPtr)0, new Ode.dNearCallback(NearCallback));
public void NearCallback(IntPtr data, IntPtr o1, IntPtr o2)
{
//number of hits
int hits = 0;
Ode.dContactGeom[] contacts = new Ode.dContactGeom[8];
hits = Ode.dCollide(o1, o2, contacts.Length, contacts,
System.Runtime.InteropServices.Marshal.SizeOf(contacts[0].GetType()));
}



Share this post


Link to post
Share on other sites

This topic is 3592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this