Esempio n. 1
0
void terrain::setTerrainSize(btVector3 size)
{
	if(size == m_terrainSize) return;
	
	btVector3 modscale = (size - m_terrainSize) / m_terrainSize;	// the difference between the new and old size divided by the old size
	
	if(m_terrainSize.z() == 0) modscale.setZ(size.z());				// incase of NAN
	
	m_terrainMinHeight = m_terrainMaxHeight = 0;
    for(int i=0; i<m_terrainVertexCount; i++){
        m_terrainVerts[i].x += modscale.x() * m_terrainVerts[i].x;
        m_terrainVerts[i].y += modscale.y() * m_terrainVerts[i].y;
        
		if(m_terrainSize.z() == 0)
			m_terrainVerts[i].z = size.z();
		else
			m_terrainVerts[i].z += modscale.z() * m_terrainVerts[i].z;

		if(m_terrainVerts[i].z > m_terrainMaxHeight)
			m_terrainMaxHeight = m_terrainVerts[i].z;
		else if(m_terrainVerts[i].z < m_terrainMinHeight)
			m_terrainMinHeight = m_terrainVerts[i].z;
    }
    buildNormals();

	m_terrainSize = size;
	tTool->setSize(m_terrainSize);
	
	m_parent->printText(QString("Terrain Resized %1,%2,%3").arg(m_terrainSize.x()).arg(m_terrainSize.y()).arg(m_terrainSize.z()));

    this->terrainRefresh();
	emit newTerrain();
}
Esempio n. 2
0
void PhysicsDebug::drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
{
	D3D11_MAPPED_SUBRESOURCE mapStruct;

	ZeroMemory(&mapStruct, sizeof(mapStruct));

	ColourVertex vertexSet[] =
	{
		ColourVertex(D3DXVECTOR3(to.x(), to.y(), to.z()), D3DXVECTOR4(color.x(), color.y(), color.z(), 1.0f)),
		ColourVertex(D3DXVECTOR3(from.x(), from.y(), from.z()), D3DXVECTOR4(color.x(), color.y(), color.z(), 1.0f))
	};

	if(mContext->Map(mBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapStruct) != S_OK)
	{
		std::cerr << "Buffer Mapping Failed!" << std::endl;
		return;
	}

		memcpy(mapStruct.pData, &vertexSet[0], sizeof(ColourVertex) * mTotalIndices);

	mContext->Unmap(mBuffer, 0);

	mContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST);
	mShader.RenderVertexBuffer(mTotalIndices, mBuffer, mDevice, mContext, &ShaderData(mGameCam)); 
}
Esempio n. 3
0
void renderSPH()
{
	static const btVector3 activeColor = btVector3(1, 1, 1);
	static const btVector3 inactiveColor = btVector3(.3, .3, .7);
    for(int n = 0; n < fluid->numParticles(); ++n)
    {
        btVector3 p = fluid->getPosition(n);
		btVector3 vel = fluid->getVelocity(n);
		float speed = std::min(1.0f, vel.length() / 1.0f);
		btVector3 color = (1.0f - speed) * inactiveColor + speed * activeColor;

		glPushMatrix();
        
	    glColor3f(color.x(), color.y(), color.z() );
		float xt = (p.getX() - minBound.x()) / (maxBound.x() - minBound.x());
		float yt = (p.getY() - minBound.y()) / (maxBound.y() - minBound.y());
		float zt = (p.getZ() - minBound.z()) / (maxBound.z() - minBound.z());
        glTranslatef(xt*scale.x() + origin.x(), yt*scale.y()  + origin.y(), zt*scale.z() + origin.z());
        glBegin( GL_LINE_LOOP );
        GLUquadricObj *quadric;
        quadric = gluNewQuadric();
        gluQuadricDrawStyle(quadric, GLU_FILL );
        gluSphere( quadric , 1.0f , 8 , 8);
		glGetError();
        gluDeleteQuadric(quadric);
        glEnd();
		glPopMatrix();
    }
}
	virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
	{
		ScnDebugRenderComponent::pImpl()->drawLine(
			MaVec3d( from.x(), from.y(), from.z() ),
			MaVec3d( to.x(), to.y(), to.z() ),
			RsColour( color.x(), color.y(), color.z(), 1.0f ) );
	}
