vector for ball velocity

Started by
-1 comments, last by anders211 10 years, 3 months ago

shotTime - time between pressing button "D" and releasing button,

rigthTime - time between pressing button "RIGHT" and releasing button

#define MAX_SPEED 27.7777f //[m/s] ~= 100km/h
#define MAX_KICK_THRESHOLD 2000 //[ms]
How to write general algorithm for example like this:
- When only "D" is pressed then vector must have direction (0,1,1),so it has angle 45 over axis Z.
- When "D" pressed and "LEFT" and the delay of pressing LEFT and D is the same then vector is (-1,1,1)
- When "D" pressed and "RIGHT" and the delay of pressing LEFT and D is the same then vector is (1,1,1)
- When "D" pressed and UP and the delay of pressing UP and D is the same then vector is (0,1,0)
- When "D" pressed and DOWN and the delay of pressing DOWN and D is the same then vector is (0,0,1)
In additional to above output vector must have legth in relative to MAX_KICK_THRESHOLD and MAX_SPEED, so when delay of pressing is 1 [s] then the speed should be 50km/h so lenght of the vector should be 27.7777f/2.
Here is my algorithm but according to my calculation it doesn't generate the right output data:

void Ball::kick(DWORD shotTime, DWORD rightTime, DWORD leftTime, DWORD upTime, DWORD downTime)
{
if(shotTime > MAX_KICK_THRESHOLD) 
shotTime = MAX_KICK_THRESHOLD;


//calculate V parameters (length of the vector and coordinates)
float length = MAX_SPEED * shotTime / MAX_KICK_THRESHOLD;


float upTimeF = static_cast<float>(upTime) / static_cast<float>(shotTime);       //0..1
float downTimeF = static_cast<float>(downTime) / static_cast<float>(shotTime);   //0..1
float facYZ = upTimeF - downTimeF;
facYZ = d3d::DEGREE_45 + d3d::DEGREE_45 * facYZ; //angle
D3DXVECTOR3 up = D3DXVECTOR3(0, length*sin(facYZ), length*cos(facYZ));


float leftTimeF = static_cast<float>(leftTime) / static_cast<float>(shotTime);   //0..1
float rightTimeF = static_cast<float>(rightTime) / static_cast<float>(shotTime); //0..1
    float facXZ = leftTimeF - rightTimeF;
facXZ = d3d::DEGREE_90 + d3d::DEGREE_45 * facXZ; //angle
D3DXVECTOR3 left = D3DXVECTOR3(length*cos(facXZ), 0, length*sin(facXZ));


D3DXVECTOR3 V = up + left;
}

This topic is closed to new replies.

Advertisement