13 Replies - 4981 Views - Last Post: 05 February 2012 - 08:05 AM

#1 mitko900  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 21-January 12

Moving texture to point

Posted 31 January 2012 - 02:20 PM

Hi, guys I am trying to make my 2d texture to go at my 3D model points slowly,but I have some problems with that:


Posted Image

1.My first question is how to make the enemy initialize randomly only behind the black line ?
2.How to get pseudo 3D model coordinates ?
3.After I have the model coordinates how to move my 2d texture slowly to the model ?

Is This A Good Question/Topic? 0
  • +

Replies To: Moving texture to point

#2 mitko900  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 21-January 12

Re: Moving texture to point

Posted 31 January 2012 - 02:55 PM

I forgot to mention that I am drawing randomly the enemy this way:
   Vector2 position = new Vector2(random.Next(0, 1000), random.Next(0, 1000));
                    eninit = new Enemy(enemyTexture, position, 1000, 100, 0.5f);
//adding enemy to the list....
                    enemies.Add(eninit);

And my translation for the model is:
          Matrix translation = Matrix.CreateTranslation(
                    modelTransformaton.X, modelTransformaton.Y, -modelTransformaton.Z);

Where modelTransformation is a Matrix4x4.
Was This Post Helpful? 0
  • +
  • -

#3 ShadowsEdge19  Icon User is offline

  • D.I.C Addict

Reputation: 142
  • View blog
  • Posts: 664
  • Joined: 16-January 10

Re: Moving texture to point

Posted 31 January 2012 - 03:52 PM

You need to look into controlling the drawing order (z-buffer) for your objects, if you look around your room/office you'll see exactly what I'm talking about. Pick any object in front of you that is visible and you'll notice that it's in front of something else because it's closer to you. The same thing applies to 3D games, since we're using XNA that uses the LHR (Left Hand Rule), so that means Z = 0 is the closest thing possible to the screen and anything else is either behind the screen (0-N) or further away (0+N).

So you will need to figure out a way of making an artificial draw order for your 2D objects and then use it with the Z axis of your 3D objects to work out the draw order for all your objects together.
Was This Post Helpful? 2
  • +
  • -

#4 mitko900  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 21-January 12

Re: Moving texture to point

Posted 02 February 2012 - 05:15 AM

How can I draw a random model each time I call my enemy class ?
I tried this way:
 if ((texture != null) && (texture.Meshes.Count > 0))
            {
                Matrix[] transforms = new Matrix[texture.Bones.Count];
                texture.CopyAbsoluteBoneTransformsTo(transforms);
              
                foreach (ModelMesh meshh in texture.Meshes)
                {                   
                    foreach (BasicEffect effect in meshh.Effects)
                    {
                        effect.EnableDefaultLighting();
                        effect.World = transforms[meshh.ParentBone.Index] *
                            Matrix.CreateRotationY(0.0f)
                            * Matrix.CreateTranslation(Vector3.Zero);
                        effect.View = Matrix.CreateLookAt(new Vector3(0.0f, 50.0f, 5000.0f),
                           position, Vector3.Up);
                        effect.Projection = Matrix.CreatePerspectiveFieldOfView(
                            MathHelper.ToRadians(60.0f), aspectRatio,
                            1.0f, 10000.0f);
                    }                  
                    meshh.Draw();
                }            
            }            

and in the view matrix the position value x,y are always random from 0 to 700,but when I start the game windows and call the enemy class 3 times it draw me three objects at the same coordinates, but the values in position are always different.
Was This Post Helpful? 0
  • +
  • -

#5 mitko900  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 21-January 12

Re: Moving texture to point

Posted 02 February 2012 - 01:59 PM

Someone ?
Was This Post Helpful? 0
  • +
  • -

#6 ShadowsEdge19  Icon User is offline

  • D.I.C Addict

Reputation: 142
  • View blog
  • Posts: 664
  • Joined: 16-January 10

Re: Moving texture to point

Posted 02 February 2012 - 04:10 PM

Where are you assigning each model a random x, y, z value? If they are all the same each time then it's not the drawing that needs changing.
Was This Post Helpful? 0
  • +
  • -

#7 mitko900  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 21-January 12

Re: Moving texture to point

Posted 03 February 2012 - 03:59 AM

I forgot to post the random code, sorry:
 void AddEnemy()
        {            
            if (enemies.Count <= 10)
            {
                previousEnemyTime = TimeSpan.Zero;
                nextEnemyTime = TimeSpan.FromSeconds(10.0f);                               
                Microsoft.Xna.Framework.Vector3 position = new Microsoft.Xna.Framework.Vector3(random.Next(0, 300) * (-1), random.Next(0, 100) * (-1), 0.0f);              
                eninit = new Enemy(secondModel, position, 100, 100, 0.5f);
//List<Enemy>                
enemies.Add(eninit);
            }
        }

