christian.wolf2 Posted August 16, 2017 Share Posted August 16, 2017 Hello, I currently setup a simple project where an entity moves along an path, defined by an bezier curve. To move the object, I tried to use the following code: dvec3 pos; const double* start = startNode->getPosition(); const double* end = endNode->getPosition(); float mt = 1 - t; float mt2 = mt * mt; float t2 = t * t; pos.x = mt2 * start[0] + 2 * mt * t * quadraticPoint[0] + t2 * end[0]; pos.y = mt2 * start[1] + 2 * mt * t * quadraticPoint[1] + t2 * end[1]; pos.z = mt2 * start[2] + 2 * mt * t * quadraticPoint[2] + t2 * end[2]; dvec3 direction = getQuadraticTangent(t); dmat4 mat = setTo(pos, direction, vec3(0.f, .0f, 1.f)); obj->setWorldTransform(mat * rotateX((double)-90.f)* rotateZ((double)180.f)); The t-value increased between 0 and 1 while adding the iFPS each frame. With this lines of code I am running into the issue, that my entity is not facing in the direction it travels, even the direction vector is successfully calculated during the process (I rendered it into my scene). After a while I got an idea and modified my code a little bit: dvec3 pos; const double* start = startNode->getPosition(); const double* end = endNode->getPosition(); t = getLerpTimeFromArcLengthLUT(t); float mt = 1 - t; float mt2 = mt * mt; float t2 = t * t; pos.x = mt2 * start[0] + 2 * mt * t * quadraticPoint[0] + t2 * end[0]; pos.y = mt2 * start[1] + 2 * mt * t * quadraticPoint[1] + t2 * end[1]; pos.z = mt2 * start[2] + 2 * mt * t * quadraticPoint[2] + t2 * end[2]; vec3 direction = getQuadraticTangent(t); obj->setPosition(pos); obj->setDirection(direction, vec3(0.f, 0.f, 1.f)); obj->setWorldTransform(obj->getWorldTransform() * rotateX((double)-90.f)* rotateZ((double)180.f)); For this piece of code, the entity moves and transforms as expected. So now I try to understand why my changes in the last three lines got a complete different result? I expected, that setTo and setWorldTransform does exactly the same thing than setDirection and setWorldTransform. What lines in the upper example needs to be modified, that the result will be the same as in the bottom one? And on top of that, which is more performance friendly? Best regards and many thanks in advance Christian Link to comment
alexander Posted August 17, 2017 Share Posted August 17, 2017 Hi! Oops. There is some issue with the argument names in the setTo / lookAt functions. "Direction" is the target point. So, if you change your code like this: dmat4 mat = setTo(pos, pos + direction, vec3(0.f, .0f, 1.f)); it will work. We will correct the manual (and the names of arguments in the API) in the future release. Thank you! Best regards, Alexander Link to comment
christian.wolf2 Posted August 17, 2017 Author Share Posted August 17, 2017 Hi Alex, many thanks, modified the line of code and worked for me. Best regards, Christian Link to comment
Recommended Posts