void BeGraphicsModel::draw( unsigned int current_material, const btTransform& transform, const btVector3& scale )
{
// 	btScalar m[16];
	transform.getOpenGLMatrix(m_matrix);
// 	m_system->matrixPush(GL_MODELVIEW);
	glPushMatrix();

// 	m_system->matrixMult(GL_MODELVIEW, m_matrix);
	m_system->matrixMult(m_matrix);
// 	m_system->matrixLoad(GL_MODELVIEW, m_matrix);
	
// 		m_system->matrixPush(GL_MODELVIEW);
// 		glPushMatrix();

			if ( scale.x() != 1.0f || scale.y() != 1.0f || scale.z() != 1.0f )
				m_system->matrixScale(GL_MODELVIEW, scale.x(), scale.y(), scale.z());
			
			draw(current_material);

// 		glPopMatrix();
// 		m_system->matrixPop(GL_MODELVIEW);

// 	m_system->matrixPop(GL_MODELVIEW);
	glPopMatrix();

	//glEnable(GL_CULL_FACE);
	//glCullFace(GL_BACK);
}
Esempio n. 6
0
	virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace)
	{
		elfCollision* collision;

		m_collisionObject = rayResult.m_collisionObject;
		if (normalInWorldSpace)
		{
			m_hitNormalWorld = rayResult.m_hitNormalLocal;
		}
		else
		{
			m_hitNormalWorld = m_collisionObject->getWorldTransform().getBasis()*rayResult.m_hitNormalLocal;
		}
		m_hitPointWorld.setInterpolate3(m_rayFromWorld, m_rayToWorld, rayResult.m_hitFraction);

		collision = elfCreateCollision();

		collision->position.x = m_hitPointWorld.x();
		collision->position.y = m_hitPointWorld.y();
		collision->position.z = m_hitPointWorld.z();
		collision->normal.x = m_hitNormalWorld.x();
		collision->normal.y = m_hitNormalWorld.y();
		collision->normal.z = m_hitNormalWorld.z();
		collision->actor = ((elfPhysicsObject*)((btRigidBody*)m_collisionObject)->getUserPointer())->actor;
		elfIncRef((elfObject*)collision->actor);

		elfAppendListObject(m_list, (elfObject*)collision);

		return rayResult.m_hitFraction;
	}
Esempio n. 7
0
static inline btVector3 getPrincipalInertia(const btVector3 & p, const btScalar & m)
{
	return m * btVector3(
		p.y() * p.y() + p.z() * p.z(),
		p.x() * p.x() + p.z() * p.z(),
		p.x() * p.x() + p.y() * p.y());
}
Esempio n. 8
0
void Camera::setTarget(btVector3 target) {
	btScalar yaw =
		atan((pos.x() - target.x()) / (pos.z() - target.z()));
	btScalar pitch =
		atan((pos.y() - target.y()) / (pos.z() - target.z()));
	quat = btQuaternion(btVector3(0, 1, 0), M_PI) * btQuaternion(yaw, pitch, 0);
}
void PhysicsDebugRenderer::drawContactPoint(const btVector3 &PointOnB, const btVector3 &normalOnB, btScalar distance, int lifeTime, const btVector3 &color)
{
	const glm::vec3 center(PointOnB.x(), PointOnB.y(), PointOnB.z());
	const glm::vec3 cubeSize(0.1f, 0.1f, 0.1f);
	const glm::vec3 cubeColor(color.x(), color.y(), color.z());

	DebugRenderer::DrawCube(center, cubeSize, cubeColor);
}
Esempio n. 10
0
void PhysicsDebugRenderer::drawLine(const btVector3 &from, const btVector3 &to, const btVector3 &color)
{
	const glm::vec3 start(from.x(), from.y(), from.z());
	const glm::vec3 end(to.x(), to.y(), to.z());
	const glm::vec3 lineColor(color.x(), color.y(), color.z());

	DebugRenderer::DrawLine(start, end, lineColor);
}
Esempio n. 11
0
	void drawLine(const btVector3 &from, const btVector3 &to, const btVector3 &color) override {
		DebugRenderQueue::addLine(
			Vec3(from.x(), from.y(), from.z()),
			Vec3(to.x(), to.y(), to.z()),
			Vec4(color.x(), color.y(), color.z(), 1.0f)
		);
		
	}
