Files
2025-12-15 22:10:55 +08:00

711 lines
24 KiB
C++

/***********************************************************************************************************************
*
* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc.
* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret
* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event
* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized
* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the
* scope and manner of such use.
*
***********************************************************************************************************************/
/**
\file AnimDef.cpp
Library of common functions to define Motions and Keyframes
***********************************************************************************************************************/
// Do not define INITIALIZE_A3D_API here. It should be only included once in a project.
#include "AnimDef.hpp"
//######################################################################################################################
// creates a view
A3DStatus CreateView(A3DPDFDocument* pDoc, A3DPDF3DArtwork* p3DArtwork,
A3DDouble dPosX, A3DDouble dPosY, A3DDouble dPosZ,
A3DDouble dTargetX, A3DDouble dTargetY, A3DDouble dTargetZ,
A3DDouble dUpX, A3DDouble dUpY, A3DDouble dUpZ,
A3DPDFEProjectionMode eProjectionMode,
A3DDouble dZoomFactor, A3DDouble dFieldOfView,
A3DBool bIsDefault, const A3DUTF8Char* pcViewName,
A3DPDFView** ppView)
{
A3DPDFViewData sViewData;
A3D_INITIALIZE_DATA(A3DPDFViewData, sViewData);
sViewData.m_sViewBackgroundColor.m_dBlue = 0.25;
sViewData.m_sViewBackgroundColor.m_dGreen = 0.25;
sViewData.m_sViewBackgroundColor.m_dRed = 0.25;
sViewData.m_eViewLighting = kA3DPDFLightCADOptimized;
sViewData.m_eViewRenderingStyle = kA3DPDFRenderingSolid;
sViewData.m_sPosition.m_dX = dPosX;
sViewData.m_sPosition.m_dY = dPosY;
sViewData.m_sPosition.m_dZ = dPosZ;
sViewData.m_sTarget.m_dX = dTargetX;
sViewData.m_sTarget.m_dY = dTargetY;
sViewData.m_sTarget.m_dZ = dTargetZ;
sViewData.m_sUpVector.m_dX = dUpX;
sViewData.m_sUpVector.m_dY = dUpY;
sViewData.m_sUpVector.m_dZ = dUpZ;
sViewData.m_eProjectionMode = eProjectionMode;
sViewData.m_dZoomFactor = dZoomFactor; // only valid for orthographic projection
sViewData.m_dFieldOfView = dFieldOfView; // only valid for perspective projection
sViewData.m_bIsDefault = bIsDefault;
size_t iLen = strlen(pcViewName);
sViewData.m_pcExternalName = new A3DUTF8Char[iLen+1];
strcpy(sViewData.m_pcExternalName, pcViewName);
A3DPDFViewCreate(pDoc, &sViewData, ppView);
delete []sViewData.m_pcExternalName;
A3DPDF3DArtworkAddView(p3DArtwork, *ppView);
return A3D_SUCCESS;
}
static double stadMatrix[16];
static void stMatrixMatrixMult(double m[16], const double o[16])
{
memcpy(stadMatrix, m, 16*sizeof(double));
stadMatrix[12] = 0;
stadMatrix[13] = 0;
stadMatrix[14] = 0;
stadMatrix[15] = 1;
m[0] = stadMatrix[0] * o[0] + stadMatrix[4] * o[1] + stadMatrix[8] * o[2] + stadMatrix[12] * o[3];
m[1] = stadMatrix[1] * o[0] + stadMatrix[5] * o[1] + stadMatrix[9] * o[2] + stadMatrix[13] * o[3];
m[2] = stadMatrix[2] * o[0] + stadMatrix[6] * o[1] + stadMatrix[10] * o[2] + stadMatrix[14] * o[3];
m[3] = stadMatrix[3] * o[0] + stadMatrix[7] * o[1] + stadMatrix[11] * o[2] + stadMatrix[15] * o[3];
m[4] = stadMatrix[0] * o[4] + stadMatrix[4] * o[5] + stadMatrix[8] * o[6] + stadMatrix[12] * o[7];
m[5] = stadMatrix[1] * o[4] + stadMatrix[5] * o[5] + stadMatrix[9] * o[6] + stadMatrix[13] * o[7];
m[6] = stadMatrix[2] * o[4] + stadMatrix[6] * o[5] + stadMatrix[10] * o[6] + stadMatrix[14] * o[7];
m[7] = stadMatrix[3] * o[4] + stadMatrix[7] * o[5] + stadMatrix[11] * o[6] + stadMatrix[15] * o[7];
m[8] = stadMatrix[0] * o[8] + stadMatrix[4] * o[9] + stadMatrix[8] * o[10] + stadMatrix[12] * o[11];
m[9] = stadMatrix[1] * o[8] + stadMatrix[5] * o[9] + stadMatrix[9] * o[10] + stadMatrix[13] * o[11];
m[10]= stadMatrix[2] * o[8] + stadMatrix[6] * o[9] + stadMatrix[10] * o[10] + stadMatrix[14] * o[11];
m[11]= stadMatrix[3] * o[8] + stadMatrix[7] * o[9] + stadMatrix[11] * o[10] + stadMatrix[15] * o[11];
m[12]= stadMatrix[0] * o[12] + stadMatrix[4] * o[13] + stadMatrix[8] * o[14] + stadMatrix[12] * o[15];
m[13]= stadMatrix[1] * o[12] + stadMatrix[5] * o[13] + stadMatrix[9] * o[14] + stadMatrix[13] * o[15];
m[14]= stadMatrix[2] * o[12] + stadMatrix[6] * o[13] + stadMatrix[10] * o[14] + stadMatrix[14] * o[15];
m[15]= stadMatrix[3] * o[12] + stadMatrix[7] * o[13] + stadMatrix[11] * o[14] + stadMatrix[15] * o[15];
}
#define X 0
#define Y 1
#define Z 2
#define W 3
void hoopsQuaternionToMatrix(double * quaternion, double *matrix)
{
double s, xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz;
s = 2.0/(quaternion[X]*quaternion[X] + quaternion[Y]*quaternion[Y] + quaternion[Z]*quaternion[Z] + quaternion[W]*quaternion[W]);
xs = quaternion[X]*s; ys = quaternion[Y]*s; zs = quaternion[Z]*s;
wx = quaternion[W]*xs; wy = quaternion[W]*ys; wz = quaternion[W]*zs;
xx = quaternion[X]*xs; xy = quaternion[X]*ys; xz = quaternion[X]*zs;
yy = quaternion[Y]*ys; yz = quaternion[Y]*zs; zz = quaternion[Z]*zs;
matrix[0] = 1.0 - (yy+zz);
matrix[1] = xy + wz;
matrix[2] = xz - wy;
matrix[4] = xy - wz;
matrix[5] = 1.0 - (xx + zz);
matrix[6] = yz + wx;
matrix[8] = xz + wy;
matrix[9] = yz - wx;
matrix[10] = 1.0 - (xx + yy);
}
void stLoadIdentityMatrix(double adMat[16])
{
int i;
for(i = 1; i < 15; i++)
adMat[i]=0;
adMat[0] = adMat[5] = adMat[10] = adMat[15] = 1.;
}
void stApplyPositionToMatrix(double adMat[16], double dPosX, double dPosY, double dPosZ)
{
adMat[12] += dPosX; adMat[13] += dPosY; adMat[14] += dPosZ;
}
void stCopyMatrix(A3DDouble adMatrix[16], double adMat[16])
{
int i;
for(i = 0; i < 16; i++)
adMatrix[i] = adMat[i];
}
void AddKeyFrameTransfo(A3DPDFAnimKeyFrame**& ppKeyFrame, int& idxkeyframe,
A3DDouble dTime, double adMat[16],
bool bQuat, double dQuatW, double dQuatX, double dQuatY, double dQuatZ,
double dPosX, double dPosY, double dPosZ,
double dR, double dG, double dB,
double dOpacity,
A3DPDFERenderingStyle eRenderingStyle,
int iApplyAppearance = 0)
{
A3DPDFAnimKeyFrame* pKeyFrame;
A3DPDFAnimKeyFrameData sKeyFrameData;
A3D_INITIALIZE_DATA(A3DPDFAnimKeyFrameData, sKeyFrameData);
sKeyFrameData.m_dTime = dTime;
if(iApplyAppearance == 0)
sKeyFrameData.m_iInterpolationMask =
kA3DPDFInterpolateTransformationMatrix |
kA3DPDFInterpolateAppearanceColor |
kA3DPDFInterpolateAppearanceTransparency;
else if(iApplyAppearance == 1)
sKeyFrameData.m_iInterpolationMask =
kA3DPDFInterpolateTransformationMatrix;
else if(iApplyAppearance == 2)
sKeyFrameData.m_iInterpolationMask = 0;
A3DPDFAnimAppearanceData sAppearanceData;
A3D_INITIALIZE_DATA(A3DPDFAnimAppearanceData, sAppearanceData);
sAppearanceData.m_sColor.m_dRed = dR;
sAppearanceData.m_sColor.m_dGreen = dG;
sAppearanceData.m_sColor.m_dBlue = dB;
sAppearanceData.m_dOpacity = dOpacity;
sAppearanceData.m_eRenderingStyle = eRenderingStyle;
sKeyFrameData.m_psAppearanceData = &sAppearanceData;
A3DPDFAnimTransformationData sTransfoData;
A3D_INITIALIZE_DATA(A3DPDFAnimTransformationData, sTransfoData);
sKeyFrameData.m_psTransformationData = &sTransfoData;
if(bQuat)
{
double adQuat[4];
adQuat[0] = dQuatW;
adQuat[1] = dQuatX;
adQuat[2] = dQuatY;
adQuat[3] = dQuatZ;
double adRot[16];
stLoadIdentityMatrix(adRot);
hoopsQuaternionToMatrix(adQuat, adRot);
stMatrixMatrixMult(adMat, adRot);
}
stApplyPositionToMatrix(adMat, dPosX, dPosY, dPosZ);
stCopyMatrix(sTransfoData.m_adMatrix, adMat);//better would be to cast...
A3DPDFAnimKeyFrameCreate(&sKeyFrameData, &pKeyFrame);
ppKeyFrame[idxkeyframe++] = pKeyFrame;
}
void AddKeyFrameAppearance(A3DPDFAnimKeyFrame**& ppKeyFrame, int& idxkeyframe,
A3DDouble dTime,
int iInterpolationMask,
double dR, double dG, double dB,
double dOpacity,
A3DPDFERenderingStyle eRenderingStyle)
{
A3DPDFAnimKeyFrame* pKeyFrame;
A3DPDFAnimKeyFrameData sKeyFrameData;
A3D_INITIALIZE_DATA(A3DPDFAnimKeyFrameData, sKeyFrameData);
sKeyFrameData.m_dTime = dTime; // seconds
sKeyFrameData.m_iInterpolationMask = iInterpolationMask;
A3DPDFAnimAppearanceData sAppearanceData;
A3D_INITIALIZE_DATA(A3DPDFAnimAppearanceData, sAppearanceData);
// -1 + bool at false should be specified to not take these values into account:
// -1 for colors and kA3DPDFInterpolateAppearanceColor not specified => no color change ;
// -1 for opacity and kA3DPDFInterpolateAppearanceTransparency not specified => no opacity change
sAppearanceData.m_sColor.m_dRed = dR;
sAppearanceData.m_sColor.m_dGreen = dG;
sAppearanceData.m_sColor.m_dBlue = dB;
sAppearanceData.m_dOpacity = dOpacity;
sAppearanceData.m_eRenderingStyle = eRenderingStyle;
sKeyFrameData.m_psAppearanceData = &sAppearanceData;
A3DPDFAnimKeyFrameCreate(&sKeyFrameData, &pKeyFrame);
ppKeyFrame[idxkeyframe++] = pKeyFrame;
}
A3DStatus CreateMotionAppearInit(A3DPDFAnimMotion**& ppMotion, int& idxMotion,
A3DMiscMarkupLinkedItem** ppTargets, int idxTargets,
double dColInitR, double dColInitG, double dColInitB,
double dOpacInit,
A3DPDFERenderingStyle eRenderingStyle,
double dTimeOffset,
double& dTimeDuration)
{
A3DPDFAnimMotion* pMotion;
A3DPDFAnimMotionData2 sMotionData;
A3D_INITIALIZE_DATA(A3DPDFAnimMotionData2, sMotionData);
// --- KEYFRAMES
const int INBKEYFRAMESALLOC = 10;
A3DPDFAnimKeyFrame** ppKeyFrame;
ppKeyFrame = (A3DPDFAnimKeyFrame**) malloc(INBKEYFRAMESALLOC * A3DUns32(sizeof(A3DPDFAnimKeyFrame*)));
int idxKeyFrame = 0;
if(! (dColInitR == -1 && dColInitG == -1 && dColInitB == -1) )
{
AddKeyFrameAppearance(ppKeyFrame, idxKeyFrame, 0.0,
0, //kA3DPDFInterpolateAppearanceColor,
dColInitR, dColInitG, dColInitB,
-1, // opacity
eRenderingStyle); // rendering style
AddKeyFrameAppearance(ppKeyFrame, idxKeyFrame, 0.1, // set 0.1 second but it could be any time before the end (just the previous keyframe counts)
0, //kA3DPDFInterpolateAppearanceColor,
-1,-1,-1, // RGB
-1, // opacity
eRenderingStyle); // rendering style
}
if(! (dOpacInit == -1))
{
AddKeyFrameAppearance(ppKeyFrame, idxKeyFrame, 0.0,
0, //kA3DPDFInterpolateAppearanceTransparency,
-1, -1, -1,
dOpacInit, // opacity
eRenderingStyle); // rendering style
AddKeyFrameAppearance(ppKeyFrame, idxKeyFrame, 0.1, // set 0.1 second but it could be any time before the end (just the previous keyframe counts)
0, //kA3DPDFInterpolateAppearanceTransparency,
-1, -1, -1,
dOpacInit, // opacity
eRenderingStyle); // rendering style
}
// --- MOTION CREATION
sMotionData.m_bRepeat = false;
sMotionData.m_dTimeOffset = dTimeOffset;
sMotionData.m_iNumTargets = idxTargets;
sMotionData.m_ppTargets = ppTargets;
sMotionData.m_iNumKeyFrames = idxKeyFrame;
sMotionData.m_ppKeyFrames = ppKeyFrame;
A3DPDFAnimMotionCreate2(&sMotionData, &pMotion);
ppMotion[idxMotion++] = pMotion;
dTimeDuration = 0.1;
return A3D_SUCCESS;
}
A3DStatus CreateMotionFlash(A3DPDFAnimMotion**& ppMotion, int& idxMotion,
A3DMiscMarkupLinkedItem** ppTargets, int idxTargets,
double dColInitR, double dColInitG, double dColInitB,
double dColBlinkR, double dColBlinkG, double dColBlinkB,
A3DPDFERenderingStyle eRenderingStyle,
double dTimeOffset,
double& dTimeDuration)
{
A3DPDFAnimMotion* pMotion;
A3DPDFAnimMotionData2 sMotionData;
A3D_INITIALIZE_DATA(A3DPDFAnimMotionData2, sMotionData);
// --- KEYFRAMES
const int INBKEYFRAMESALLOC = 10;
A3DPDFAnimKeyFrame** ppKeyFrame;
ppKeyFrame = (A3DPDFAnimKeyFrame**) malloc(INBKEYFRAMESALLOC * A3DUns32(sizeof(A3DPDFAnimKeyFrame*)));
int idxKeyFrame = 0;
// flash yellow to red
AddKeyFrameAppearance(ppKeyFrame, idxKeyFrame, 0.0,
kA3DPDFInterpolateAppearanceColor ,
dColInitR, dColInitG, dColInitB, // RGB
-1.0, // opacity
eRenderingStyle ); // rendering style
AddKeyFrameAppearance(ppKeyFrame, idxKeyFrame, 0.16,
kA3DPDFInterpolateAppearanceColor,
dColBlinkR, dColBlinkG, dColBlinkB, // RGB
-1.0, // opacity
eRenderingStyle); // rendering style
AddKeyFrameAppearance(ppKeyFrame, idxKeyFrame, 0.32,
kA3DPDFInterpolateAppearanceColor ,
dColInitR, dColInitG, dColInitB, // RGB
-1.0, // opacity
eRenderingStyle); // rendering style
AddKeyFrameAppearance(ppKeyFrame, idxKeyFrame, 0.49,
kA3DPDFInterpolateAppearanceColor,
dColBlinkR, dColBlinkG, dColBlinkB, // RGB
-1.0, // opacity
eRenderingStyle); // rendering style
AddKeyFrameAppearance(ppKeyFrame, idxKeyFrame, 0.66,
kA3DPDFInterpolateAppearanceColor ,
dColInitR, dColInitG, dColInitB, // RGB
-1.0, // opacity
eRenderingStyle); // rendering style
AddKeyFrameAppearance(ppKeyFrame, idxKeyFrame, 0.83,
kA3DPDFInterpolateAppearanceColor,
dColBlinkR, dColBlinkG, dColBlinkB, // RGB
-1.0, // opacity
eRenderingStyle); // rendering style
AddKeyFrameAppearance(ppKeyFrame, idxKeyFrame, 1.00,
0, //kA3DPDFInterpolateAppearanceColor ,
dColInitR, dColInitG, dColInitB, // RGB
-1.0, // opacity
eRenderingStyle); // rendering style
// --- MOTION CREATION
sMotionData.m_bRepeat = false;
sMotionData.m_dTimeOffset = dTimeOffset;
sMotionData.m_iNumTargets = idxTargets;
sMotionData.m_ppTargets = ppTargets;
sMotionData.m_iNumKeyFrames = idxKeyFrame;
sMotionData.m_ppKeyFrames = ppKeyFrame;
A3DPDFAnimMotionCreate2(&sMotionData, &pMotion);
ppMotion[idxMotion++] = pMotion;
dTimeDuration = 1.0;
return A3D_SUCCESS;
}
A3DStatus CreateMotionMoveRotateAndHide(A3DPDFAnimMotion**& ppMotion, int& idxMotion,
A3DMiscMarkupLinkedItem** ppTargets, int idxTargets,
double dInitValueX, double dInitValueY, double dInitValueZ,
double dApplyTranslateX, double dApplyTranslateY, double dApplyTranslateZ,
double dColInitR, double dColInitG, double dColInitB,
bool bHide,
A3DPDFERenderingStyle eRenderingStyle,
double dTimeOffset,
double& dTimeDuration)
{
A3DPDFAnimMotion* pMotion;
A3DPDFAnimMotionData2 sMotionData;
A3D_INITIALIZE_DATA(A3DPDFAnimMotionData2, sMotionData);
// --- KEYFRAMES
const int INBKEYFRAMESALLOC = 20;
A3DPDFAnimKeyFrame **ppKeyFrame;
ppKeyFrame = (A3DPDFAnimKeyFrame**) malloc(INBKEYFRAMESALLOC * A3DUns32(sizeof(A3DPDFAnimKeyFrame*)));
int idxKeyFrame = 0;
// start with an identity transfo matrix ; it will be updated at each new frame
double adMat[16];
stLoadIdentityMatrix(adMat);
// init
AddKeyFrameTransfo(ppKeyFrame, idxKeyFrame, 0.0,
adMat, // position matrix
false,0,0,0,0, // no rotation
dInitValueX, dInitValueY, dInitValueZ, // defines the initial position for this movement
dColInitR, dColInitG, dColInitB, // RGB
1.0, // opacity
eRenderingStyle ); // rendering style
AddKeyFrameTransfo(ppKeyFrame, idxKeyFrame, 0.25,
adMat, // position matrix
true, 0.7071, 0, 0, 0.7071, // quaternion for the rotation
dApplyTranslateX/4.0, dApplyTranslateY/4.0, dApplyTranslateZ/4.0, // defines the initial position for this movement
dColInitR, dColInitG, dColInitB, // RGB
1.0, // opacity
eRenderingStyle); // rendering style
AddKeyFrameTransfo(ppKeyFrame, idxKeyFrame, 0.50,
adMat, // position matrix
true, 0.7071, 0, 0, 0.7071, // quaternion for the rotation
dApplyTranslateX*2/4.0, dApplyTranslateY*2/4.0, dApplyTranslateZ*2/4.0, // defines the initial position for this movement
dColInitR, dColInitG, dColInitB, // RGB
1.0, // opacity
eRenderingStyle); // rendering style
AddKeyFrameTransfo(ppKeyFrame, idxKeyFrame, 0.75,
adMat, // position matrix
true, 0.7071, 0, 0, 0.7071, // quaternion for the rotation
dApplyTranslateX*3/4.0, dApplyTranslateY*3/4.0, dApplyTranslateZ*3/4.0, // defines the initial position for this movement
dColInitR, dColInitG, dColInitB, // RGB
1.0, // opacity
eRenderingStyle); // rendering style
AddKeyFrameTransfo(ppKeyFrame, idxKeyFrame, 1.0,
adMat, // position matrix
true, 0.7071, 0, 0, 0.7071, // quaternion for the rotation
dApplyTranslateX*4/4.0, dApplyTranslateY*4/4.0, dApplyTranslateZ*4/4.0, // defines the initial position for this movement
dColInitR, dColInitG, dColInitB, // RGB
1.0, // opacity
eRenderingStyle, // rendering style
2); // no appearance mask
if(bHide)
{
// hide the objects init
AddKeyFrameAppearance(ppKeyFrame, idxKeyFrame, 1.5,
kA3DPDFInterpolateAppearanceTransparency,
-1, -1, -1, // RGB
1.0, // opacity
eRenderingStyle ); // rendering style
// hide the objects end
AddKeyFrameAppearance(ppKeyFrame, idxKeyFrame, 2.0,
kA3DPDFInterpolateAppearanceTransparency,
-1, -1, -1, // RGB
0.0, // opacity
eRenderingStyle); // rendering style
}
// --- MOTION CREATION
sMotionData.m_bRepeat = false;
sMotionData.m_dTimeOffset = dTimeOffset;
sMotionData.m_iNumTargets = idxTargets;
sMotionData.m_ppTargets = ppTargets;
sMotionData.m_iNumKeyFrames = idxKeyFrame;
sMotionData.m_ppKeyFrames = ppKeyFrame;
A3DPDFAnimMotionCreate2(&sMotionData, &pMotion);
ppMotion[idxMotion++] = pMotion;
dTimeDuration = 2.0;
return A3D_SUCCESS;
}
A3DStatus CreateMotionMoveAndHide(A3DPDFAnimMotion**& ppMotion, int& idxMotion,
A3DMiscMarkupLinkedItem** ppTargets, int idxTargets,
double dInitValueX, double dInitValueY, double dInitValueZ,
double dApplyTranslateX, double dApplyTranslateY, double dApplyTranslateZ,
double dColInitR, double dColInitG, double dColInitB,
bool bHide,
A3DPDFERenderingStyle eRenderingStyle,
double dTimeOffset,
double& dTimeDuration)
{
A3DPDFAnimMotion* pMotion;
A3DPDFAnimMotionData2 sMotionData;
A3D_INITIALIZE_DATA(A3DPDFAnimMotionData2, sMotionData);
// --- KEYFRAMES
const int INBKEYFRAMESALLOC = 20;
A3DPDFAnimKeyFrame **ppKeyFrame;
ppKeyFrame = (A3DPDFAnimKeyFrame**) malloc(INBKEYFRAMESALLOC * A3DUns32(sizeof(A3DPDFAnimKeyFrame*)));
int idxKeyFrame = 0;
// start with an identity transfo matrix ; it will be updated at each new frame
double adMat[16];
stLoadIdentityMatrix(adMat);
// init
AddKeyFrameTransfo(ppKeyFrame, idxKeyFrame, 0.0,
adMat, // position matrix
false, 0, 0, 0, 0, // no rotation
dInitValueX, dInitValueY, dInitValueZ, // defines the initial position for this movement
dColInitR, dColInitG, dColInitB, // RGB
1.0, // opacity
eRenderingStyle); // rendering style
// translated position
AddKeyFrameTransfo(ppKeyFrame, idxKeyFrame, 1.0,
adMat,
false, 0, 0, 0, 0, // no rotation
dApplyTranslateX, dApplyTranslateY, dApplyTranslateZ, // apply this translation
dColInitR, dColInitG, dColInitB, // RGB
1.0, // opacity
eRenderingStyle, // rendering style
2); // no appearance mask
if(bHide)
{
// hide the objects init
AddKeyFrameAppearance(ppKeyFrame, idxKeyFrame, 1.5,
kA3DPDFInterpolateAppearanceTransparency,
-1, -1, -1, // RGB
1.0, // opacity
eRenderingStyle ); // rendering style
// hide the objects end
AddKeyFrameAppearance(ppKeyFrame, idxKeyFrame, 2.0,
kA3DPDFInterpolateAppearanceTransparency,
-1, -1, -1, // RGB
0.0, // opacity
eRenderingStyle); // rendering style
}
// --- MOTION CREATION
sMotionData.m_bRepeat = false;
sMotionData.m_dTimeOffset = dTimeOffset;
sMotionData.m_iNumTargets = idxTargets;
sMotionData.m_ppTargets = ppTargets;
sMotionData.m_iNumKeyFrames = idxKeyFrame;
sMotionData.m_ppKeyFrames = ppKeyFrame;
A3DPDFAnimMotionCreate2(&sMotionData, &pMotion);
ppMotion[idxMotion++] = pMotion;
dTimeDuration = 2.0;
return A3D_SUCCESS;
}
A3DStatus CreateMotionMoveInitTransfo(A3DPDFAnimMotion**& ppMotion, int& idxMotion,
A3DMiscMarkupLinkedItem** ppTargets, int idxTargets,
double dInitTranslateX, double dInitTranslateY, double dInitTranslateZ,
double dTimeOffset,
double& dTimeDuration)
{
A3DPDFAnimMotion* pMotion;
A3DPDFAnimMotionData2 sMotionData;
A3D_INITIALIZE_DATA(A3DPDFAnimMotionData2, sMotionData);
// --- KEYFRAMES
const int INBKEYFRAMESALLOC = 20;
A3DPDFAnimKeyFrame **ppKeyFrame;
ppKeyFrame = (A3DPDFAnimKeyFrame**) malloc(INBKEYFRAMESALLOC * A3DUns32(sizeof(A3DPDFAnimKeyFrame*)));
int idxKeyFrame = 0;
// start with an identity transfo matrix ; it will be updated at each new frame
double adMat[16];
stLoadIdentityMatrix(adMat);
// init
AddKeyFrameTransfo(ppKeyFrame, idxKeyFrame, 0.0,
adMat, // position matrix
false, 0, 0, 0, 0, // no rotation
dInitTranslateX, dInitTranslateY, dInitTranslateZ,
-1, -1, -1,
1.0, // opacity
kA3DPDFRenderingSolid, // rendering style
2);// no mask
// translated position
AddKeyFrameTransfo(ppKeyFrame, idxKeyFrame, 0.1, // 0.1 to be sure that the event is considered. smaller value as 0.05 is sometimes not considered.
adMat,
false, 0, 0, 0, 0, // no rotation
dInitTranslateX, dInitTranslateY, dInitTranslateZ,
-1, -1, -1,
1.0, // opacity
kA3DPDFRenderingSolid, // rendering style
2);// no mask
// --- MOTION CREATION
sMotionData.m_bRepeat = false;
sMotionData.m_dTimeOffset = dTimeOffset;
sMotionData.m_iNumTargets = idxTargets;
sMotionData.m_ppTargets = ppTargets;
sMotionData.m_iNumKeyFrames = idxKeyFrame;
sMotionData.m_ppKeyFrames = ppKeyFrame;
A3DPDFAnimMotionCreate2(&sMotionData, &pMotion);
ppMotion[idxMotion++] = pMotion;
dTimeDuration = 0.1;
return A3D_SUCCESS;
}
void AddKeyFrameCamera(A3DPDFAnimKeyFrame**& ppKeyFrame, int& idxkeyframe,
A3DDouble dTime,
int /*iInterpolationMask*/,
double dPosX, double dPosY, double dPosZ,
double dTargetX, double dTargetY, double dTargetZ,
double dUpX, double dUpY, double dUpZ,
double dFov, A3DPDFEProjectionMode eMode, double dZoomFactor)
//A3DPDFERenderingStyle eRenderingStyle)
{
A3DPDFAnimKeyFrame* pKeyFrame;
A3DPDFAnimKeyFrameData sKeyFrameData;
A3D_INITIALIZE_DATA(A3DPDFAnimKeyFrameData, sKeyFrameData);
sKeyFrameData.m_dTime = dTime;
sKeyFrameData.m_iInterpolationMask = kA3DPDFInterpolateCamera;
A3DPDFAnimCameraData sCameraData;
A3D_INITIALIZE_DATA(A3DPDFAnimCameraData, sCameraData);
sCameraData.m_sPosition.m_dX = dPosX;
sCameraData.m_sPosition.m_dY = dPosY;
sCameraData.m_sPosition.m_dZ = dPosZ;
sCameraData.m_sTarget.m_dX = dTargetX;
sCameraData.m_sTarget.m_dY = dTargetY;
sCameraData.m_sTarget.m_dZ = dTargetZ;
sCameraData.m_sUpVector.m_dX = dUpX;
sCameraData.m_sUpVector.m_dY = dUpY;
sCameraData.m_sUpVector.m_dZ = dUpZ;
sCameraData.m_dFieldOfView = dFov;
sCameraData.m_eMode = eMode;
sCameraData.m_dZoomFactor = dZoomFactor;
sKeyFrameData.m_psCameraData = &sCameraData;
A3DPDFAnimKeyFrameCreate(&sKeyFrameData, &pKeyFrame);
ppKeyFrame[idxkeyframe++] = pKeyFrame;
}
A3DStatus CreateMotionCameraInit(A3DPDFAnimMotion**& ppMotion, int& idxMotion,
double dPosX0, double dPosY0, double dPosZ0,
double dTargetX0, double dTargetY0, double dTargetZ0,
double dUpX0, double dUpY0, double dUpZ0,
double dFov0, A3DPDFEProjectionMode eMode0, double dZoomFactor0,
double dPosX, double dPosY, double dPosZ,
double dTargetX, double dTargetY, double dTargetZ,
double dUpX, double dUpY, double dUpZ,
double dFov, A3DPDFEProjectionMode eMode, double dZoomFactor,
double dTimeOffset,
double& dTimeDuration)
{
A3DPDFAnimMotion* pMotion;
A3DPDFAnimMotionData2 sMotionData;
A3D_INITIALIZE_DATA(A3DPDFAnimMotionData2, sMotionData);
// --- KEYFRAMES
const int INBKEYFRAMESALLOC = 10;
A3DPDFAnimKeyFrame** ppKeyFrame;
ppKeyFrame = (A3DPDFAnimKeyFrame**) malloc(INBKEYFRAMESALLOC * A3DUns32(sizeof(A3DPDFAnimKeyFrame*)));
int idxKeyFrame=0;
AddKeyFrameCamera(ppKeyFrame, idxKeyFrame, 0.0,
0, //kA3DPDFInterpolateAppearanceColor,
dPosX0, dPosY0, dPosZ0,
dTargetX0, dTargetY0, dTargetZ0,
dUpX0, dUpY0, dUpZ0,
dFov0, eMode0, dZoomFactor0);
AddKeyFrameCamera(ppKeyFrame, idxKeyFrame, 1.0, // set 1 second but it could be any time before the end (just the previous keyframe counts)
0, //kA3DPDFInterpolateAppearanceColor,
dPosX, dPosY, dPosZ,
dTargetX, dTargetY, dTargetZ,
dUpX, dUpY, dUpZ,
dFov, eMode, dZoomFactor);
// --- MOTION CREATION
sMotionData.m_bRepeat = false;
sMotionData.m_dTimeOffset = dTimeOffset;
sMotionData.m_iNumTargets = 0;
sMotionData.m_ppTargets = NULL;
sMotionData.m_iNumKeyFrames = idxKeyFrame;
sMotionData.m_ppKeyFrames = ppKeyFrame;
A3DPDFAnimMotionCreate2(&sMotionData, &pMotion);
ppMotion[idxMotion++] = pMotion;
dTimeDuration = 1.0;
return A3D_SUCCESS;
}