示例#1
0
void Box::DoRender() const
{
	glScalef(GetHalfSize().x, GetHalfSize().y, GetHalfSize().z);
	glutSolidCube(2);
	glPushAttrib(GL_LIGHTING_BIT);
	glDisable(GL_LIGHTING);
	glColor3f(1,1,1);
	glutWireCube(2);
	glPopAttrib();
}
示例#2
0
文件: Box.cpp 项目: brindza/phys-anim
void Box::meshify(int divide) {
	// positive z is into the page
	int id = 0;

	Vector3 bound = GetHalfSize();
	float x_base = -1 * bound[0];
	float y_base = -1 * bound[1];
	float z_base = -1 * bound[2];

	Vertex * P111 = new Vertex(Vector3(x_base, bound[1], z_base), id); id = id + 1;
	Vertex * P211 = new Vertex(Vector3(x_base, y_base, z_base), id); id = id + 1;
	Vertex * P121 = new Vertex(Vector3(bound[0], bound[1], z_base), id); id = id + 1;
	Vertex * P221 = new Vertex(Vector3(bound[0], y_base, z_base), id); id = id+1;
	Vertex * P112 = new Vertex(Vector3(x_base, bound[1], bound[2]), id); id = id+1;
	Vertex * P122 = new Vertex(Vector3(bound[0], bound[1], bound[2]), id); id = id + 1;
	Vertex * P212 = new Vertex(Vector3(x_base, y_base, bound[2]), id); id = id + 1;
	Vertex * P222 = new Vertex(Vector3(bound[0], y_base, bound[2]), id); id = id+1;

	P111->addNeighbor(P112);
	P111->addNeighbor(P211);
	P111->addNeighbor(P121);

	P211->addNeighbor(P111);
	P211->addNeighbor(P212);
	P211->addNeighbor(P221);

	P121->addNeighbor(P111);
	P121->addNeighbor(P221);
	P121->addNeighbor(P122);

	P221->addNeighbor(P211);
	P221->addNeighbor(P222);
	P221->addNeighbor(P121);

	P112->addNeighbor(P122);
	P112->addNeighbor(P212);
	P112->addNeighbor(P111);

	P122->addNeighbor(P112);
	P122->addNeighbor(P222);
	P122->addNeighbor(P121);

	P222->addNeighbor(P122);
	P222->addNeighbor(P221);
	P222->addNeighbor(P212);

	P212->addNeighbor(P222);
	P212->addNeighbor(P112);
	P212->addNeighbor(P211);

	verticies.push_back(P111);
	verticies.push_back(P121);
	verticies.push_back(P221);
	verticies.push_back(P211);
	verticies.push_back(P112);
	verticies.push_back(P122);
	verticies.push_back(P222);
	verticies.push_back(P212);
}
示例#3
0
		BOHGE_FORCEINLINE Aabbox3d operator* (const vector3<T>& scale ) const
		{
			vector3<T> center = GetCenter();
			vector3<T> size = GetHalfSize();
			size *= scale;
			//注意旋转以后的顶点位置的前后有所变化,需要更改构造方式,此处会影响相交的判断
			return Aabbox3d<T>( center - size , center + size );
		}
示例#4
0
文件: Box.cpp 项目: brindza/phys-anim
Vector3 Box::GetNormalLocalInertialTensor() const
{
	// TODO: is this correct? I am not sure what the 'Normal' Inertial Tensor is
	// interial matrix for box is
	//				 | (y^2 + z^2)      0           0      |
	//	I = (M/12) * |      0      (x^2 + z^2)      0      |
	//				 |      0           0      (x^2 + y^2) |
	Vector3 size = 2*GetHalfSize();
	float x2 = size.x * size.x;
	float y2 = size.y * size.y;
	float z2 = size.z * size.z;
	return (GetNormalMass()/12.0) * Vector3((y2+z2), (x2+z2), (x2+y2));
}
示例#5
0
Ogre::Vector3 Box::GetClosestPoint(Vector3 const& p) const
{
	// transform into local space
	Vector3 op = GetTransformation().inverseAffine()*p;
	Vector3 hs = GetHalfSize();
	if(fabs(op.x) < hs.x && fabs(op.y) < hs.y && fabs(op.z) < hs.z)
	{
		// point inside box
		return p;
	}

	Vector3 oc = Vector3(
		std::min(std::max(op.x, -hs.x), hs.x),
		std::min(std::max(op.y, -hs.y), hs.y),
		std::min(std::max(op.z, -hs.z), hs.z));

	return GetTransformation()*oc;
}
示例#6
0
void Box::GetExtentsAlongAxis(Vector4 const& v, float & a, float & b) const
{
	// The implementation of this function is optimized to the point of opacity.
	// If you're interested in its inner workings, contact me directly.

	// transform v into object space.
	Vector4 ov = TransformPlane(v, GetTransformation().inverseAffine());
	Vector3 ov3(ov.x, ov.y, ov.z);
	// note: ov3 is unit length

	// distance from center of box to plane
	float dc = ov.w;

	// distances along ov from center to each of the positive three faces, abs'ed and summed
	float extDist = GetHalfSize().absDotProduct(ov3);

	a = dc - extDist;
	b = dc + extDist;
}