• Create Account

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

# Monkan

Member Since 11 Oct 2010
Offline Last Active Jul 01 2015 03:03 AM

### box2d concave interior question

20 May 2012 - 04:32 PM

Hi,

I'm using Box2d.
In my game I have buildings that you can enter and when you are inside I want you not to be able to walk outside of the edges of the building. When I say building I basically mean rectangle.

At first I was wondering if there was a way to set a box2d body to stop other bodies leaving it instead of separating them (basically the opposite) but I don't think you can do this.

Then I thought I would make 3 separate bodies each with a different shape which would be the 2 walls and the ceiling and then I would connect them with a couple of joints. This method seems a bit overkill in my mind.

What I would like ideally is 1 body with 3 shapes attached to it so the centre of the body is still the centre of the building but I can't think of a way to do this as I'm not too sure how I would position the shapes.

Have I missed something really obvious?

Does anyone know a good way of doing this?

### circular gravity

25 March 2012 - 11:10 AM

Hi,

I'm making a game where you walk around a circle, its 2D and the circle is going to be a planet, its kind of like Angry Birds in Space in terms of gravity. At the moment I am rotating my objects to align with the gravity vector which is pointing in to the centre of the planet. This is fine for objects on the planet but then I want to have a rocket ship that leaves the planet so I don't want to set the rotation of the ship to be inline with the planet as I will need to rotate the ship to steer. I'm sure there are also other situations where I will want to rotate objects away from this set rotation.

At the moment I use this function to apply gravity to objects which is a member of my GameObject base class -

```public void ApplyGravity(Vector2 planetPosition, float gravityForce, float deltaTime)
{
Vector2 gravity = m_position - planetPosition;
if (gravity.LengthSquared() != 0)
{
gravity.Normalize();
}

gravity *= gravityForce;
// Apply gravity to velocity
m_velocity -= gravity * deltaTime;
// Adjust rotation of object to stick to circle
Vector2 normalisedGravity = gravity;
normalisedGravity.Normalize();
float desiredRotation = (float)Math.Atan2(gravity.Y, gravity.X);

m_rotation = desiredRotation;
}
```

So just a bit of advice would be nice,

Should I keep it like this for objects on the planet which will want to be rotated to snap to the circle in most cases and then have specific states where the objects are allowed to rotate?

Or is there something I'm missing, maybe some sort of rotational gravity force that is applied to objects to attempt to align them with the planet but still allow some movement if there is a strong enough force in the opposing direction?

Any advice is appreciated, if you would like more info or my explanation was rubbish then just say,

Thanks.

### randomly generated planet / rock

18 December 2011 - 02:58 PM

Hi,

I want to make a randomly generated planet that is not a perfect sphere. So I was thinking of a way to do this and I figured if I create a shape like a soccer ball (icosahedron I think?) with quite a few faces and verts then I could apply perlin noise to all the verts to create a random shape that is still spherical-ish.
So I created one in Blender, subdivided it a few times, exported as an .OBJ and imported it into my program. Applied my Perlin noise and got the effect I desired, however, I have now run into a few problems so I have a few questions I would like to ask please and see if there is a better way of tackling this problem.

1. How easy is it to create the soccer ball shape in code? And can anyone help me with the maths of how I would do it? This way I wouldn't need to export and import .OBJ files when I want to change how subdivided the shape is and could maybe apply the Perlin Noise at the same time as creating each vert.

2. I think I know how to create new normals after I've applied the Perlin Noise (using the cross product for each face), but how can I calculate new texture coordinates?

3. Is there a better way to achieve the effect I want or am I on the right track? Eventually I will want things to move across the surface (like Mario Galaxy) and so will add gravity and collisions but I think I know how to do these things just about (Gravity will be simple and I will use triangle intersections with objects and the planet mesh) and can cross that bridge when I get to it.

Any help or advice or interesting resources would be greatly appreciated.

Thanks.

### What has been deprecated?

13 September 2011 - 03:09 AM

Hi,

Is there a list somewhere of everything that has been removed from the new versions of OpenGL because I am confused as to what I can use if I'm trying to just use new functionality. Or is there a way of making an error appear if I am using deprecated functionality?

Have all the glEnable(GLenum) / glDisable(GLenum) been deprecated? Because some tutorials I see still use certain ones?

Cheers

x

### Help with Program Structure

04 September 2011 - 04:00 AM

Hi,

So I'm trying to use the new OpenGL stuff and do away with all the old stuff but I'm having trouble structuring my programs and can't find any example programs on the internet that help me.

How do people handle these things? At the moment I have a baseObject class that things inherit from, now I was thinking I would give each object a matrix for its transformations that I can pass to a shader. I then need global access to some sort of camera and perspective matrices so I was thinking I would just have them as global objects even though I have always been told this is not good. I also need to store the vertex batches for all different objects to be able to draw them so I was thinking I would give each object its own vertex batches and store ones that are used a lot like cubes, spheres and rectangles as global objects that I can access anywhere encase I need then.

Basically I am really confused about how to structure my program and still be able to get access to all the things I need from the places in my program. Can someone please tell me how they do it or can someone point me in the direction of an example program please.

Thanks
x

PARTNERS