Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


NDraskovic

Member Since 11 Oct 2010
Offline Last Active Today, 12:30 AM

Topics I've Started

Starting OpenGL

27 November 2012 - 06:57 AM

Hey

I've been learning the basics of game development for some time now, and I believe that I am ready to take "the next step". So far, I've been working with XNA, but I get the feeling that Microsoft is slowly abandoning it. Therefor, I think it's time to switch to another API - I did some research, and I think that OpenGL would be good place to go, because it is supported on many platforms, and has a large enough community from which I could get help when I get stuck. My question is - which developing environment would be best to start working with C++ and OpenGL. I've been using Visual Studio for some time now, so if it's possible to use it with OpenGL it would be great.

Collision detection doesn't work for automated elements in XNA 4.0

30 August 2012 - 09:00 AM

I have a really weird problem. I made a 3D simulator of an "assembly line" as a part of a college project. Among other things it needs to be able to detect when a box object passes in front of sensor. I tried to solve this by making a model of a laser and checking if the box collides with it. I had some problems with BoundingSpheres of models meshes so I simply create a BoundingSphere and place it in the same place as the model. I organized them into a list of BoundingSpheres called "spheres" and for each model I create one BoundingSphere. All models except the box are static, so the box object has its own BoundingSphere (not a member of the "spheres" list). I also implemented a picking algorithm that I use to start the movement. This is the code that checks for collision:
if (spheres.Count != 0)
		{	
			for (int i = 1; i < spheres.Count; i++)
			{				  
				if (spheres[i].Intersects(PickingRay) != null && Microsoft.Xna.Framework.Input.ButtonState.Pressed == Mouse.GetState().LeftButton)
				{
					start = true;
					break;
				}
				if (BoxSphere.Intersects(spheres[i]) && start)
				{					  
					MoveBox(0, false);//The MoveBox function receives the direction (0) and a bool value that dictates whether the box should move or not (false means stop)
					start = false;
					break;
				}
				if (start /*&& Microsoft.Xna.Framework.Input.ButtonState.Pressed == Mouse.GetState().LeftButton*/ && !BoxSphere.Intersects(spheres[i]))
				{
					MoveBox(0, true);					  
					break;
				}

			}
}

The problem is this: When I use the mouse to move the box (the commented part in the third if condition) the collision works fine (I have another part of code that I removed to simplify my question - it calculates the "address" of the box, and by that number I know that the collision is correct). But when I comment it (like in this example) the box just passes trough the lasers and does not detect the collision (the idea is that the box stops at each laser and the user passes it forth by clicking on the appropriate "switch"). Can you see the problem? Please help, and if you need more informations I will try to give them. Thanks

Collision detection not working properly

06 August 2012 - 06:22 AM

I have a really weird problem with my collision detection algorithm. I have a few static elements and one movable, and for now I just want to make the movable element stop when it collides with the static ones. I tried to solve this in 2 ways - by using BoundingSpheres that are created automatically for each mesh of the static elements (in this case, algorithm never returned the "true" value in the Intersect method, although the models obviously collide), and I tried creating independent BoundingSpheres with the same center as the models that I'm drawing. In this case I get some results (the Intersects method returns true value sometimes), but the routine I have is triggered at the wrong time. For example, there are 3 static elements in coordinates (-5.0f,0f,0f), (0f,0f,0f) and (5.0f,0f,0f). When I run the program there are 3 collisions (as they should be) but they all take place between the first 2 elements (but not exactly in front of them). The weirdest part is that in the same program I have a picking algorithm that works with the same BoundingSpheres perfectly (when I click the position where the BoundingSphere should be, the proper function is triggered). What could be causing this?

[XNA 4.0] Calculating 2D (screen) coordinates from 3D coordinates

11 July 2012 - 01:34 AM

Hey

I have a program that draws some items to the scene by loading their positions from a file. Now I want to place a Ray on the same location where the items are drawn. So my question is how can I calculate the position of the ray (it's 2D components) by using 3D coordinates of each particular item? The items don't move anywhere, so once they are placed they stay until the end of the programs execution.
Thanks.

[XNA 4.0] BoundingSphere moves when it should not

09 July 2012 - 05:39 AM

Hey

I have a XNA 4.0 project in which I load a file that contains type and coordinates of items I need to draw to the screen. Also I need to check if one particular type (the only movable one) is passing in front or trough other items. This is the code I use to load the configuration:

if (ks.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.L))
		    {
			    this.GraphicsDevice.Clear(Color.CornflowerBlue);
			    Otvaranje.ShowDialog();
			    try
			    {
				    using (StreamReader sr = new StreamReader(Otvaranje.FileName))
				    {
					    String linija;
					    while ((linija = sr.ReadLine()) != null)
					    {
						    red = linija.Split(',');						  
						    model = red[0];
						    x = red[1];
						    y = red[2];
						    z = red[3];
						    elementi.Add(Convert.ToInt32(model));
						    podatci.Add(new Vector3(Convert.ToSingle(x), Convert.ToSingle(y), Convert.ToSingle(z)));
						 
						    sfere.Add(new BoundingSphere(new Vector3(Convert.ToSingle(x), Convert.ToSingle(y), Convert.ToSingle(z)), 1f));
													 
					    }
				    }				   
			    }
			    catch (Exception ex)
			    {
				    Window.Title = ex.ToString();
			    }
		    }

The "Otvaranje" is an OpenFileDialog object, "elementi" is a List<Int32> (determines the type of item that would be drawn), podatci is a List<Vector3> (determines the location where the items will be drawn) and sfere is a List<BoundingSphere>. Now I solved the picking algorithm (checking for ray and bounding sphere intersection) and it works fine, but the collision detection does not. I noticed, while using picking, that BoundingSphere's move even though the objects that they correspond to do not. The movable object is drawn to the world1 Matrix, and the static objects are drawn into the world2 Matrix (world1 and world2 have the same values, I just separated them so that the static elements would not move when the movable one does). The problem is that when I move the item I want, all boundingSpheres move accordingly. How can I move only the boundingSphere that corresponds to that particular item, and leave the rest where they are?

PARTNERS