Raúl
Moderator
 Moderator
| Posts: 444 |  | Karma: 6
|
Re:Creación de laberinto - 2008/03/12 22:09
Hola,
Puedes echar un vistazo al código del servicio Maze Simulator para ver como crea las paredes a partir de un bmp. El método que añade los muros es este:
| Code: | // Adds a simple cube at a specified location in the maze grid
void AddWall(int row, int col, float height, BasicColor color)
{
// TT Oct-2006 - Add an option to use a sphere instead of a cube
if (_UseSphere[(byte)color])
{
SphereShapeProperties cSphereShape = null;
SingleShapeEntity sphere = null;
float radius;
radius = _state.SphereScale * height / 2.0f;
// create simple entity, with a single shape
cSphereShape = new SphereShapeProperties(
// TT -- Change to infinite mass so that the walls
// do not "blow apart" if you bump them!
// TT Oct 2006 -- Allow user to specify this
_WallMasses[(byte)color], // mass in kilograms.
new Pose(), // relative pose
radius); // radius
cSphereShape.Material = new MaterialProperties("gsphere", 1.0f, 0.01f, 0.01f);
// Set the color of the sphere according to the bitmap image
// or the specified color if no bitmap
if (_WallTextures[(byte)color] == "")
{
// TT - Changed for October CTP because DiffuseColor
// is a Vector4, but my WallColors are Vector3
//cBoxShape.DiffuseColor = _WallColors[(byte)color];
cSphereShape.DiffuseColor.X = (float)(_WallColors[(byte)color].X / 255.0);
cSphereShape.DiffuseColor.Y = (float)(_WallColors[(byte)color].Y / 255.0);
cSphereShape.DiffuseColor.Z = (float)(_WallColors[(byte)color].Z / 255.0);
cSphereShape.DiffuseColor.W = 1.0f;
}
else
cSphereShape.TextureFileName = _WallTextures[(byte)color];
sphere = new SingleShapeEntity(new SphereShape(cSphereShape),
new Vector3((col * -_state.GridSpacing),
radius,
-(row * _state.GridSpacing)));
// Name the entity. All entities must have unique names
sphere.State.Name = "ball_" + row + "_" + col;
// Insert entity in simulation.
_simEnginePort.Insert(sphere);
}
else
{
// Dimensions are in meters
Vector3 dimensions =
new Vector3(_state.WallBoxSize * _state.GridSpacing,
height * _state.HeightScale,
_state.WallBoxSize * _state.GridSpacing);
BoxShapeProperties cBoxShape = null;
SingleShapeEntity box = null;
// create simple immovable entity, with a single shape
cBoxShape = new BoxShapeProperties(
// TT -- Change to infinite mass so that the walls
// do not "blow apart" if you bump them!
// TT Oct 2006 -- Allow user to specify this
_WallMasses[(byte)color], // mass in kilograms.
new Pose(), // relative pose
dimensions); // dimensions
cBoxShape.Material = new MaterialProperties("gbox", 1.0f, 0.4f, 0.5f);
// Set the color of the box according to the bitmap image
// or the specified color if no bitmap
if (_WallTextures[(byte)color] == "")
{
// TT - Changed for October CTP because DiffuseColor
// is a Vector4, but my WallColors are Vector3
//cBoxShape.DiffuseColor = _WallColors[(byte)color];
cBoxShape.DiffuseColor.X = (float)(_WallColors[(byte)color].X / 255.0);
cBoxShape.DiffuseColor.Y = (float)(_WallColors[(byte)color].Y / 255.0);
cBoxShape.DiffuseColor.Z = (float)(_WallColors[(byte)color].Z / 255.0);
cBoxShape.DiffuseColor.W = 0.5f;
}
else
cBoxShape.TextureFileName = _WallTextures[(byte)color];
box = new SingleShapeEntity(new BoxShape(cBoxShape),
new Vector3(col * -_state.GridSpacing,
height * _state.HeightScale / 2,
-(row * _state.GridSpacing)));
// Name the entity. All entities must have unique names
box.State.Name = "wall_" + row + "_" + col;
// Insert entity in simulation.
_simEnginePort.Insert(box);
}
BlockCounter++;
}
|
Como ves usa la entidad box para crear las pareces. Una esquina se forma por dos 'boxes' pegados.
También puedes coger un entorno ya creado y editarlo directamente usando el modo de edición del simulador.
Echa un vistazo a este mensaje:
-> Crear una simulación
Raúl Arrabales Moreno. conscious-robots.com/raul |