📄 3dplus.h
字号:
class C3dViewport;
class C3dShape : public C3dFrame
{
public:
DECLARE_DYNAMIC(C3dShape);
C3dShape();
virtual ~C3dShape();
void New();
BOOL Create(D3DVECTOR* pVectors, int iVectors,
D3DVECTOR* pNormals, int iNormals,
int* pFaceData, BOOL bAutoGen = FALSE);
BOOL Create(D3DVECTOR* pVectors, int iVectors, int* pFaceData, BOOL bAutoGen = FALSE)
{return Create(pVectors, iVectors, NULL, 0, pFaceData, bAutoGen);}
BOOL AddFaces(D3DVECTOR* pVectors, int iVectors,
D3DVECTOR* pNormals, int iNormals,
int* pFaceData);
BOOL CreateCuboid(double x, double y, double z);
BOOL CreateCube(double side)
{return CreateCuboid(side, side, side);}
const char* Load(const char* pszFileName);
const char* Load() {return Load("");}
BOOL Load(UINT uiResid);
BOOL Save(const char* pszFileName = NULL);
int GetFaceCount();
BOOL SetFaceColor(int iFace, double r, double g, double b);
BOOL SetColor(double r, double g, double b);
BOOL SetFrameColor(double r, double g, double b);
BOOL CreateSphere(double r, int nBands = 16);
BOOL CreateSurface(double x1, double x2, double dx,
double z1, double z2, double dz,
SURFHTFN pfnHeight, void* pArg);
BOOL CreateRSolid(double z1, double z2, double dz,
BOOL bClosed1, BOOL bClosed2,
SOLIDRFN pfnRad, void* pArg,
int nFacets = 8);
BOOL CreateCone(double x1, double y1, double z1,
double r1, BOOL bClosed1,
double x2, double y2, double z2,
double r2, BOOL bClosed2,
int nFacets = 8);
BOOL CreateRod(double x1, double y1, double z1,
double x2, double y2, double z2,
double r, int nFacets = 8)
{return CreateCone(x1, y1, z1, r, TRUE, x2, y2, z2, r, TRUE, nFacets);}
IDirect3DRMVisual* GetVisual() {return m_pIVisual;}
void AttachVisual(IDirect3DRMVisual* pIVisual);
BOOL GetBox(double& x1, double& y1, double& z1,
double& x2, double& y2, double& z2);
BOOL SetMaterial(C3dMaterial* pMaterial);
BOOL SetTexture(C3dTexture* pTexture);
BOOL SetFaceTexture(int iFirst, int iCount, C3dTexture* pTexture);
BOOL SetFaceTexture(int iFace, C3dTexture* pTexture)
{return SetFaceTexture(iFace, 1, pTexture);}
IDirect3DRMMeshBuilder* GetMeshBuilder() {return m_pIMeshBld;}
C3dVector GetFaceNormal(int iFace);
C3dShape* Clone();
#if 0
void Add(C3dShape* pShape);
#endif
BOOL C3dShape::HitTest(CPoint pt,
C3dViewport* pViewport,
int* piFace = NULL,
D3DVECTOR* pvHit = NULL);
BOOL CreateShadow(C3dLight* pLight,
D3DVECTOR& vPt,
D3DVECTOR& vNormal);
C3dImageList m_ImgList; // list of associated images and tex maps
protected:
virtual IDirect3DRMVisual* _GetVisualInterface()
{return m_pIVisual;}
IDirect3DRMVisual* m_pIVisual;
IDirect3DRMMeshBuilder* m_pIMeshBld;
};
class C3dShapeList : protected CObList
{
public:
C3dShapeList();
virtual ~C3dShapeList();
void Append(C3dShape* pShape) {CObList::AddTail(pShape);}
void Remove(C3dShape* pShape);
void Delete(C3dShape* pShape);
void DeleteAll();
#if 0 // not used
C3dShape* Find(C3dShape* pShape);
#endif
C3dShape* GetNext(POSITION& rPosition)
{return (C3dShape*) CObList::GetNext(rPosition);}
};
////////////////////////////////////////////////////////////////////
// C3dAnimKey, C3dAnimation
class C3dAnimKey : public C3dObject
{
public:
C3dAnimKey(double time,
const D3DVECTOR& pos,
const D3DVECTOR& dir,
const D3DVECTOR& up)
: m_vPos(pos), m_vDir(dir), m_vUp(up), m_dTime(time)
{
}
public:
C3dVector m_vPos;
C3dVector m_vDir;
C3dVector m_vUp;
double m_dTime;
};
class C3dAnimation : private CObList
{
public:
C3dAnimation();
virtual ~C3dAnimation();
void Attach(C3dFrame* pFrame);
BOOL AddKey(C3dAnimKey* pKey);
BOOL AddKey(double time);
BOOL SetTime(double time);
double GetLength();
void DeleteAll();
int GetNumKeys() {return GetCount();}
double GetCurTime() {return m_dCurTime;}
protected:
C3dFrame* m_pFrame;
double m_dCurTime;
};
///////////////////////////////////////////////////////////////////
// C3dDevice
class C3dDevice : public C3dObject
{
public:
DECLARE_DYNAMIC(C3dDevice);
C3dDevice();
virtual ~C3dDevice();
BOOL Create(CDirect3D* pD3D);
int GetWidth();
int GetHeight();
void Update();
IDirect3DRMDevice* GetInterface() {return m_pIDevice;}
void SetQuality(D3DRMRENDERQUALITY quality);
protected:
IDirect3DRMDevice* m_pIDevice;
};
///////////////////////////////////////////////////////////////////
// C3dViewport
class C3dViewport : public C3dObject
{
public:
DECLARE_DYNAMIC(C3dViewport);
C3dViewport();
virtual ~C3dViewport();
void Clear();
BOOL Create(C3dDevice* pDevice,
C3dCamera* pCamera,
int x, int y,
int cx, int cy);
void ForceUpdate(RECT* pRect);
BOOL Render(C3dFrame* pFrame);
IDirect3DRMViewport* GetInterface() {return m_pIViewport;}
C3dShape* HitTest(CPoint pt);
BOOL SetFieldOfView(double f);
protected:
IDirect3DRMViewport* m_pIViewport;
};
///////////////////////////////////////////////////////////////////
// C3dStage
class C3dScene;
class C3dStage : public C3dFrame
{
public:
DECLARE_DYNAMIC(C3dStage);
C3dStage();
virtual ~C3dStage();
BOOL Create(CDirect3D* pD3D);
void Clear()
{m_Viewport.Clear();}
void ForceUpdate(RECT* pRect)
{m_Viewport.ForceUpdate(pRect);}
void Render();
void SetScene(C3dScene* pScene);
void SetBackground(C3dScene* pScene);
void SetQuality(D3DRMRENDERQUALITY quality);
C3dCamera* GetCamera() {return &m_Camera;}
C3dViewport* GetViewport() {return &m_Viewport;}
protected:
C3dDevice m_Device; // the device we render to
C3dViewport m_Viewport; // the viewport (TODO: multiple vps)
C3dCamera m_Camera; // the camera
C3dScene* m_pScene; // current scene
D3DRMRENDERQUALITY m_Quality;
};
///////////////////////////////////////////////////////////////////
// C3dTexture
class C3dTexture : public C3dImage
{
public:
DECLARE_DYNAMIC(C3dTexture);
C3dTexture();
virtual ~C3dTexture();
BOOL Create();
BOOL Load(CFile* fp);
BOOL Load(const char* pszFilename);
BOOL LoadResource(const char* pszResname);
BOOL Load(UINT uiResid);
IDirect3DRMTexture* GetInterface() {return m_pITexture;}
BOOL SetTransparency(double r, double g, double b);
BOOL SetColors(int iColors);
BOOL SetShades(int iShades);
protected:
virtual IDirect3DRMVisual* _GetVisualInterface()
{return m_pITexture;}
virtual void _OnImageChanged();
IDirect3DRMTexture* m_pITexture;
};
///////////////////////////////////////////////////////////////////
// C3dWrap
class C3dWrap : public C3dObject
{
public:
DECLARE_DYNAMIC(C3dWrap);
C3dWrap();
virtual ~C3dWrap();
IDirect3DRMWrap* GetInterface() {return m_pIWrap;}
BOOL Create(D3DRMWRAPTYPE type,
C3dFrame* pRefFrame,
double ox, double oy, double oz,
double dx, double dy, double dz,
double ux, double uy, double uz,
double ou, double ov,
double su, double sv);
BOOL Apply(C3dShape* pShape);
BOOL ApplyRelative(C3dFrame* pFrame, C3dShape* pShape);
BOOL Apply(C3dShape* pShape, int iFace);
protected:
IDirect3DRMWrap* m_pIWrap;
};
///////////////////////////////////////////////////////////////////
// C3dChromeWrap
class C3dChromeWrap : public C3dWrap
{
public:
DECLARE_DYNAMIC(C3dChromeWrap);
C3dChromeWrap();
virtual ~C3dChromeWrap();
BOOL Create(C3dShape* pShape, C3dCamera* pCamera);
C3dShape* m_pShape;
};
///////////////////////////////////////////////////////////////////
// C3dSprite
class C3dSprite : public C3dFrame
{
public:
DECLARE_DYNAMIC(C3dSprite);
C3dSprite();
virtual ~C3dSprite();
BOOL Create(C3dScene* pScene,
double x, double y, double z,
double scale,
UINT uiIDBitmap,
int iPhases = 1);
BOOL SetPhase(int iPhase);
int GetNumPhases() {return m_Tex.GetNumPhases();}
int GetPhase() {return m_Tex.GetPhase();}
protected:
C3dTexture m_Tex;
};
///////////////////////////////////////////////////////////////////
// C3dScene
class C3dScene : public C3dFrame
{
public:
DECLARE_DYNAMIC(C3dScene);
C3dScene();
virtual ~C3dScene();
BOOL Create();
void SetAmbientLight(double r, double g, double b)
{m_AmbLight.SetColor(r, g, b);}
BOOL AddLight(C3dLight* pLight);
void Move(double delta);
void SetBackground(double r, double g, double b);
void SetBackground(C3dImage* pImage);
void SetCameraPosition(D3DVECTOR& p);
void SetCameraDirection(D3DVECTOR& d);
void SetCameraDirection(D3DVECTOR& d, D3DVECTOR& u);
void SetCameraField(double f);
C3dAmbLight* GetAmbLight() {return &m_AmbLight;}
public:
C3dFrameList m_ShapeList; // list of shapes
C3dImageList m_ImgList; // list of associated images
D3DCOLOR m_clrBkgnd; // background color
C3dImage* m_pBkgndImg; // background image
C3dStage* m_pStage; // stage to which we are attached
C3dVector m_vCamPos; // camera position
C3dVector m_vCamDir; // camera direction
C3dVector m_vCamUp; // camera up vector
double m_dCamField; // camera field of view
protected:
C3dAmbLight m_AmbLight; // the ambient light
};
/////////////////////////////////////////////////////////////////////////////
// C3dWnd window
// Callback function used to notify selection changes
typedef void (CALLBACK * SELCHANGEFN)(C3dShape* pShape, CPoint pt, void *pArg);
class C3dController;
class C3dWnd : public CWnd
{
// Construction
public:
C3dWnd();
BOOL Create(const char* pszCaption,
DWORD dwStyle,
int x, int y,
int cx, int cy,
CWnd* pParent = NULL);
BOOL Create(CWnd* pParent, UINT uiID, D3DCOLORMODEL cm = D3DCOLOR_MONO);
// Attributes
public:
// Operations
public:
BOOL Update(double delta);
BOOL SetScene(C3dScene* pScene);
BOOL AttachController(C3dController* pController);
C3dCamera* GetCamera()
{return m_pStage->GetCamera();}
C3dShape* HitTest(CPoint pt);
void EnableMouseSelection(SELCHANGEFN pNotifyFn,
void* pArg,
BOOL bEnable = TRUE);
C3dStage* GetStage() {return m_pStage;}
CDirectDraw* GetDD() {return m_pDD;}
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(C3dWnd)
protected:
virtual void PostNcDestroy( );
virtual BOOL OnWndMsg( UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult );
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~C3dWnd();
// Generated message map functions
protected:
//{{AFX_MSG(C3dWnd)
afx_msg void OnActivateApp(BOOL bActive, HTASK hTask);
//afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
afx_msg void OnPaletteChanged(CWnd* pFocusWnd);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnDestroy();
afx_msg void OnMove(int x, int y);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnPaint();
afx_msg BOOL OnEraseBkgnd( CDC* pDC );
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
protected:
CDirectDraw* m_pDD;
CDirect3D* m_pD3D;
BOOL m_bAutoDelete;
C3dStage* m_pStage;
C3dScene* m_pScene;
BOOL m_bEnableUpdates;
int m_iWidth; // client width
int m_iHeight; // client height
CRect m_rcClient; // client area in screen coords
BOOL m_bRepaintAll; // window size changed etc.
BOOL m_bAppActive;
CBitmap* m_pGrabImg; // snapshot of the image
CPalette* m_pGrabPal;
C3dController* m_pController;
BOOL m_bEnableMouseSelection;
SELCHANGEFN m_pSelChangeFn;
void* m_pSelChangeArg;
D3DCOLORMODEL m_ColorModel;
BOOL CreateStage();
void ReleaseStage();
void ReleaseDD();
};
// include the input device classes
#include "3dInpDev.h"
// include the dialog,property page and property sheet classes
#include "3dDlg.h"
// from 3dMath.cpp
extern BOOL _3dPointInPolygon(POINT* Points, int nPoints, CPoint pt);
#endif // _3DPLUS_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -