void Airplane::Handle(ProcessEventArg arg) { Time t = timer.GetElapsedTimeAndReset(); float dt = t.AsInt()/1000.0; Matrix<3,3,float> rotM = box->GetRotationMatrix(); box->AddForce(rotM * Vector<3,float>(0,0,1*dt*trottle)); for (vector<Point*>::iterator itr = points.begin(); itr != points.end(); itr++) { Point* p = *itr; Vector<3,float> speedVec = box->GetSpeed(); float speed = speedVec.GetLength(); Vector<3,float> dragVec; if (speed > 0.1) dragVec = -speedVec/speed; Vector<3,float> normal = Vector<3,float>(0,1,0); Vector<3,float> liftVector = (dragVec % normal) % dragVec; if (liftVector.IsZero()) return; float liftLen = liftVector.GetLength(); liftVector.Normalize(); float dotP = dragVec * normal; dotP = fmin(fmax(dotP, -1),1); float attackAngel = asin(dotP); float rho = 1.2f; float area = 5*5; float force = 0.5f * rho * speed * speed * area; Vector<3,float> forceVec = (liftVector * LiftCoefficient(attackAngel,0) + dragVec * DragCoefficient(attackAngel,0)) * force; //logger.info << forceVec << logger.end; box->AddForce(rotM * forceVec, p->forceIdx ); } //box->AddForce(Vector<3,float>(0,lift,0)); return; // Matrix<3,3,float> rotM = box->GetRotationMatrix(); // //logger.info << speed << logger.end; // //speed = rotM*speed; // Quaternion<float> q = Quaternion<float>(rotM); // Vector<3,float> angles = q.GetEulerAngles(); // float pitch = -angles[0]; // //logger.info << "pitch " << pitch << logger.end; // float cl = 1; // float lift = speedVec[2]*cl; //logger.info << "cl " << cl << logger.end; //logger.info << "lift " << lift << logger.end; // Vector<3,float> old_pos; // Quaternion<float> old_rot; // node->GetAccumulatedTransformations(&old_pos, &old_rot); // node->Move(0,0,0.01*dt*trottle); // // calc lift // Vector<3,float> angles = old_rot.GetEulerAngles(); // float pitch = -angles[0]; // float cl = pitch*0.08+0.5; // float lift = speed.GetLengthSquared()*cl*.5*2000.0; // node->Move(0,(lift-9.82)*dt,0); // //logger.info << lift << logger.end; // logger.info << "speed: " << speed.GetLengthSquared() << // " cl: " << cl << // " pitch: " << pitch << // " lift: " << lift << logger.end; // // stuff // Vector<3,float> pos; // Quaternion<float> rot; // node->GetAccumulatedTransformations(&pos, &rot); // // fix down. // if (pos[1] < 0) { // node->SetPosition(Vector<3,float>(pos[0],0.0,pos[2])); // node->GetAccumulatedTransformations(&pos, &rot); // } // Vector<3,float> dx = pos-old_pos; // logger.info << "pos: " << pos << " old_pos: " << old_pos << logger.end; // speed = dx/dt; }