Esempio n. 12
0
void glDebugDraw::drawLine(const btVector3 &from, const btVector3 &to, 
            const btVector3 &color)
{
    glColor3f(color.x(), color.y(), color.z());
    glBegin(GL_LINES);
    glVertex3f(from.x(), from.y(), from.z());
    glVertex3f(to.x(), to.y(), to.z());
    glEnd();
}
Esempio n. 13
0
btVector3 btRigidBody::getLocalInertia() const
{

	btVector3 inertiaLocal;
	const btVector3 inertia = m_invInertiaLocal;
	inertiaLocal.setValue(inertia.x() != btScalar(0.0) ? btScalar(1.0) / inertia.x() : btScalar(0.0),
		inertia.y() != btScalar(0.0) ? btScalar(1.0) / inertia.y() : btScalar(0.0),
		inertia.z() != btScalar(0.0) ? btScalar(1.0) / inertia.z() : btScalar(0.0));
	return inertiaLocal;
}
Esempio n. 14
0
	void PhysicsDebugDraw::drawTriangle( const btVector3& a, const btVector3& b, const btVector3& c,const btVector3& color, btScalar alpha )
	{
		const Vector3 v1 = { a.x(), a.y(), a.z() };
		const Vector3 v2 = { b.x(), b.y(), b.z() };
		const Vector3 v3 = { c.x(), c.y(), c.z() };
		const Color color2 = color::fromFloatRGBA( color.x(), color.y(), color.z(), 1.0f );

		const Vector3 points[] = { v1, v2, v3, v1 };
		debugrenderer::drawLines( points, TIKI_COUNT( points ), color2 );
	}
Esempio n. 15
0
void PhysicsDebugDrawer::drawLine(const btVector3& from, const btVector3& to, const btVector3& color)
{
    // Draw a line with the 'from' position being slightly darker.
    glm::vec3 glmColor = glm::vec3(color.x(), color.y(), color.z());
    lines.positions.push_back(glm::vec3(from.x(), from.y(), from.z()));
    lines.colors.push_back(glmColor * 0.80f);

    lines.positions.push_back(glm::vec3(to.x(), to.y(), to.z()));
    lines.colors.push_back(glmColor);
}
Esempio n. 16
0
void PhysicsDebug::drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
{
	mIC->BeginVertex();
	mIC->SetPosition3(from.get128());
	mIC->SetColor(FromRGBf(color.x(), color.y(), color.z()));
	mIC->EndVertex();
	mIC->BeginVertex();
	mIC->SetPosition3(to.get128());
	mIC->SetColor(FromRGBf(color.x(), color.y(), color.z()));
	mIC->EndVertex();
}
Esempio n. 17
0
void updateCollisionSphere(float x, float y, float z, float vx, float vy, float vz)
{
	x = (x - origin.x()) / scale.x();
	y = (y - origin.y()) / scale.y();
	z = (z - origin.z()) / scale.z();
	x = x * (maxBound.x() - minBound.x()) + minBound.x();
	y = y * (maxBound.y() - minBound.y()) + minBound.y();
	z = z * (maxBound.z() - minBound.z()) + minBound.z();
	collisionSpherePos = btVector3(x, y, z);
	collisionSphereVel = btVector3(vx, vy, vz);
}
Esempio n. 18
0
  virtual void drawSphere (const btVector3& p, btScalar radius, const btVector3& color)
  {
    double p_[3] = {p.x() / bulletWorldScalingFactor,
                    p.y() / bulletWorldScalingFactor,
                    p.z() / bulletWorldScalingFactor};
    double color_[3] = {color.x(), color.y(), color.z()};

    if(callbacks_.drawSphere)
      (*callbacks_.drawSphere)(p_, radius / bulletWorldScalingFactor, color_, arg_);
    else
      btIDebugDraw::drawSphere(p/bulletWorldScalingFactor, radius / bulletWorldScalingFactor, color);
  }
 void btWorldFactory::createBoxAreaSpawn(QVariantList &spawnsList, btVector3 size, btVector3 pos)
 {
     QVariantMap spawnMap;
     spawnMap.insert("type", "boxArea");
     spawnMap.insert("sizeX", (double)size.x());
     spawnMap.insert("sizeY", (double)size.y());
     spawnMap.insert("sizeZ", (double)size.z());
     spawnMap.insert("posX", (double)pos.x());
     spawnMap.insert("posY", (double)pos.y());
     spawnMap.insert("posZ", (double)pos.z());
     spawnsList.append(spawnMap);
 }
