Animation.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:7k
源码类别:
OpenGL
开发平台:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // Animation.cpp : implementation file
- //
- // glOOP (OpenGL Object Oriented Programming library)
- // Copyright (c) Craig Fahrnbach 1997, 1998
- //
- // OpenGL is a registered trademark of Silicon Graphics
- //
- //
- // This program is provided for educational and personal use only and
- // is provided without guarantee or warrantee expressed or implied.
- //
- // Commercial use is strickly prohibited without written permission
- // from ImageWare Development.
- //
- // This program is -not- in the public domain.
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "glOOP.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAnimation
- IMPLEMENT_DYNAMIC(CAnimation, CObject)
- /////////////////////////////////////////////////////////////////////////////
- // CAnimation construction
- CAnimation::CAnimation()
- {
- // Set the attributes to default values..
- m_dTimePrevious = 0.0;
- m_Color.SetColor4f(0.0f, 0.0f, 0.0f, 1.0f);
- Vec4f(0.0f, 0.0f, 0.0f, 1.0f, m_fOrigin);
- Vec3f(0.0f, 0.0f, 0.0f, m_fRotation);
- Vec3f(0.0f, 0.0f, 0.0f, m_fScale);
- Vec3f(0.0f, 0.0f, 0.0f, m_fTranslate);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CAnimation Destructor
- CAnimation::~CAnimation()
- {
- }
- /////////////////////////////////////////////////////////////////////////////
- // CAnimation Methods or virtual function implimentation
- void CAnimation::AddAnimationPage(LPVOID pSht, C3dObject* pObject, C3dCamera* pCamera, C3dWorld* pWorld)
- {
- // Virtual prototype function only! Add specific
- // functionality to your derived object class!
- }
- void CAnimation::AnimateCamera(C3dCamera* pCamera, double dTime)
- {
- // Virtual prototype function only! Add specific
- // functionality to your derived object class!
- }
- void CAnimation::AnimateObject(C3dObject* pObject, double dTime)
- {
- // Virtual prototype function only! Add specific
- // functionality to your derived object class!
- }
- void CAnimation::AnimateWorld(C3dWorld* pWorld, double dTime)
- {
- // Virtual prototype function only! Add specific
- // functionality to your derived object class!
- }
- void CAnimation::Serialize(CArchive& ar, int iVersion)
- {
- CString szBuffer;
- CString szName;
- szBuffer.GetBuffer(256);
- szName.GetBuffer(128);
- if (ar.IsStoring())
- {
- // Save the Base Class CAnimation data...
- szBuffer.Format("%stName < %s >n", szIndent, m_szName);
- ar.WriteString(szBuffer);
- }
- else
- {
- // Read the Base Class CAnimation data...
- // Get the Name of this animation procedure. Note that the
- // name may contain spaces, so we extract the
- // string between the < > characters..
- ar.ReadString(szBuffer);
- // locate the position of the brackets
- int begin = szBuffer.Find("<");
- int end = szBuffer.Find(">");
- if(end > begin)
- {
- // extract the objectname from within the barckets
- m_szName = szBuffer.Mid(begin+1, (end-begin)-1);
- m_szName.TrimLeft(); // trim leading spaces
- m_szName.TrimRight(); // trim tailing spaces
- }
- // Must remove the derived class defined end marker!
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft();
- sscanf(szBuffer, "}n");
- }
- }
- void CAnimation::Reset()
- {
- // Virtual prototype function only! Add specific
- // functionality to your derived object class!
- }
- /////////////////////////////////////////////////////////////////////////////
- // CAnimation function implimentation
- CAnimation* CAnimation::IsAnimationClass(CString* szString)
- {
- // Is this class derived from CAnimation?
- //
- if(szString->Compare("CAnimKeyFrame {") == 0) {
- CAnimKeyFrame* pAnimation = new CAnimKeyFrame;
- ASSERT(pAnimation);
- return pAnimation;
- }
- if(szString->Compare("CAnimSpin {") == 0) {
- CAnimSpin* pAnimation = new CAnimSpin;
- ASSERT(pAnimation);
- return pAnimation;
- }
- if(szString->Compare("CAnimWobble {") == 0) {
- CAnimWobble* pAnimation = new CAnimWobble;
- ASSERT(pAnimation);
- return pAnimation;
- }
- if(szString->Compare("CAnimAVI {") == 0) {
- CAnimAVI* pAnimation = new CAnimAVI;
- ASSERT(pAnimation);
- return pAnimation;
- }
- // Class not of type CAnimation
- return NULL;
- }
- void CAnimation::SaveCameraAttributes(C3dCamera* pCamera)
- {
- if(!pCamera)
- return;
- // Save our camera attributes
- VecCopy4f(pCamera->m_fOrigin, m_fOrigin);
- VecCopy3f(pCamera->m_fRotation, m_fRotation);
- }
- void CAnimation::SaveObjectAttributes(C3dObject* pObject)
- {
- if(!pObject)
- return;
- // Save our object attributes
- m_Color.SetColor4fv(&pObject->m_Color);
- VecCopy4f(pObject->m_fOrigin, m_fOrigin);
- VecCopy3f(pObject->m_fRotation, m_fRotation);
- VecCopy3f(pObject->m_fScale, m_fScale);
- VecCopy3f(pObject->m_fTranslate, m_fTranslate);
- if(pObject->m_iType == LIGHT_OBJECT)
- {
- C3dObjectLight* pLight = (C3dObjectLight*)pObject;
- m_ColorAmb.SetColor4fv(&pLight->m_ColorAmbient);
- m_ColorDif.SetColor4fv(&pLight->m_ColorDiffuse);
- m_ColorSpc.SetColor4fv(&pLight->m_ColorSpecular);
- pLight->m_fSpotAngle = m_fSpotAngle;
- }
- }
- void CAnimation::RestoreCameraAttributes(C3dCamera* pCamera)
- {
- // Ensure that we have a vaild pointer..
- if(!pCamera)
- return;
- // Reset our common variables
- ResetCommon();
- // Restore our camera attributes
- VecCopy4f(m_fOrigin, pCamera->m_fOrigin);
- VecCopy3f(m_fRotation, pCamera->m_fRotation);
- }
- void CAnimation::RestoreObjectAttributes(C3dObject* pObject)
- {
- // Ensure that we have a vaild pointer..
- if(!pObject)
- return;
- // Reset our common variables
- ResetCommon();
- // Restore our object attributes
- pObject->m_Color.SetColor4fv(&m_Color);
- VecCopy4f(m_fOrigin, pObject->m_fOrigin);
- VecCopy3f(m_fRotation, pObject->m_fRotation);
- VecCopy3f(m_fScale, pObject->m_fScale);
- VecCopy3f(m_fTranslate, pObject->m_fTranslate);
- if(pObject->m_iType == LIGHT_OBJECT)
- {
- C3dObjectLight* pLight = (C3dObjectLight*)pObject;
- pLight->m_ColorAmbient.SetColor4fv(&m_ColorAmb);
- pLight->m_ColorDiffuse.SetColor4fv(&m_ColorDif);
- pLight->m_ColorSpecular.SetColor4fv(&m_ColorSpc);
- pLight->m_fSpotAngle = m_fSpotAngle;
- }
- }
- void CAnimation::ResetCommon()
- {
- // Reset the first pass flag so that we will save the
- // initial parameters.
- m_bFirst = TRUE;
- // Reset the time reference of our last iteration
- m_dTimePrevious = 0.0;
- // Call the derived CAnimation Reset procedure..
- Reset();
- }