Was This Post Helpful? 0
  • +
  • -

#8 mitko900  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 21-January 12

Re: Moving texture to point

Posted 03 February 2012 - 04:15 PM

Ok is there a easy way to understand when two models are collided ?

If it was in 2d I would use:
rectangle2 = new Microsoft.Xna.Framework.Rectangle((int)enemy[i].Position.X, (int)enemy[i].Position.Y, enemy[i].Width, enemy[i].Height);
                    

and then check if the first rectangle2.Intersects(rectangle1).
It seems that for model is more complicated.
Was This Post Helpful? 0
  • +
  • -

#9 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Moving texture to point

Posted 03 February 2012 - 04:36 PM

Bounding Boxes

You'll want to build BoundingBoxes for the objects and check if they are colliding. Or if the model is an odd shape, there are a couple of other types of Bounding Volumes that you could use.

This post has been edited by Kilorn: 03 February 2012 - 04:37 PM

Was This Post Helpful? 0
  • +
  • -

#10 mitko900  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 21-January 12

Re: Moving texture to point

Posted 04 February 2012 - 12:05 PM

Is there some samples or something ?
Was This Post Helpful? 0
  • +
  • -

#11 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Moving texture to point

Posted 04 February 2012 - 02:39 PM

Riemer has a great tutorial series that deals with 3D objects. Where you create a 3D flight simulator. Here is the collision portion of that series.
Was This Post Helpful? 0
  • +
  • -

#12 mitko900  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 21-January 12

Re: Moving texture to point

Posted 04 February 2012 - 02:59 PM

Yeah really its great tutorial,but I find out that BoundingSphere will do the job, but it seems that I have some problems make it work:
 if ((texture != null) && (texture.Meshes.Count > 0))
            {
                Matrix[] transforms = new Matrix[texture.Bones.Count];
                texture.CopyAbsoluteBoneTransformsTo(transforms);

                foreach (ModelMesh meshh in texture.Meshes)
                {
                    if (this.sphere.Radius == 0)
                        this.sphere = meshh.BoundingSphere;
                    else
                        this.sphere = BoundingSphere.CreateMerged(sphere, meshh.BoundingSphere);  
                    foreach (BasicEffect effect in meshh.Effects)
                    {
                        effect.EnableDefaultLighting();
                        effect.World = transforms[meshh.ParentBone.Index] *
                            Matrix.CreateRotationY(modelRotation)
                            * Matrix.CreateTranslation(position);                        
                        effect.View = Matrix.CreateLookAt(new Vector3(0.0f, 50.0f, 5000.0f),
                          Vector3.Zero, Vector3.Up);
                        effect.Projection = Matrix.CreatePerspectiveFieldOfView(
                            MathHelper.ToRadians(45.0f), aspectRatio,
                            1.0f, 10000.0f);
                        cc = transforms[meshh.ParentBone.Index] *
                            Matrix.CreateRotationY(modelRotation)
                            * Matrix.CreateTranslation(position); 
                    }
                    meshh.Draw();
                }
                this.sphere.Radius = 50.0f;
                sphere.Center = this.position;
                sphere.Transform(cc);
            }
        }

I think that while my enemy is moving the Bounding Sphere don't move , and I wasn't able to find any error.
Any ideas ?
Was This Post Helpful? 0
  • +
  • -

#13 mitko900  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 21-January 12

Re: Moving texture to point

Posted 05 February 2012 - 06:56 AM

Ok I have some progress ,and some problems:

Posted Image
The green sphere is the player and the red one the enemy,in this picture the enemy collided successfully with the player.
The problem is that the sphere is too far from the model,here the code which draw the sphere:
pos = Matrix.Invert(translation).Translation;

                           view1 = transforms[mesh.ParentBone.Index] *
                           Matrix.CreateScale(1 / mesh.BoundingSphere.Radius) *
                           scaling * rotation * translation;
                           projection1 = Matrix.CreatePerspective(
                           1, 1 / GraphicsDevice.Viewport.AspectRatio, 1f, 10000);
 modelsp.Radius = 1000.0f;                                      
                    modelsp.Center = pos;                   
                    DrawShape.AddBoundingSphere(modelsp, Microsoft.Xna.Framework.Color.Green);
DrawShape.Draw(gameTime, view1, projection1);





any ideas ?

This post has been edited by mitko900: 05 February 2012 - 07:08 AM

Was This Post Helpful? 0
  • +
  • -

#14 mitko900  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 21-January 12

Re: Moving texture to point

Posted 05 February 2012 - 08:05 AM

I forgot to add this line to my code:
modelsp = BoundingSphere.CreateMerged(modelsp, mesh.BoundingSphere);


Posted Image
but collision now is not active :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1