Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
AnimSpin.cpp
Package: gloop.zip [view]
Upload User: shxiangxiu
Upload Date: 2007-01-03
Package Size: 1101k
Code Size: 7k
Category:
OpenGL program
Development Platform:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // AnimSpin.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"
- #include "AnimationDialog.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAnimSpin
- IMPLEMENT_DYNAMIC(CAnimSpin, CAnimation)
- /////////////////////////////////////////////////////////////////////////////
- // CAnimSpin construction
- CAnimSpin::CAnimSpin()
- {
- // Set the attributes to default values..
- m_szName = SZ_ANIMATE_SPIN;
- m_bFirst = TRUE;
- m_fSpinX = 2.0f;
- m_fSpinY = 2.0f;
- m_fSpinZ = 2.0f;
- m_dSpeedX = 0.0f;
- m_dSpeedY = 0.0f;
- m_dSpeedZ = 0.0f;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CAnimSpin Destructor
- CAnimSpin::~CAnimSpin()
- {
- }
- /////////////////////////////////////////////////////////////////////////////
- // CAnimSpin Methods or virtual function implimentation
- void CAnimSpin::AddAnimationPage(LPVOID pSht, C3dObject* pObject, C3dCamera* pCamera, C3dWorld* pWorld)
- {
- CAnimPropSheet* pSheet = (CAnimPropSheet*)pSht;
- ASSERT(pSheet);
- // Add the page to the property sheet
- pSheet->AddPage(&pSheet->m_SpinPage);
- // Save the address of this animation procedure in the page
- pSheet->m_SpinPage.m_pAnimation = this;
- }
- void CAnimSpin::AnimateCamera(C3dCamera* pCamera, double dTime)
- {
- GLfloat fXIncrement; // Rotation incremental values
- GLfloat fYIncrement;
- GLfloat fZIncrement;
- // Ensure that we have a vaild pointer..
- if(!pCamera)
- return;
- // First pass through, just save the objects original
- // parameters
- if(m_bFirst)
- {
- m_bFirst = FALSE;
- SaveCameraAttributes(pCamera);
- return;
- }
- // Calculate the incremental index values
- if(m_dSpeedX)
- fXIncrement = (GLfloat)(m_fSpinX/(m_dSpeedX/(dTime-m_dTimePrevious)));
- else
- fXIncrement = m_fSpinX; // incrememt as fast as possible..
- if(m_dSpeedY)
- fYIncrement = (GLfloat)(m_fSpinY/(m_dSpeedY/(dTime-m_dTimePrevious)));
- else
- fYIncrement = m_fSpinY; // incrememt as fast as possible..
- if(m_dSpeedZ)
- fZIncrement = (GLfloat)(m_fSpinZ/(m_dSpeedZ/(dTime-m_dTimePrevious)));
- else
- fZIncrement = m_fSpinZ; // incrememt as fast as possible..
- // Rotate or spin the camera
- pCamera->m_fRotation[X] += fXIncrement;
- if(pCamera->m_fRotation[X] > 360)
- pCamera->m_fRotation[X] -= 360;
- pCamera->m_fRotation[Y] += fYIncrement;
- if(pCamera->m_fRotation[Y] > 360)
- pCamera->m_fRotation[Y] -= 360;
- pCamera->m_fRotation[Z] += fZIncrement;
- if(pCamera->m_fRotation[Z] > 360)
- pCamera->m_fRotation[Z] -= 360;
- // Save the time of the last iteration
- m_dTimePrevious = dTime;
- }
- void CAnimSpin::AnimateObject(C3dObject* pObject, double dTime)
- {
- GLfloat fXIncrement; // Rotation incremental values
- GLfloat fYIncrement;
- GLfloat fZIncrement;
- // Ensure that we have a vaild pointer..
- if(!pObject)
- return;
- // First pass through, just save the objects original
- // parameters
- if(m_bFirst)
- {
- m_bFirst = FALSE;
- SaveObjectAttributes(pObject);
- return;
- }
- // Calculate the incremental index values
- if(m_dSpeedX)
- fXIncrement = (GLfloat)(m_fSpinX/(m_dSpeedX/(dTime-m_dTimePrevious)));
- else
- fXIncrement = m_fSpinX; // incrememt as fast as possible..
- if(m_dSpeedY)
- fYIncrement = (GLfloat)(m_fSpinY/(m_dSpeedY/(dTime-m_dTimePrevious)));
- else
- fYIncrement = m_fSpinY; // incrememt as fast as possible..
- if(m_dSpeedZ)
- fZIncrement = (GLfloat)(m_fSpinZ/(m_dSpeedZ/(dTime-m_dTimePrevious)));
- else
- fZIncrement = m_fSpinZ; // incrememt as fast as possible..
- // Rotate or spin the shape
- if(m_fSpinX)
- {
- pObject->m_fRotation[X] += fXIncrement;
- if(pObject->m_fRotation[X] > 360)
- pObject->m_fRotation[X] -= 360;
- if(pObject->m_fRotation[X] < 0)
- pObject->m_fRotation[X] += 360;
- }
- if(m_fSpinY)
- {
- pObject->m_fRotation[Y] += fYIncrement;
- if(pObject->m_fRotation[Y] > 360)
- pObject->m_fRotation[Y] -= 360;
- if(pObject->m_fRotation[Y] < 0)
- pObject->m_fRotation[Y] += 360;
- }
- if(m_fSpinZ)
- {
- pObject->m_fRotation[Z] += fZIncrement;
- if(pObject->m_fRotation[Z] > 360)
- pObject->m_fRotation[Z] -= 360;
- if(pObject->m_fRotation[Z] < 0)
- pObject->m_fRotation[Z] += 360;
- }
- // Save the time of the last iteration
- m_dTimePrevious = dTime;
- }
- void CAnimSpin::Serialize(CArchive& ar, int iVersion)
- {
- CString szBuffer;
- CString szName;
- szBuffer.GetBuffer(256);
- szName.GetBuffer(128);
- if (ar.IsStoring())
- {
- // Save the CAnimation derived class header...
- szBuffer.Format("%sCAnimSpin {n", szIndent);
- ar.WriteString(szBuffer);
- // Save the this animation procedures' specific data...
- szBuffer.Format("%stSpinX < %f >n", szIndent, m_fSpinX);
- ar.WriteString(szBuffer);
- szBuffer.Format("%stSpinY < %f >n", szIndent, m_fSpinY);
- ar.WriteString(szBuffer);
- szBuffer.Format("%stSpinZ < %f >n", szIndent, m_fSpinZ);
- ar.WriteString(szBuffer);
- szBuffer.Format("%stSpinSpeedX < %f >n", szIndent, m_dSpeedX);
- ar.WriteString(szBuffer);
- szBuffer.Format("%stSpinSpeedY < %f >n", szIndent, m_dSpeedY);
- ar.WriteString(szBuffer);
- szBuffer.Format("%stSpinSpeedZ < %f >n", szIndent, m_dSpeedZ);
- ar.WriteString(szBuffer);
- // Save the base class data...
- CAnimation::Serialize(ar, iVersion);
- szBuffer.Format("%s}n", szIndent); // end of animation def
- ar.WriteString(szBuffer);
- }
- else
- {
- // Read the derived class data..
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft(); // Remove leading white spaces
- sscanf(szBuffer, "SpinX < %f >n", &m_fSpinX);
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft();
- sscanf(szBuffer, "SpinY < %f >n", &m_fSpinY);
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft();
- sscanf(szBuffer, "SpinZ < %f >n", &m_fSpinZ);
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft();
- sscanf(szBuffer, "SpinSpeedX < %lf >n", (float*)&m_dSpeedX);
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft();
- sscanf(szBuffer, "SpinSpeedY < %lf >n", (float*)&m_dSpeedY);
- ar.ReadString(szBuffer);
- szBuffer.TrimLeft();
- sscanf(szBuffer, "SpinSpeedZ < %lf >n", (float*)&m_dSpeedZ);
- // Read the base class data...
- CAnimation::Serialize(ar, iVersion);
- }
- }
- void CAnimSpin::Reset()
- {
- // TODO: Add any CAnimSpin reset code here..
- }
- /////////////////////////////////////////////////////////////////////////////
- // CAnimSpin function implimentation