- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
CPhysic.h
资源名称:brm2.rar [点击查看]
上传用户:liujun12jf
上传日期:2022-07-12
资源大小:638k
文件大小:2k
源码类别:
OpenGL
开发平台:
Visual C++
- #ifndef _CPHYSIC_H_
- #define _CPHYSIC_H_
- #include <Newton.h>
- #include "object_physics.h"
- class CPhysicObject;
- // callback for applying powers to body
- void ForceAndTorqueCallback(const NewtonBody* body);
- // callback for transforming matrix of graphic object
- void TransformCallback(const NewtonBody* body, const dFloat* matrix);
- // if object actives/deactives, this is called
- void AutoactiveCallback(const NewtonBody *b, unsigned state);
- int GCBegin(const NewtonMaterial* material, const NewtonBody* body0, const NewtonBody* body1);
- int GCProcess(const NewtonMaterial* material, const NewtonContact* contact);
- void GCEnd(const NewtonMaterial* material);
- // this is because normally unfreezing needs newton world pointer, and this does not
- void NewtonBodyUnfreeze(NewtonBody *b);
- void NewtonBodyDestroy(NewtonBody *b);
- class CPhysic
- {
- public:
- NewtonWorld *nWorld;
- float timeStep;
- float fSpeed;
- float fSlowSpeed;
- float fNormalSpeed;
- bool bSlowMode;
- CPhysic()
- {
- fSlowSpeed = 0.1f;
- fNormalSpeed = 1;
- fSpeed = fNormalSpeed;
- bSlowMode = false;
- }
- void SwitchSlowMode()
- {
- bSlowMode = !bSlowMode;
- SetSpeed();
- }
- void SetSpeed(float spd=-1)
- {
- if (spd == -1)
- {
- if (bSlowMode) fSpeed = fSlowSpeed;
- else fSpeed = fNormalSpeed;
- }
- else fSpeed = spd;
- }
- int GetActive() // LOOOOL, tato funkcia rulez =D
- {
- int active;
- AutoactiveCallback((NewtonBody*)&active, -1);
- return active;
- }
- void Init()
- {
- // create newton world
- nWorld = NewtonCreate(NULL, NULL);
- CVector mn(-1, -1, -1); CVector mx(1, 1, 1);
- mn *= 100;
- mx *= 100;
- NewtonSetWorldSize(nWorld, &mn[0], &mx[0]);
- int defaultID = NewtonMaterialGetDefaultGroupID(nWorld);
- NewtonMaterialSetCollisionCallback(nWorld, defaultID, defaultID, 0, GCBegin, GCProcess, GCEnd);
- }
- void AddObject(CPhysicObject *o);
- void Frame(float frameTime);
- };
- #endif