File: ImplicitClothExample.cpp

package info (click to toggle)
bullet 2.83.7%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 48,772 kB
  • sloc: cpp: 355,312; lisp: 12,087; ansic: 11,969; python: 644; makefile: 116; xml: 27
file content (129 lines) | stat: -rw-r--r-- 3,097 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "ImplicitClothExample.h"


#include "../CommonInterfaces/CommonExampleInterface.h"
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
#include "../CommonInterfaces/CommonRenderInterface.h"
#include "../CommonInterfaces/CommonCameraInterface.h"
#include "../CommonInterfaces/CommonGraphicsAppInterface.h"
#include "../CommonInterfaces/CommonWindowInterface.h"
#include "stan/vecmath.h"
#include "stan/Cloth.h"
#include "Bullet3Common/b3Vector3.h"
#include "Bullet3Common/b3AlignedObjectArray.h"


#ifdef _DEBUG
int numX = 20, numY=20;
#else
int numX = 60, numY=60;
#endif
const size_t total_points = (numX)*(numY);


struct ImplicitClothExample  : public CommonExampleInterface
{
	struct GUIHelperInterface* m_guiHelper;
	int m_option;

	Cloth* m_cloth;
	
	
	
	
public:
	ImplicitClothExample(struct GUIHelperInterface* helper, int option)
	:m_guiHelper(helper),
	m_option(option),
	m_cloth(0)
	{
	}
	virtual void    initPhysics();
	virtual void    exitPhysics();
	virtual void	stepSimulation(float deltaTime);
	virtual void	renderScene();
	virtual void	physicsDebugDraw(int debugFlags);//for now we reuse the flags in Bullet/src/LinearMath/btIDebugDraw.h
	virtual bool	mouseMoveCallback(float x,float y)
	{
		return false;
	}
	virtual bool	mouseButtonCallback(int button, int state, float x, float y)
	{
		return false;
	}
	virtual bool	keyboardCallback(int key, int state)
	{
		return false;
	}

	virtual void resetCamera()
	{
		float dist = 10;
		float pitch = 62;
		float yaw = 33;
		float targetPos[3]={-3,2.4,-3.6};
		m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]);
	}

	
};


void    ImplicitClothExample::initPhysics()
{
	float size=10;
	m_guiHelper->setUpAxis(1);
	m_cloth = ClothCreate(numX,numY,size);
	
}
void    ImplicitClothExample::exitPhysics()
{
	delete m_cloth;
	m_cloth=0;
}
void	ImplicitClothExample::stepSimulation(float deltaTime)
{
	m_cloth->Simulate(deltaTime);
	m_cloth->cloth_gravity.y = -9.8;//-9.8;//-9.8;//-9.8;//0;//-9.8;//0;//-9.8;//0;//-9.8;
	m_cloth->cloth_gravity.z =-9.8;//0;//-9.8;//0;//-9.8;
	
	m_cloth->spring_struct=10000000.0f;
	m_cloth->spring_shear=10000000.0f;
	
	//m_cloth->spring_struct=1000000.0f;
	//m_cloth->spring_shear=1000000.0f;
	
	m_cloth->spring_damp = 0;//100;

	
}
void	ImplicitClothExample::renderScene()
{
}
void	ImplicitClothExample::physicsDebugDraw(int debugFlags)
{
		
	CommonRenderInterface* renderer = m_guiHelper->getRenderInterface();
	
		b3AlignedObjectArray<unsigned int> indices;
		
		for (int i=0;i<m_cloth->springs.count;i++)
		{
			indices.push_back(m_cloth->springs[i].a);
			indices.push_back(m_cloth->springs[i].b);
		}
		float lineColor[4]={0.4,0.4,1.0,1};
		renderer->drawLines(&m_cloth->X[0].x,lineColor,total_points,sizeof(float3),&indices[0],indices.size(),1);
	
		float pointColor[4]={1,0.4,0.4,1};
		
//		renderer->drawPoints(&m_cloth->X[0].x,pointColor,total_points,sizeof(float3),3);
		
		
}


class CommonExampleInterface*    ImplicitClothCreateFunc(struct CommonExampleOptions& options)
{
	return new ImplicitClothExample(options.m_guiHelper, options.m_option);
}