File: Wall.cpp

package info (click to toggle)
yade 2026.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,448 kB
  • sloc: cpp: 97,645; python: 52,173; sh: 677; makefile: 162
file content (69 lines) | stat: -rw-r--r-- 2,476 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
// © 2009 Václav Šmilauer <eudoxos@arcig.cz>
#include <core/Aabb.hpp>
#include <pkg/common/Wall.hpp>

#ifdef YADE_OPENGL
#include <lib/opengl/OpenGLWrapper.hpp>
#endif

namespace yade { // Cannot have #include directive inside.

YADE_PLUGIN((Wall)(Bo1_Wall_Aabb)
#ifdef YADE_OPENGL
                    (Gl1_Wall)
#endif
);

Wall::~Wall() { } // vtable

Real Wall::getVolume() { return 0.; }

void Bo1_Wall_Aabb::go(const shared_ptr<Shape>& cm, shared_ptr<Bound>& bv, const Se3r& se3, const Body* /*b*/)
{
	Wall* wall = static_cast<Wall*>(cm.get());
	if (!bv) { bv = shared_ptr<Bound>(new Aabb); }
	Aabb* aabb = static_cast<Aabb*>(bv.get());
	if (scene->isPeriodic && scene->cell->hasShear()) throw logic_error(__FILE__ "Walls not supported in sheared cell.");
	const Real& inf       = std::numeric_limits<Real>::infinity();
	aabb->min             = Vector3r(-inf, -inf, -inf);
	aabb->min[wall->axis] = se3.position[wall->axis];
	aabb->max             = Vector3r(inf, inf, inf);
	aabb->max[wall->axis] = se3.position[wall->axis];
}


#ifdef YADE_OPENGL
int Gl1_Wall::div = 20;

void Gl1_Wall::go(const shared_ptr<Shape>& cm, const shared_ptr<State>& pp, bool, const GLViewInfo& glinfo)
{
	Wall*    wall = static_cast<Wall*>(cm.get());
	int      ax0 = wall->axis, ax1 = (wall->axis + 1) % 3, ax2 = (wall->axis + 2) % 3;
	Vector3r a1, b1, a2, b2; // beginnings (a) and endings (b) of lines in both senses (0,1)
	// compensate for our position, since the functor is called with transformation to the wall se3 already, but we really want to be centered in the middle of the scene
	Real mn1  = glinfo.sceneCenter[ax1] - glinfo.sceneRadius - pp->se3.position[ax1];
	Real mn2  = glinfo.sceneCenter[ax2] - glinfo.sceneRadius - pp->se3.position[ax2];
	Real step = 2 * glinfo.sceneRadius / div;
	//cerr<<"center "<<glinfo.sceneCenter<<", radius "<<glinfo.sceneRadius<<", mn["<<ax1<<"]="<<mn1<<", mn["<<ax2<<"]="<<mn2<<endl;

	a1[ax0] = b1[ax0] = a2[ax0] = b2[ax0] = 0;
	a1[ax1]                               = mn1 - step;
	a2[ax2]                               = mn2 - step;
	b1[ax1]                               = mn1 + step * (div + 2);
	b2[ax2]                               = mn2 + step * (div + 2);
	glColor3v(cm->color);
	glBegin(GL_LINES)
		;
		for (int i = 0; i <= div; i++) {
			a1[ax2] = b1[ax2] = mn1 + i * step;
			a2[ax1] = b2[ax1] = mn2 + i * step;
			glVertex3v(a1);
			glVertex3v(b1);
			glVertex3v(a2);
			glVertex3v(b2);
		}
	glEnd();
}
#endif

} // namespace yade