/** * Update the animation. This method will be called by the * scenegraph rendering function just before the animated * branch will be rendered. */ int CRRCControlSurfaceAnimation::update() { // calculate the deflection angle by summing up the contribution // of all mapped control inputs times the individual gain float angle = 0.0f; for (int i = 0; i < (int)datasource.size(); i++) { angle += *datasource[i] * source_gain[i] * max_angle; } // limit to max_angle (caution: max_angle could be < 0.0, so we use the abs value!) if (angle > abs_max_angle) { angle = abs_max_angle; } else if (angle < -abs_max_angle) { angle = -abs_max_angle; } // calculate transformation matrix for surface rotation sgQuat q; sgMat4 qmat; sgAngleAxisToQuat(q, angle, axis); sgQuatToMatrix(qmat, q); sgMultMat4(current_transformation, qmat, move_to_origin); sgPostMultMat4(current_transformation, move_back); ((ssgTransform*)anim_branch)->setTransform(current_transformation); return 1; }
/** \brief Draw the airplane shadow * * This method actually does not draw anything. It only * updates the aircraft shadow's transformation node in the * scenegraph with the aircraft shadow's current position and * orientation. The actual drawing is done by the global * ssgCullAndDraw() call. * * \todo calculate proper shadow rotation * \todo adjust shadow location to match real terrain height * * \param airplane pointer to the airplane's FDM object */ void CRRCAirplaneLaRCSimSSG::draw_shadow(FDMBase* airplane, float shadow_matrix[4][4]) { CRRCMath::Vector3 pos = airplane->getPos(); sgMat4 m; model_trans->getTransform(m); sgPostMultMat4(m, shadow_matrix); //jwtodoshadow m[3][1] += 0.1; shadow_trans->setTransform(m); }
void calc_coord(void) { sgMat4 m, m2; int i, j; tFace *curFace; float width, height; float scale, offX, offY; int largerRow; float maxWidth; int col; ssgBranch *branch; ColWidth = (float*)calloc(NbMaxCols, sizeof(float)); fprintf(stderr, "After Rotation:\n"); largerRow = 0; maxWidth = 0; for (i = 0; i < NbRows; i++) { curFace = GF_TAILQ_FIRST(&(Row[i].faces)); while (curFace) { if (curFace->isPresent) { branch = curFace->branch->getParent(0); if (branch->isAKindOf(_SSG_TYPE_BASETRANSFORM)) { ((ssgBaseTransform*)branch)->getTransform(m2); curFace->align[0] *= m2[3][0]; curFace->align[1] *= m2[3][1]; curFace->align[2] *= m2[3][2]; fprintf(stderr, "Align face %s : %f %f %f\n", curFace->faceName, curFace->align[0], curFace->align[1], curFace->align[2]); } sgMakeTransMat4(m, curFace->align); sgMakeIdentMat4(m2); for (j = 0; j < 3; j++) { m2[j][j] = curFace->lscale[j]; } sgPostMultMat4(m, m2); sgMakeRotMat4(m2, curFace->xform.hpr); sgPostMultMat4(m, m2); sgCopyMat4(curFace->mat, m); sgXformPnt3(curFace->sbbmin, curFace->lbbmin, m); sgXformPnt3(curFace->sbbmax, curFace->lbbmax, m); fprintf(stderr, " Face %s : %f %f %f --- %f %f %f\n", curFace->faceName, curFace->sbbmin[0], curFace->sbbmin[1], curFace->sbbmin[2], curFace->sbbmax[0], curFace->sbbmax[1], curFace->sbbmax[2]); curFace->lwidth = 2.0 * MAX(fabs(curFace->sbbmin[0]), fabs(curFace->sbbmax[0])); curFace->lheight = 2.0 * MAX(fabs(curFace->sbbmin[2]), fabs(curFace->sbbmax[2])); //curFace->lwidth = fabs(curFace->sbbmin[0] - curFace->sbbmax[0]); //curFace->lheight = fabs(curFace->sbbmin[2] - curFace->sbbmax[2]); Row[i].lwidth += curFace->lwidth; Row[i].lheight = MAX(Row[i].lheight, curFace->lheight); } curFace = GF_TAILQ_NEXT(curFace, link); } if (Row[i].lwidth > maxWidth) { maxWidth = Row[i].lwidth; largerRow = i; } } height = 0; fprintf(stderr, "After Scaling:\n"); for (i = 0; i < NbRows; i++) { height += Row[i].lheight; } width = maxWidth; scale = (float)ImgSize / MAX(width, height); curFace = GF_TAILQ_FIRST(&(Row[largerRow].faces)); i = 0; fprintf(stderr, "Columns : "); while (curFace) { ColWidth[i] = curFace->lwidth * scale; fprintf(stderr, "%.2f ", ColWidth[i]); curFace = GF_TAILQ_NEXT(curFace, link); i++; } fprintf(stderr, "\n"); fprintf(stderr, "Total Width = %.2f Height = %.2f\n", width, height); fprintf(stderr, "Image Width = %.2f Height = %.2f\n", width*scale, height*scale); offY = - (float)ImgSize / 2.0; for (i = 0; i < NbRows; i++) { curFace = GF_TAILQ_FIRST(&(Row[i].faces)); offY += Row[i].lheight*scale / 2.0; col = 0; offX = - (float)ImgSize / 2.0; while (curFace) { if (curFace->isPresent) { sgCopyMat4(m, curFace->mat); curFace->texScale = scale; sgMakeIdentMat4(m2); for (j = 0; j < 3; j++) { m2[j][j] = scale; } sgPostMultMat4(m, m2); sgXformPnt3(curFace->sbbmin, curFace->lbbmin, m); sgXformPnt3(curFace->sbbmax, curFace->lbbmax, m); offX += ColWidth[col] / 2.0; curFace->offset[0] = offX; curFace->offset[2] = offY; offX += ColWidth[col] / 2.0; sgMakeTransMat4(m2, curFace->offset); sgPostMultMat4(m, m2); sgCopyMat4(curFace->mat, m); curFace->branch->setTransform(m); } else { offX += ColWidth[col]; } col++; curFace = GF_TAILQ_NEXT(curFace, link); } offY += Row[i].lheight*scale / 2.0; } }