I want to check collision with tiny but i don't what to do ???
please help me!!
Moderator: Brume Dev Team
// testing camera attached collision shape (fps like collisions)
BrumeSphereColored cameraSphere = new BrumeSphereColored(this, "cameraSphere");
this.ActiveCamera.AddChild(cameraSphere);
cameraSphere.AddCollisionShapes(GenerateCollisionShapes(cameraSphere));
cameraSphere.CollisionEvent += new BrumeCollisionDelegate(OnCollisionWithCamera);
...
...
...
void OnCollisionWithCamera(BrumeObject cameraSphere, BrumeCollisionShape otherShape, List<BrumeCollisionContact> contacts)
{
// camera does not collide with ground
if (!(otherShape is BrumeCollisionPlane))
{
cameraSphere.Parent.MoveToLastPosition();
cameraSphere.MoveToLastPosition();
}
}
BrumeXMesh pinguinMesh = new BrumeXMesh(this, "pinguinMesh", "tiny_4anim.x", false);
....
BrumeObject obj = pinguin.GetChild("body");
....
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace Brume.Tests
{
public class TinyMove : Brume
{
private BrumeFPSCamera camera1 = null;
private BrumeLight directionalLight = null;
private BrumeLightedObject tiny = null;
public TinyMove()
: base()
{
BrumeFileManager.AddDirForAll("../../../Data/Internal");
BrumeFileManager.AddDirForAll("../../Data");
}
BrumeCylinderColored collisionShape = null;
BrumeObject root = null;
override protected void GameInit()
{
camera1 = new BrumeFPSCamera(this, "camera1", new BrumeVector(0, 0, -5.0f), new BrumeVector(0.0f, 0.0f, 1.0f), new BrumeVector(0.0f, 1.0f, 0.0f));
this.SetActiveCamera(camera1);
this.BufferClearColor = Color.Black;
this.GlobalAmbientLight = Color.FromArgb(255, 100, 100, 100);
directionalLight = new BrumeDirectionalLight(this, "Directionnal Light", new BrumeVector(-1.0f, -1.0f, 1.0f), new BrumeVector(-1.0f, 1.0f, 1.0f), Color.FromArgb(255, 170, 170, 170));
directionalLight.Specular = Color.FromArgb(255, 255, 255, 255);
directionalLight.Enabled = true;
directionalLight.Update();
root = new BrumeObject(this, "root");
root.Pos.Y = -1.5f;
root.Pos.Z = 5.0f;
BrumeXMesh tinyMesh = new BrumeXMesh(this, "tiny", "tiny_4anim.x", false);
BrumeAnimationManager.AddAnimationsFromMesh(tinyMesh);
tiny = new BrumeLightedObject(this, "tiny");
tiny.Animation = BrumeAnimationManager.GetAnimation("Wave");
tiny.Mesh = tinyMesh;
tiny.Size = 0.005f;
tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));
root.AddChild(tiny);
collisionShape = new BrumeCylinderColored(this, "cylinder");
collisionShape.AddCollisionShapes(GenerateCollisionShapes(collisionShape));
collisionShape.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));
collisionShape.CollisionEvent += new BrumeCollisionDelegate(OnCollisionWithCube);
collisionShape.HasGlobalSize = false;
collisionShape.ZSize = 2.5f;
collisionShape.Pos.Y = 1.2f;
collisionShape.Mesh = null; // comment this line to see the cylinder shape
root.AddChild(collisionShape);
BrumeCubeColored cube = new BrumeCubeColored(this, "cube", Color.Blue, Color.Red);
cube.AddCollisionShapes(GenerateCollisionShapes(cube));
}
void OnCollisionWithCube(BrumeObject collisionShape, BrumeCollisionShape otherShape, List<BrumeCollisionContact> contacts)
{
root.MoveToLastPosition();
}
static float moveSpeed = 100.0f;
static float factor = 0.01f;
protected override void MoveScene(float fElapsedTime)
{
directionalLight.Update();
// Tiny moves
if (BrumeKeyboard.IsPressed(BrumeKey.UpArrow))
{
if (tiny.Animation == null || tiny.Animation.Name != "Walk")
{
tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
}
tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, -1));
root.Pos += root.Dir * factor;
}
else if (BrumeKeyboard.IsPressed(BrumeKey.DownArrow))
{
if (tiny.Animation == null || tiny.Animation.Name != "Walk")
{
tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
}
tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));
root.Pos += -root.Dir * factor;
}
else if (BrumeKeyboard.IsPressed(BrumeKey.RightArrow))
{
if (tiny.Animation == null || tiny.Animation.Name != "Walk")
{
tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
}
tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(-1, 0, 0));
root.Pos += root.Right * factor;
}
else if (BrumeKeyboard.IsPressed(BrumeKey.LeftArrow))
{
if (tiny.Animation == null || tiny.Animation.Name != "Walk")
{
tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
}
tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(1, 0, 0));
root.Pos += -root.Right * factor;
}
else
{
if (tiny.Animation == null || tiny.Animation.Name != "Wave")
{
tiny.Animation = BrumeAnimationManager.GetAnimation("Wave");
tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));
}
}
// FPS camera move
BrumeFPSCamera camera = (BrumeFPSCamera)this.ActiveCamera;
if (camera != null && (this.DebugConsole.debugLevel != 2 || BrumeKeyboard.IsPressed(BrumeKey.Space)))
{
camera.FPSOrient((float)MouseDeltaX / (float)2, (float)MouseDeltaY / (float)2);
// 5 - moving
if (MouseDeltaZ > 0.0f)
moveSpeed *= 0.5f;
else
if (MouseDeltaZ < 0.0f)
moveSpeed /= 0.5f;
if (BrumeKeyboard.IsPressed(BrumeKey.W))
camera.FPSMove(camera.Dir * (fElapsedTime / moveSpeed));
if (BrumeKeyboard.IsPressed(BrumeKey.S))
camera.FPSMove(-camera.Dir * (fElapsedTime / moveSpeed));
if (BrumeKeyboard.IsPressed(BrumeKey.D))
camera.FPSMove(camera.Right * (fElapsedTime / moveSpeed));
if (BrumeKeyboard.IsPressed(BrumeKey.A))
camera.FPSMove(-camera.Right * (fElapsedTime / moveSpeed));
}
// moving
base.MoveScene(fElapsedTime);
}
protected override void RenderScene()
{
base.RenderScene();
}
protected override void AfterRendering()
{
base.AfterRendering();
// exit ?
if (BrumeKeyboard.IsPressed(BrumeKey.Escape))
{
this.Close();
return;
}
}
public static void Main()
{
using (TinyMove game = new TinyMove())
{
game.Play();
}
}
}
}
override protected void GameInit() {
camera1 = new BrumeFPSCamera(this, "camera1", new BrumeVector(0, 0, -5.0f), new BrumeVector(0.0f, 0.0f, 1.0f), new BrumeVector(0.0f, 1.0f, 0.0f));
this.SetActiveCamera(camera1);
this.BufferClearColor = Color.AliceBlue;
this.GlobalAmbientLight = Color.FromArgb(255, 100, 100, 100);
directionalLight = new BrumeDirectionalLight(this, "Directionnal Light", new BrumeVector(-1.0f, -1.0f, 1.0f), new BrumeVector(-1.0f, 1.0f, 1.0f), Color.FromArgb(255, 170, 170, 170));
directionalLight.Specular = Color.FromArgb(255, 255, 255, 255);
directionalLight.Enabled = true;
directionalLight.Update();
root = new BrumeObject(this, "root");
root.Pos.Y = -1.5f;
root.Pos.Z = 5.0f;
BrumeXMesh tinyMesh = new BrumeXMesh(this, "tiny", "tiny_4anim.x", false);
BrumeAnimationManager.AddAnimationsFromMesh(tinyMesh);
tiny = new BrumeLightedObject(this, "tiny");
tiny.Animation = BrumeAnimationManager.GetAnimation("Wave");
tiny.Mesh = tinyMesh;
tiny.Size = 0.005f;
tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));
root.AddChild(tiny);
collisionShape = new BrumeCylinderColored(this, "cylinder");
collisionShape.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));
collisionShape.CollisionEvent += new BrumeCollisionDelegate(OnCollision);
collisionShape.HasGlobalSize = false;
collisionShape.ZSize = 2.5f;
collisionShape.Pos.Y = 1.2f;
collisionShape.AddCollisionShapes(GenerateCollisionShapes(collisionShape));
//collisionShape.Mesh = null; // comment this line to see the cylinder shape
root.AddChild(collisionShape);
BrumeXMesh houseMesh = new BrumeXMesh(this, "house", "room.x", false);
BrumeLightedObject house = new BrumeLightedObject(this, "house");
house.Mesh = houseMesh;
house.Pos = new BrumeVector(0, 1, 10);
house.HasPhysicsAndCollisions = true;
BrumeCubeColored cube = new BrumeCubeColored(this, "cube", Color.HotPink);
cube.AddCollisionShapes(GenerateCollisionShapes(cube));
BrumeSphereColored sph = new BrumeSphereColored(this, "sph");
sph.AddCollisionShapes(GenerateCollisionShapes(sph));
sph.Pos = new BrumeVector(5, 0, 0);
BrumeCylinderColored cyl = new BrumeCylinderColored(this, "cyl");
cyl.AddCollisionShapes(GenerateCollisionShapes(cyl));
cyl.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));
cyl.Pos = new BrumeVector(3, 0, 0);
BrumeOctaederColored oct = new BrumeOctaederColored(this, "oct");
oct.AddCollisionShapes(GenerateCollisionShapes(oct));
oct.Pos = new BrumeVector(8, 0, 0);
BrumeConeColored cone = new BrumeConeColored(this, "cone");
cone.AddCollisionShapes(GenerateCollisionShapes(cone));
cone.Pos = new BrumeVector(-3, 0, 0);
BrumeTorusColored tor = new BrumeTorusColored(this, "tor");
tor.AddCollisionShapes(GenerateCollisionShapes(tor));
tor.Pos = new BrumeVector(-5, 0, 0);
BrumeXMesh tigerMesh = new BrumeXMesh(this, "tiger", "tiger.x", false);
BrumeLightedObject tiger = new BrumeLightedObject(this, "tiger");
tiger.Mesh = tigerMesh;
tiger.AddCollisionShapes(GenerateCollisionShapes(tiger));
tiger.Pos = new BrumeVector(-5, 0, -3);
//tiger.HasPhysicsAndCollisions = true;
BrumeXMesh deskMesh = new BrumeXMesh(this, "desk", "desk.x", false);
BrumeLightedObject desk = new BrumeLightedObject(this, "desk");
desk.Mesh = deskMesh;
desk.AddCollisionShapes(GenerateCollisionShapes(desk));
desk.Pos = new BrumeVector(0, 0, -5);
desk.Size = 0.005f;
}
void OnCollision(BrumeObject collisionShape, BrumeCollisionShape otherShape, List<BrumeCollisionContact> contacts) {
root.MoveToLastPosition();
}
static float moveSpeed = 100.0f;
static float factor = 0.03f;
protected override void MoveScene(float fElapsedTime) {
directionalLight.Update();
// Tiny moves
if (BrumeKeyboard.IsPressed(BrumeKey.NumPad8)) {
if (tiny.Animation == null || tiny.Animation.Name != "Walk") {
tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
}
tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, -1));
root.Pos += root.Dir * factor;
} else if (BrumeKeyboard.IsPressed(BrumeKey.NumPad5)) {
if (tiny.Animation == null || tiny.Animation.Name != "Walk") {
tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
}
tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));
root.Pos += -root.Dir * factor;
} else if (BrumeKeyboard.IsPressed(BrumeKey.NumPad9)) {
if (tiny.Animation == null || tiny.Animation.Name != "Walk") {
tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
}
root.Pos += -root.Up * factor;
} else if (BrumeKeyboard.IsPressed(BrumeKey.NumPad7)) {
if (tiny.Animation == null || tiny.Animation.Name != "Walk") {
tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
}
root.Pos += root.Up * factor;
} else if (BrumeKeyboard.IsPressed(BrumeKey.NumPad6)) {
if (tiny.Animation == null || tiny.Animation.Name != "Walk") {
tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
}
tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(-1, 0, 0));
root.Pos += root.Right * factor;
} else if (BrumeKeyboard.IsPressed(BrumeKey.NumPad4)) {
if (tiny.Animation == null || tiny.Animation.Name != "Walk") {
tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
}
tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(1, 0, 0));
root.Pos += -root.Right * factor;
} else {
if (tiny.Animation == null || tiny.Animation.Name != "Wave") {
tiny.Animation = BrumeAnimationManager.GetAnimation("Wave");
tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));
}
}
// FPS camera move
BrumeFPSCamera camera = (BrumeFPSCamera)this.ActiveCamera;
if (camera != null && (this.DebugConsole.debugLevel != 2 || BrumeKeyboard.IsPressed(BrumeKey.Space))) {
camera.FPSOrient((float)MouseDeltaX / (float)2, (float)MouseDeltaY / (float)2);
// 5 - moving
if (MouseDeltaZ > 0.0f)
moveSpeed *= 0.5f;
else
if (MouseDeltaZ < 0.0f)
moveSpeed /= 0.5f;
if (BrumeKeyboard.IsPressed(BrumeKey.W))
camera.FPSMove(camera.Dir * (fElapsedTime / moveSpeed));
if (BrumeKeyboard.IsPressed(BrumeKey.S))
camera.FPSMove(-camera.Dir * (fElapsedTime / moveSpeed));
if (BrumeKeyboard.IsPressed(BrumeKey.D))
camera.FPSMove(camera.Right * (fElapsedTime / moveSpeed));
if (BrumeKeyboard.IsPressed(BrumeKey.A))
camera.FPSMove(-camera.Right * (fElapsedTime / moveSpeed));
}
// moving
base.MoveScene(fElapsedTime);
}
Users browsing this forum: No registered users and 0 guests