Esempio n. 20
0
void PhysicsDebugDrawer::drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
{

	
	data.push_back( from.x());
	data.push_back( from.y());
	data.push_back( from.z());

	data.push_back( to.x());
	data.push_back( to.y());
	data.push_back( to.z());
}
Esempio n. 21
0
	void PhysicsDebugDraw::drawLine( const btVector3& from, const btVector3& to, const btVector3& color )
	{
		const Color color2	= color::fromFloatRGBA( color.x(), color.y(), color.z(), 1.0f );

		const Vector3 points[] =
		{
			{ from.x(), from.y(), from.z() },
			{ to.x(), to.y(), to.z() }
		};

		debugrenderer::drawLines( points, TIKI_COUNT( points ), color2 );
	}
Esempio n. 22
0
  virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color)
  {
    double PointOnB_[3] = {PointOnB.x() / bulletWorldScalingFactor,
                           PointOnB.y() / bulletWorldScalingFactor,
                           PointOnB.z() / bulletWorldScalingFactor};
    double normalOnB_[3] = {normalOnB.x() / bulletWorldScalingFactor,
                            normalOnB.y() / bulletWorldScalingFactor,
                            normalOnB.z() / bulletWorldScalingFactor};
    double color_[3] = {color.x(), color.y(), color.z()};

    if(callbacks_.drawContactPoint)
      (*callbacks_.drawContactPoint)(PointOnB_, normalOnB_, distance, lifeTime, color_, arg_);
  }
Esempio n. 23
0
void InverseTransformPoint3x3(btVector3& out, const btVector3& in, const btTransform& tr)
{
	const btMatrix3x3& rot = tr.getBasis();
	const btVector3& r0 = rot[0];
	const btVector3& r1 = rot[1];
	const btVector3& r2 = rot[2];

	const btScalar x = r0.x()*in.x() + r1.x()*in.y() + r2.x()*in.z();
	const btScalar y = r0.y()*in.x() + r1.y()*in.y() + r2.y()*in.z();
	const btScalar z = r0.z()*in.x() + r1.z()*in.y() + r2.z()*in.z();

	out.setValue(x, y, z);
}
Esempio n. 24
0
// void BeGraphicsModel::draw( const float* transform, const float x, const float y, const float z )
void BeGraphicsModel::drawToDepth(const float* transform, const btVector3& scale )
{
	m_system->matrixPush(GL_MODELVIEW);
// 	std::cout << "scale" << std::endl;
	m_system->matrixMult(GL_MODELVIEW, transform);
	if ( scale.x() != 1.0f || scale.y() != 1.0f || scale.z() != 1.0f )
		m_system->matrixScale(GL_MODELVIEW, scale.x(), scale.y(), scale.z());
	drawToDepth();
	m_system->matrixPop(GL_MODELVIEW);

	//glEnable(GL_CULL_FACE);
	//glCullFace(GL_BACK);
}
Esempio n. 25
0
 virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
 {
   double from_[3] = {from.x() / bulletWorldScalingFactor,
                      from.y() / bulletWorldScalingFactor,
                      from.z() / bulletWorldScalingFactor};
   double to_[3] = {to.x() / bulletWorldScalingFactor,
                    to.y() / bulletWorldScalingFactor,
                    to.z() / bulletWorldScalingFactor};
   double color_[3] = {color.x(), color.y(), color.z()};
   
   if(callbacks_.drawLine)
     (*callbacks_.drawLine)(from_, to_, color_, arg_);
 }
