Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


Getting circle quarter based on Vector3 direction


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
23 replies to this topic

#21 AllEightUp   Moderators   -  Reputation: 4234

Like
0Likes
Like

Posted 19 May 2013 - 06:51 PM

There is something I'm unsure about.

 

All I have is "D3DXVECTOR3 gravity", how do I get dirVec and upVec from gravity?

Gravity is a particle effector, it has nothing to do with the dirVec and upVec which are part of the emitter.  I don't know if there is a language barrier here or if you just really don't understand the very basic bits of vector math, either way I suggest you should be able to figure this out on your own.  I'll simply describe how I would write things and then leave it to you to figure out the rest:

 

Emitter

  Vector3f  Position

  Vector3f  Direction  // dirVec

  Vector3f  Up            // upVec

  float         EmissionAngle  // Radians, I don't do degree's...

  float         EmissionVelocity

 

Initialize the emitter (source and target are points in space, source is where the particles start, target is the direction they move towards initially)

  emitter.Position = source.

  emitter.EmissionVelocity = 10.0f;

  emitter.Direction = Normalize( target - source );

  // Check for a valid reference axis, can't be the same as +-direction vector.

  if( Abs( Dot( emitter.Direction, Vector3f( 0, 1, 0 ) ) ) < 0.001f )

     emitter.Up = Normalize( Cross( emitter.Direction, Cross( emitter.Direction, Vector3f( 1, 0, 0 ) ) )

  else

    emitter.Up = Normalize( Cross( emitter.Direction, Cross( emitter.Direction, Vector3f( 0, 1, 0 ) ) )

 

Particle

  Vector3f  Position

  Vector3f  Velocity

 

Effectors

  Vector3f  Gravity

 

Initialize a particle:

  particle.Position = Emitter.Position;

  // Replace dirVec and upVec in the function with references to the emitter data.

  particle.Velocity = GetRandomVector( emitter ) * emitter.EmissionVelocity;

 

Update a particle:

  particle.Position += particle.Velocity * deltat;

  particle.Velocity += effectors.Gravity;

 

 

 

At this point, you should be able to figure this all out using basic vector math.  If you can't figure out the basic vector math being performed here you really need to go learn some of the basics or nothing is going to help you very much further until you do that.  Particles are all about vector math so I can't help further if this is a math problem.  If it is just language, hopefully the above will explain any miss communications.


Sponsor:

#22 Medo3337   Members   -  Reputation: 672

Like
0Likes
Like

Posted 20 May 2013 - 04:56 AM

Well, I'm not native English speaker, here is what I have done so far, still didn't get it to work, is there is anything wrong in the following code?

 

Generate a new particle:

D3DXVECTOR3 direction = gravity - position; // The lines should look at the gravity direction
D3DXVec3Normalize(&direction, &direction);
D3DXVECTOR3 Up;
// Check for a valid reference axis, can't be the same as +-direction vector.
if( abs( D3DXVec3Dot( &direction, &D3DXVECTOR3( 0, 1, 0 ) ) ) < 0.001f )
{
     D3DXVECTOR3 cr;
     D3DXVec3Cross(&cr, &direction, &D3DXVECTOR3( 1, 0, 0 ) );
     D3DXVec3Cross(&Up, &direction, &cr);
     D3DXVec3Normalize( &Up, &Up );
} else {
     D3DXVECTOR3 cr;
     D3DXVec3Cross(&cr, &direction, &D3DXVECTOR3( 0, 1, 0 ) );
     D3DXVec3Cross(&Up, &direction, &cr);
     D3DXVec3Normalize( &Up, &Up );
}

D3DXVECTOR3 randVec = GetRandVector(direction, Up);
particle.velocity += randVec * velocity_var;

 

D3DXVECTOR3 GetRandVector(D3DXVECTOR3 dirVec, D3DXVECTOR3 upVec)
{
  D3DXVec3Normalize(&dirVec, &dirVec);

  D3DXVECTOR3 vVector;

  const float  angleRange = D3DX_PI/2.0f; // 45 degree's.

  float angle  = GetRandMinMax( 0.0f, 2.0f * D3DX_PI );  // Anywhere in the full circle.
  float range = GetRandMinMax( 0.0f, tan( angleRange ) );

  D3DXVECTOR3 offset = upVec * range;

  // Hmm.  No D3DX for vector around vector rotation.  Bah..
  float s = sin( angle );
  float c = cos( angle );
  
  D3DXVECTOR3 temp(
    offset.x*(dirVec.x*dirVec.x*(1-c)+c) + offset.y * (dirVec.x*dirVec.y*(1-c)-dirVec.z*s) + offset.z*(dirVec.x*dirVec.z*(1-c)+dirVec.y*s),
   offset.x*(dirVec.x*dirVec.y*(1-c)+dirVec.z*s) + offset.y*(dirVec.y*dirVec.y*(1-c)+c) + offset.z*(dirVec.y*dirVec.z*(1-c-dirVec.x*s)),
   offset.x*(dirVec.x*dirVec.z*(1-c)-dirVec.y*s) + offset.y*(dirVec.y*dirVec.z*(1-c)+dirVec.x*s)+offset.z*(dirVec.z*dirVec.z*(1-c)+c)
  );


  temp += dirVec;
  D3DXVec3Normalize( &vVector, &temp );

  return vVector;
}

 

 



#23 AllEightUp   Moderators   -  Reputation: 4234

Like
0Likes
Like

Posted 21 May 2013 - 12:08 AM

I don't see anything obvious which unfortunately means this needs to be debugged.  My primary guesses would be that I screwed something up when translating the rotation about vector code from my libraries or that the cross products are in the wrong orders.  Beyond that, sorry can't help without being able to stick it in a debugger and walk through it.



#24 Medo3337   Members   -  Reputation: 672

Like
0Likes
Like

Posted 21 May 2013 - 03:41 AM

BTW, I notice that the variable 'EmissionAngle' is defined and never used.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS