Noob basic question about geoms bodys and textures...

Topics: User Forum
Jan 27, 2008 at 10:15 PM
dunno what im doing wrong here im doing almost the same thing as the samples....
i got a circle picture with 100px x 100px and a rectangle with 800px x 10px and im trying to make a simple ground and object interaction to start playing around with forces and see how things works... but for some reason it isnt workng well the texture and the real geometry/body just looks like not at same postion

n1 knows what im missing?
thxs and sry bad inglesh lol..

ah i did that based on demo 04...

my code:

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using FarseerGames.FarseerPhysics;
using FarseerGames.FarseerPhysics.Collisions;
using FarseerGames.FarseerPhysics.Dynamics;
using FarseerGames.FarseerPhysics.Mathematics;
using XNABalzak;

namespace XNA_ForceTest
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

Vector2 originBola;
Texture2D textureBola;
Body bodyBola;
Geom geomBola;

Vector2 originChao;
Texture2D textureChao;
Body bodyChao;
Geom geomChao;

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";

Farseer.Physics.BiasFactor = .4f;
Farseer.Physics.MaxContactsToDetect = 2;
//for stacked objects, simultaneous collision are the bottlenecks so limit them to 2 per geometric pair.
}

protected override void Initialize()
{
// TODO: Add your initialization logic here


base.Initialize();
}

protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);

// TODO: use this.Content to load your game content here
textureBola = this.Content.Load<Texture2D>("Bola");
textureChao = this.Content.Load<Texture2D>("tabua");

originBola = new Vector2(textureBola.Width / 2f, textureBola.Height / 2f);

bodyBola = BodyFactory.Instance.CreateCircleBody(Farseer.Physics, textureBola.Height, 1f);
bodyBola.Position = Vector2.Add(originBola, new Vector2(700, 200));
bodyBola.Tag = "Bola";

geomBola = GeomFactory.Instance.CreateCircleGeom(Farseer.Physics, bodyBola, textureBola.Height, 25);
geomBola.RestitutionCoefficient = .4f;
geomBola.FrictionCoefficient = .4f;
geomBola.Tag = "Bola";

originChao = new Vector2(textureChao.Width / 2f, textureChao.Height / 2f);

bodyChao = BodyFactory.Instance.CreateRectangleBody(Farseer.Physics, textureChao.Width, textureChao.Height,
1f);
bodyChao.Position = Vector2.Add(originChao, new Vector2(0, 400));
bodyChao.IsStatic = true;
bodyChao.Tag = "Chao";

geomChao = GeomFactory.Instance.CreateRectangleGeom(Farseer.Physics, bodyChao, textureChao.Width, textureChao.Height);
geomChao.RestitutionCoefficient = .4f;
geomChao.FrictionCoefficient = .4f;
geomChao.Tag = "Chao";
}

protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

protected override void Update(GameTime gameTime)
{
// TODO: Add your update logic here
if (Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();

XNABalzak.Farseer.Physics.Update(gameTime.ElapsedGameTime.Milliseconds * .001f);

base.Update(gameTime);
}

protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
spriteBatch.Draw(textureBola, bodyBola.Position, null, Color.White, bodyBola.Rotation,
originBola, 1, SpriteEffects.None, 0f);

spriteBatch.Draw(textureChao, bodyChao.Position, null, Color.White, bodyChao.Rotation,
originChao, 1, SpriteEffects.None, 0);
spriteBatch.End();

base.Draw(gameTime);
}
}
}
Jan 28, 2008 at 12:32 AM
lol i just figured ot what was the dunb thing i was doing it is no diameter to create a circle it is radius >.< the circle was just bigger than the picture lol

srry for this hehe


balzak wrote:
dunno what im doing wrong here im doing almost the same thing as the samples....
i got a circle picture with 100px x 100px and a rectangle with 800px x 10px and im trying to make a simple ground and object interaction to start playing around with forces and see how things works... but for some reason it isnt workng well the texture and the real geometry/body just looks like not at same postion

n1 knows what im missing?
thxs and sry bad inglesh lol..

ah i did that based on demo 04...

my code:

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using FarseerGames.FarseerPhysics;
using FarseerGames.FarseerPhysics.Collisions;
using FarseerGames.FarseerPhysics.Dynamics;
using FarseerGames.FarseerPhysics.Mathematics;
using XNABalzak;

namespace XNA_ForceTest
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

Vector2 originBola;
Texture2D textureBola;
Body bodyBola;
Geom geomBola;

Vector2 originChao;
Texture2D textureChao;
Body bodyChao;
Geom geomChao;

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";

Farseer.Physics.BiasFactor = .4f;
Farseer.Physics.MaxContactsToDetect = 2;
//for stacked objects, simultaneous collision are the bottlenecks so limit them to 2 per geometric pair.
}

protected override void Initialize()
{
// TODO: Add your initialization logic here


base.Initialize();
}

protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);

// TODO: use this.Content to load your game content here
textureBola = this.Content.Load<Texture2D>("Bola");
textureChao = this.Content.Load<Texture2D>("tabua");

originBola = new Vector2(textureBola.Width / 2f, textureBola.Height / 2f);

bodyBola = BodyFactory.Instance.CreateCircleBody(Farseer.Physics, textureBola.Height, 1f);
bodyBola.Position = Vector2.Add(originBola, new Vector2(700, 200));
bodyBola.Tag = "Bola";

geomBola = GeomFactory.Instance.CreateCircleGeom(Farseer.Physics, bodyBola, textureBola.Height, 25);
geomBola.RestitutionCoefficient = .4f;
geomBola.FrictionCoefficient = .4f;
geomBola.Tag = "Bola";

originChao = new Vector2(textureChao.Width / 2f, textureChao.Height / 2f);

bodyChao = BodyFactory.Instance.CreateRectangleBody(Farseer.Physics, textureChao.Width, textureChao.Height,
1f);
bodyChao.Position = Vector2.Add(originChao, new Vector2(0, 400));
bodyChao.IsStatic = true;
bodyChao.Tag = "Chao";

geomChao = GeomFactory.Instance.CreateRectangleGeom(Farseer.Physics, bodyChao, textureChao.Width, textureChao.Height);
geomChao.RestitutionCoefficient = .4f;
geomChao.FrictionCoefficient = .4f;
geomChao.Tag = "Chao";
}

protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

protected override void Update(GameTime gameTime)
{
// TODO: Add your update logic here
if (Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();

XNABalzak.Farseer.Physics.Update(gameTime.ElapsedGameTime.Milliseconds * .001f);

base.Update(gameTime);
}

protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
spriteBatch.Draw(textureBola, bodyBola.Position, null, Color.White, bodyBola.Rotation,
originBola, 1, SpriteEffects.None, 0f);

spriteBatch.Draw(textureChao, bodyChao.Position, null, Color.White, bodyChao.Rotation,
originChao, 1, SpriteEffects.None, 0);
spriteBatch.End();

base.Draw(gameTime);
}
}
}