Esempio n. 26
0
	void multiply(const NxQuat& left, const btVector3& right)
	{
	float a,b,c,d;

	a = - left.x*right.x() - left.y*right.y() - left.z *right.z();
	b =   left.w*right.x() + left.y*right.z() - right.y()*left.z;
	c =   left.w*right.y() + left.z*right.x() - right.z()*left.x;
	d =   left.w*right.z() + left.x*right.y() - right.x()*left.y;

	w = a;
	x = b;
	y = c;
	z = d;
	}
    void btWorldFactory::createSphere(QVariantList &shapesList, btScalar radius, btVector3 pos, btVector3 euler, double density) {

        QVariantMap sphereMap;
        sphereMap.insert("type","sphere");
        sphereMap.insert("radius",(double)radius);
        sphereMap.insert("posX",(double)pos.x());
        sphereMap.insert("posY",(double)pos.y());
        sphereMap.insert("posZ",(double)pos.z());
        sphereMap.insert("eulerX",(double)euler.x());
        sphereMap.insert("eulerY",(double)euler.y());
        sphereMap.insert("eulerZ",(double)euler.z());
        sphereMap.insert("density",(double)density);
        shapesList.append(sphereMap);
    }
void AnimaPhysicsDebugDrawer::drawLine(const btVector3& from, const btVector3& to, const btVector3& color)
{
	AnimaVertex3f start(from.x(), from.y(), from.z());
	AnimaVertex3f end(to.x(), to.y(), to.z());
	AnimaColor3f col(color.x(), color.y(), color.z());
	
	// Aggiungo alla lista di vertici i due punti della linea
	_vertices.push_back(start);
	_vertices.push_back(end);
	
	// Aggiungo alla lista dei colori il colore due volte, una per ogni vertice
	_colors.push_back(col);
	_colors.push_back(col);
}
Esempio n. 29
0
 void drawLine(
     const btVector3& from,
     const btVector3& to,
     const btVector3& fromColor,
     const btVector3& toColor)
 {
     glBegin(GL_LINES);
     glColor3d(fromColor.x(), fromColor.y(), fromColor.z());
     glVertex3d(from.x(), from.y(), from.z());
     glColor3d(toColor.x(), toColor.y(), toColor.z());
     glVertex3d(to.x(), to.y(), to.z());
     glEnd();
     glColor3d(1, 1, 1);
 }
    void btWorldFactory::createCylinder(QVariantList &shapesList, btScalar radius, btScalar height, btVector3 pos, btVector3 euler, double density) {

        QVariantMap cylinderMap;
        cylinderMap.insert("type","cylinder");
        cylinderMap.insert("radius",(double)radius);
        cylinderMap.insert("height",(double)height);
        cylinderMap.insert("posX",(double)pos.x());
        cylinderMap.insert("posY",(double)pos.y());
        cylinderMap.insert("posZ",(double)pos.z());
        cylinderMap.insert("eulerX",(double)euler.x());
        cylinderMap.insert("eulerY",(double)euler.y());
        cylinderMap.insert("eulerZ",(double)euler.z());
        cylinderMap.insert("density",(double)density);
        shapesList.append(cylinderMap);
    }