Example #1
0
FloatShapeInterval OffsetPolygonEdge::clippedEdgeXRange(float y1,
                                                        float y2) const {
  if (!overlapsYRange(y1, y2) || (y1 == maxY() && minY() <= y1) ||
      (y2 == minY() && maxY() >= y2))
    return FloatShapeInterval();

  if (isWithinYRange(y1, y2))
    return FloatShapeInterval(minX(), maxX());

  // Clip the edge line segment to the vertical range y1,y2 and then return
  // the clipped line segment's horizontal range.

  FloatPoint minYVertex;
  FloatPoint maxYVertex;
  if (vertex1().y() < vertex2().y()) {
    minYVertex = vertex1();
    maxYVertex = vertex2();
  } else {
    minYVertex = vertex2();
    maxYVertex = vertex1();
  }
  float xForY1 = (minYVertex.y() < y1) ? xIntercept(y1) : minYVertex.x();
  float xForY2 = (maxYVertex.y() > y2) ? xIntercept(y2) : maxYVertex.x();
  return FloatShapeInterval(std::min(xForY1, xForY2), std::max(xForY1, xForY2));
}
Example #2
0
void ShaderNode::translateFormOtherNode(CCAffineTransform &transform)
{
	CCNode::setAdditionalTransform(transform);

	m_center = vertex2(m_sAdditionalTransform.tx * CC_CONTENT_SCALE_FACTOR(), m_sAdditionalTransform.ty * CC_CONTENT_SCALE_FACTOR());
	m_resolution = vertex2( SIZE_X * m_sAdditionalTransform.a, SIZE_Y * m_sAdditionalTransform.d);
}
Example #3
0
bool VertexPair::overlapsRect(const FloatRect& rect) const
{
    bool boundsOverlap = (minX() < rect.maxX()) && (maxX() > rect.x()) && (minY() < rect.maxY()) && (maxY() > rect.y());
    if (!boundsOverlap)
        return false;

    float leftSideValues[4] = {
        leftSide(vertex1(), vertex2(), rect.minXMinYCorner()),
        leftSide(vertex1(), vertex2(), rect.maxXMinYCorner()),
        leftSide(vertex1(), vertex2(), rect.minXMaxYCorner()),
        leftSide(vertex1(), vertex2(), rect.maxXMaxYCorner())
    };

    int currentLeftSideSign = 0;
    for (unsigned i = 0; i < 4; ++i) {
        if (!leftSideValues[i])
            continue;
        int leftSideSign = leftSideValues[i] > 0 ? 1 : -1;
        if (!currentLeftSideSign)
            currentLeftSideSign = leftSideSign;
        else if (currentLeftSideSign != leftSideSign)
            return true;
    }

    return false;
}
Example #4
0
ShaderNode::ShaderNode()
:m_center(vertex2(0.0f, 0.0f))
,m_resolution(vertex2(0.0f, 0.0f))
,m_time(0.0f)
,m_uniformCenter(0)
,m_uniformResolution(0)
,m_uniformTime(0)
{
}
//--------------------------------------------------------
void CShaderNode::setContentSize(const CCSize& var)
{
	CCNode::setContentSize(var);
	m_tagResolutionPos = vertex2(getContentSize().width,getContentSize().height);
	m_tagCenterPos.x = m_tagResolutionPos.x/2;
	m_tagCenterPos.y = m_tagResolutionPos.y/2;
}
Example #6
0
void ShaderNode::setContentSize(const CCSize& var)
{
	CCNode::setContentSize(var);
	m_resolution = vertex2(getContentSize().width, getContentSize().height);
	m_center.x = m_resolution.x / 2;
	m_center.y = m_resolution.y / 2;
}
void CCParticleSystemPoint::updateQuadWithParticle(tCCParticle* particle, CGPoint newPosition)
{
	// place vertices and colos in array
    m_pVertices[m_nParticleIdx].pos = vertex2(newPosition.x, newPosition.y);
	m_pVertices[m_nParticleIdx].size = particle->size;
	m_pVertices[m_nParticleIdx].colors = particle->color;
}
Example #8
0
// See ConvexDecompositionDemo.cpp in Bullet Docs
btCollisionShape* GameObject::GenerateShape(std::string file, float scale)
{
  ConvexDecomposition::WavefrontObj wo;
  if (!wo.loadObj (strcat ("media/models/", file.c_str ()))) {
    printf("Failed to load Player obj file\n");
  }

  btTriangleMesh* trimesh = new btTriangleMesh();

  for (int i=0;i<wo.mTriCount;i++) {
    int index0 = wo.mIndices[i*3];
    int index1 = wo.mIndices[i*3+1];
    int index2 = wo.mIndices[i*3+2];

    btVector3 vertex0(wo.mVertices[index0*3], wo.mVertices[index0*3+1],wo.mVertices[index0*3+2]);
    btVector3 vertex1(wo.mVertices[index1*3], wo.mVertices[index1*3+1],wo.mVertices[index1*3+2]);
    btVector3 vertex2(wo.mVertices[index2*3], wo.mVertices[index2*3+1],wo.mVertices[index2*3+2]);

    vertex0 *= scale;
    vertex1 *= scale;
    vertex2 *= scale;

    trimesh->addTriangle(vertex0,vertex1,vertex2);
  }

  btConvexShape* shape = new btConvexTriangleMeshShape(trimesh);

  /*printf("old numTriangles= %d\n",wo.mTriCount);
  printf("new numTrinagles= %d\n",trimesh->getNumTriangles());
  printf("old numIndices = %d\n",wo.mTriCount*3);
  printf("old numVertices = %d\n",wo.mVertexCount);*/

  return shape;
}
void ccDrawFilledPoly( const CCPoint *poli, unsigned int numberOfPoints, ccColor4F color )
{
    lazy_init();

    shader_->use();
    shader_->setUniformForModelViewProjectionMatrix();    
    shader_->setUniformLocationWith4fv(colorLocation_, (GLfloat*) &color.r, 1);

    ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );

    // XXX: Mac OpenGL error. arrays can't go out of scope before draw is executed
    ccVertex2F* newPoli = new ccVertex2F[numberOfPoints];

    // iPhone and 32-bit machines optimization
    if( sizeof(CCPoint) == sizeof(ccVertex2F) )
    {
        glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, poli);
    }
    else
    {
        // Mac on 64-bit
        for( unsigned int i=0; i<numberOfPoints;i++)
        {
            newPoli[i] = vertex2( poli[i].x, poli[i].y );
        }
        glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, newPoli);
    }    

    glDrawArrays(GL_TRIANGLE_FAN, 0, (GLsizei) numberOfPoints);

    CC_SAFE_DELETE_ARRAY(newPoli);
    CC_INCREMENT_GL_DRAWS(1);
}
Example #10
0
void CCParticleSystemPoint::updateQuadWithParticle(tCCParticle* particle, const CCPoint& newPosition)
{
	// place vertices and colos in array
    m_pVertices[m_uParticleIdx].pos = vertex2(newPosition.x, newPosition.y);
	m_pVertices[m_uParticleIdx].size = particle->size;
	ccColor4B color = {(GLubyte)(particle->color.r * 255), (GLubyte)(particle->color.g * 255), (GLubyte)(particle->color.b * 255), 
		(GLubyte)(particle->color.a * 255)};
	m_pVertices[m_uParticleIdx].color = color;
}
/* ----------------------------------------------------------------------- 
 | the function describe build btRigidBody from Ogre mesh :   
 |
 | @prama in : Ogre entity (use as a single object)
 | @pamra out : return true if build success and add collision shape to dynamicsworld
   ----------------------------------------------------------------------- */
bool
buildRigidBodyFromOgreEntity(Ogre::Entity* ent,
                             btDynamicsWorld* dynamicsWorld, 
                             btAlignedObjectArray<btCollisionShape*>& collisionShapes,
                             void* &data)
{
    void *vertices, *indices;
    size_t vertexCount = 0, indexCount = 0;
    
    getVertexBuffer(ent, vertices, vertexCount, indices, indexCount);
       
    btScalar mass(1.0f);	
    btVector3 localInertia(0,0,0);
    
    data = new btTriangleMesh();
    btTriangleMesh* trimesh = static_cast<btTriangleMesh*>(data);
    btAssert(trimesh);

    Ogre::Vector3* vert = (Ogre::Vector3*)vertices;
    Ogre::ulong* index = (Ogre::ulong*)indices;

	for (size_t i=0 ; i<vertexCount ; i++)
	{
		int index0 = index[i*3];
		int index1 = index[i*3+1];
		int index2 = index[i*3+2];

        btVector3 vertex0(vert[index0].x, vert[index0].y, vert[index0].z);
        btVector3 vertex1(vert[index1].x, vert[index1].y, vert[index1].z);
        btVector3 vertex2(vert[index2].x, vert[index2].y, vert[index2].z);

		trimesh->addTriangle(vertex0,vertex1,vertex2);
	}

    delete [] vertices;
    delete [] indices;
    
    btCollisionShape* colShape = new btConvexTriangleMeshShape(trimesh);
    const btVector3& scale = colShape->getLocalScaling();
    colShape->calculateLocalInertia(mass,localInertia);
    collisionShapes.push_back(colShape);
    
    btTransform trans;
    trans.setIdentity();
    btDefaultMotionState* motionState = new btDefaultMotionState(trans);
    btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,motionState,colShape,localInertia);
    btRigidBody* body = new btRigidBody(rbInfo);
    dynamicsWorld->addRigidBody(body);
    
    // link RigidBody and SceneNode
    Ogre::SceneNode* node = ent->getParentSceneNode();
    body->setUserPointer((void*)node);
    
    return true;
}
Example #12
0
float OffsetPolygonEdge::xIntercept(float y) const
{
    ASSERT(y >= minY() && y <= maxY());

    if (vertex1().y() == vertex2().y() || vertex1().x() == vertex2().x())
        return minX();
    if (y == minY())
        return vertex1().y() < vertex2().y() ? vertex1().x() : vertex2().x();
    if (y == maxY())
        return vertex1().y() > vertex2().y() ? vertex1().x() : vertex2().x();

    return vertex1().x() + ((y - vertex1().y()) * (vertex2().x() - vertex1().x()) / (vertex2().y() - vertex1().y()));
}
Example #13
0
void Joystick::drawArrow()
{
    CCPoint point=ccpAdd(_touchedPoint, _vector);
    ccVertex2F vertices[4]={{point.x,point.y},{point.x-25,point.y-15},{point.x,point.y+35},{point.x+25,point.y-15}};
    for (int i=0; i<4; ++i) {
        CCPoint tempPoint=ccpRotateByAngle(ccp(vertices[i].x,vertices[i].y), ccp(point.x,point.y),-1*ccpToAngle(ccp(_vector.y,_vector.x)));
        vertices[i]=vertex2(tempPoint.x, tempPoint.y);
    }
    ccColor4F colors[4]={{0,0,0,1},{0,0,0,1},{0,0,0,1},{0,0,0,1}};
    ccGLEnableVertexAttribs(kCCVertexAttribFlag_Position|kCCVertexAttribFlag_Color);
    glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices);
    glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_FLOAT, GL_FALSE, 0, colors);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
Example #14
0
void Joystick::drawCircle()
{
    ccVertex2F vertex[CIRCLE_VERTEX_COUNT+2];
    ccColor4F colors[CIRCLE_VERTEX_COUNT+2];
    float coef=M_PI*2/CIRCLE_VERTEX_COUNT;
    int radius=30;
    vertex[0]=vertex2(_touchedPoint.x, _touchedPoint.y);
    colors[0]=ccc4f(0, 0, 0, 1);
    for (int i=0; i<CIRCLE_VERTEX_COUNT; ++i) {
        vertex[i+1].x=cosf(coef*i)*radius+_touchedPoint.x;
        vertex[i+1].y=sinf(coef*i)*radius+_touchedPoint.y;
        colors[i+1]=ccc4f(0, 0, 0, 1);
    }
    
    vertex[CIRCLE_VERTEX_COUNT+1]=vertex2(radius+_touchedPoint.x, _touchedPoint.y);
    colors[CIRCLE_VERTEX_COUNT+1]=ccc4f(0, 0, 0, 1);

    ccGLEnableVertexAttribs(kCCVertexAttribFlag_Position|kCCVertexAttribFlag_Color);
    glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertex);
    glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_FLOAT, GL_FALSE, 0, colors);
    
    glDrawArrays(GL_TRIANGLE_FAN, 0, CIRCLE_VERTEX_COUNT+2);
}
Example #15
0
bool ShaderNode::initWithVertex(const char *vert, const char *frag)
{

    loadShaderVertex(vert, frag);

    m_time = 0;
    m_resolution = vertex2(SIZE_X, SIZE_Y);

    scheduleUpdate();

    setContentSize(CCSizeMake(SIZE_X, SIZE_Y));
    setAnchorPoint(ccp(0.5f, 0.5f));

    return true;
}
Example #16
0
void BulletObject::CreateFromEntity()
{
	bool wasPolygonGroup = false;

	RenderObject * renderObject = ((RenderComponent*)entity->GetComponent(Component::RENDER_COMPONENT))->GetRenderObject();
	uint32 batchesCount = renderObject->GetRenderBatchCount();
	for(uint32 batchIndex = 0; batchIndex < batchesCount; ++batchIndex)
	{
		RenderBatch * batch = renderObject->GetRenderBatch(batchIndex);
		PolygonGroup * pg = batch->GetPolygonGroup();
		if(pg)
		{
			if(!wasPolygonGroup)
			{
				collisionObject = new btCollisionObject();
				trimesh = new btTriangleMesh();
				createdWith = entity->GetWorldTransform();
				wasPolygonGroup = true;
			}

			for(int32 i = 0; i < pg->indexCount / 3; i++)
			{
				uint16 index0 = pg->indexArray[i*3];
				uint16 index1 = pg->indexArray[i*3+1];
				uint16 index2 = pg->indexArray[i*3+2];
				Vector3 v;
				pg->GetCoord(index0, v);
				v = v * createdWith;
				btVector3 vertex0(v.x, v.y, v.z);
				pg->GetCoord(index1, v);
				v = v * createdWith;
				btVector3 vertex1(v.x, v.y, v.z);
				pg->GetCoord(index2, v);
				v = v * createdWith;
				btVector3 vertex2(v.x, v.y, v.z);

				trimesh->addTriangle(vertex0,vertex1,vertex2, false);
			}
		}
	}

	if(wasPolygonGroup)
	{
		shape = new btBvhTriangleMeshShape(trimesh, true, true);    
		collisionObject->setCollisionShape(shape);
		collWorld->addCollisionObject(collisionObject);
	}
}
Example #17
0
void BulletObject::CreateCollisionObject()
{
	collisionObject = new btCollisionObject();
	
	trimesh = new btTriangleMesh();
	
	//const Vector<StaticMesh*> & meshes = meshNode->GetMeshes();
	//const Vector<int32> & indexes = meshNode->GetPolygonGroupIndexes();
	const Vector<PolygonGroupWithMaterial*> & polygroups = meshNode->GetPolygonGroups();
    
    
	uint32 meshesSize = (uint32)polygroups.size();

	createdWith = meshNode->GetWorldTransform();
	if (meshesSize > 0)
	{
		for (uint32 k = 0; k < meshesSize; ++k)
		{
			PolygonGroup * pg = polygroups[k]->GetPolygonGroup();    
			
			int i;
			for (i = 0; i < pg->indexCount / 3; i++)
			{
				uint16 index0 = pg->indexArray[i*3];
				uint16 index1 = pg->indexArray[i*3+1];
				uint16 index2 = pg->indexArray[i*3+2];
				Vector3 v;
				pg->GetCoord(index0, v);
				v = v * createdWith;
				btVector3 vertex0(v.x, v.y, v.z);
				pg->GetCoord(index1, v);
				v = v * createdWith;
				btVector3 vertex1(v.x, v.y, v.z);
				pg->GetCoord(index2, v);
				v = v * createdWith;
				btVector3 vertex2(v.x, v.y, v.z);
				
				trimesh->addTriangle(vertex0,vertex1,vertex2, false);
			}
		}
		shape = new btBvhTriangleMeshShape(trimesh, true, true);    

        collisionObject->setCollisionShape(shape);
        collWorld->addCollisionObject(collisionObject);
	}
	
}
btCollisionShape *Enco3D::Physics::ConvexMeshCollisionShape::toBulletPhysicsCollisionShape()
{
	btTriangleMesh *triangleMesh = new btTriangleMesh;
	for (unsigned int i = 0; i < m_mesh->getIndexCount(); i += 3)
	{
		unsigned int index0 = m_mesh->getIndices()[i + 0];
		unsigned int index1 = m_mesh->getIndices()[i + 1];
		unsigned int index2 = m_mesh->getIndices()[i + 2];

		btVector3 vertex0(m_mesh->getVertices()[index0].x, m_mesh->getVertices()[index0].y, m_mesh->getVertices()[index0].z);
		btVector3 vertex1(m_mesh->getVertices()[index1].x, m_mesh->getVertices()[index1].y, m_mesh->getVertices()[index1].z);
		btVector3 vertex2(m_mesh->getVertices()[index2].x, m_mesh->getVertices()[index2].y, m_mesh->getVertices()[index2].z);

		triangleMesh->addTriangle(vertex0, vertex1, vertex2);
	}

	return new btConvexTriangleMeshShape(triangleMesh, true);
}
void ccDrawSolidPoly( const CCPoint *poli, unsigned int numberOfPoints, ccColor4F color )
{
    lazy_init();

    s_pShader->use();
    s_pShader->setUniformsForBuiltins();
    s_pShader->setUniformLocationWith4fv(s_nColorLocation, (GLfloat*) &color.r, 1);

    ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );

    // XXX: Mac OpenGL error. arrays can't go out of scope before draw is executed
    ccVertex2F* newPoli = new ccVertex2F[numberOfPoints];

    // iPhone and 32-bit machines optimization
    if( sizeof(CCPoint) == sizeof(ccVertex2F) )
    {
#ifdef EMSCRIPTEN
        setGLBufferData((void*) poli, numberOfPoints * sizeof(CCPoint));
        glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
        glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, poli);
#endif // EMSCRIPTEN
    }
    else
    {
        // Mac on 64-bit
        for( unsigned int i=0; i<numberOfPoints;i++)
        {
            newPoli[i] = vertex2( poli[i].x, poli[i].y );
        }
#ifdef EMSCRIPTEN
        setGLBufferData(newPoli, numberOfPoints * sizeof(ccVertex2F));
        glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
        glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, newPoli);
#endif // EMSCRIPTEN
    }    

    glDrawArrays(GL_TRIANGLE_FAN, 0, (GLsizei) numberOfPoints);

    CC_SAFE_DELETE_ARRAY(newPoli);
    CC_INCREMENT_GL_DRAWS(1);
}
/**
 *  init opens and parses the raw file "filename".
 * .raw files consist of lines as such:
 * f1 f2 f3 f4 f5 f6 f7 f8 f9
 *  These are all floats, where each triplet specifies one vertice of the triangle (to be read as:
 * v1: (f1, f2, f3); v2: (f4, f5, f6); v3: (f7, f8, f9)
 *  init populates class variable vertices with this information
 */
int
rawReader::init(const char* filename){
	std::string str = "" ; 
	
	plint = true;

	// open .raw file
	std::cout << "Reading .raw file " << filename << std::endl;
    std::ifstream in ; 
    in.open(filename) ; 
    if (!in.is_open()) {
		std::cerr << "Unable to open file " << filename << "\n" ; 
		return 1 ;
	}

	// parse .raw file
	while(in){
		getline(in, str);

		if(str.empty()){
			// do nothing
		} // read and store vertices
		else{
			float x1,y1,z1;
			float x2,y2,z2;
			float x3,y3,z3;
			sscanf(str.c_str(), "%f %f %f %f %f %f %f %f %f", &x1, &y1, &z1, &x2, &y2, &z2, &x3, &y3, &z3);
			vec3 vertex1(x1,y1,z1);
			vec3 vertex2(x2,y2,z2);
			vec3 vertex3(x3,y3,z3);
			vertices.push_back(vertex1);
			vertices.push_back(vertex2);
			vertices.push_back(vertex3);
		} 
	}
	
	calculateNormals();

	std::cout << ".raw file read successful" << std::endl;
	return 0;
}
Example #21
0
bool ShaderNode::initWithVertex(const char *vert, const char *frag)
{
    CCNotificationCenter::sharedNotificationCenter()->addObserver(this,
                                                                  callfuncO_selector(ShaderNode::listenBackToForegrouScut),
                                                                  EVENT_COME_TO_FOREGROUScut,
                                                                  NULL);

    loadShaderVertex(vert, frag);

    m_time = 0;
    m_resolution = vertex2(SIZE_X, SIZE_Y);

    scheduleUpdate();

    setContentSize(CCSizeMake(SIZE_X, SIZE_Y));
    setAnchorPoint(ccp(0.5f, 0.5f));
    
    m_vertFileName = vert;
    m_fragFileName = frag;

    return true;
}
Example #22
0
std::shared_ptr<GenericDataArray<float> > MeshManager::generateNormals(
	std::shared_ptr<GenericDataArray<float> > vertices,
	std::shared_ptr<GenericDataArray<unsigned int> > indices)
{
	std::vector<glm::vec3> normalsVec(vertices->length());
	std::shared_ptr<GenericDataArray<float> > normals = std::make_shared<GenericDataArray<float> >(vertices->length());

	for (unsigned int i = 0; i < indices->length(); ++i) {
		unsigned int vertexIndex = indices->at(i, 0);
		glm::vec3 vertex1(vertices->at(vertexIndex, 0), vertices->at(vertexIndex, 1), vertices->at(vertexIndex, 2));

		vertexIndex = indices->at(i, 1);
		glm::vec3 vertex2(vertices->at(vertexIndex, 0), vertices->at(vertexIndex, 1), vertices->at(vertexIndex, 2));

		vertexIndex = indices->at(i, 2);
		glm::vec3 vertex3(vertices->at(vertexIndex, 0), vertices->at(vertexIndex, 1), vertices->at(vertexIndex, 2));

		glm::vec3 edge1 = vertex2 - vertex1;
		glm::vec3 edge2 = vertex3 - vertex1;

		glm::vec3 normal = glm::normalize(glm::cross(edge1, edge2));

		for (unsigned int j = 0; j < 3; ++j) {
			if (normalsVec.at(indices->at(i, j)) != glm::vec3()) {
				normalsVec.at(indices->at(i, j)) = glm::normalize(normalsVec.at(indices->at(i, j)) + normal);
			}
			else {
				normalsVec.at(indices->at(i, j)) = normal;
			}
		}
	}

	for (unsigned int i = 0; i < normalsVec.size(); ++i) {
		normals->at(i) = GenericDataArray<float>::value_type(&normalsVec[i][0]);
	}

	return normals;
}
Example #23
0
bool VertexPair::intersection(const VertexPair& other, FloatPoint& point) const
{
    // See: http://paulbourke.net/geometry/pointlineplane/, "Intersection point of two lines in 2 dimensions"

    const FloatSize& thisDelta = vertex2() - vertex1();
    const FloatSize& otherDelta = other.vertex2() - other.vertex1();
    float denominator = determinant(thisDelta, otherDelta);
    if (!denominator)
        return false;

    // The two line segments: "this" vertex1,vertex2 and "other" vertex1,vertex2, have been defined
    // in parametric form. Each point on the line segment is: vertex1 + u * (vertex2 - vertex1),
    // when 0 <= u <= 1. We're computing the values of u for each line at their intersection point.

    const FloatSize& vertex1Delta = vertex1() - other.vertex1();
    float uThisLine = determinant(otherDelta, vertex1Delta) / denominator;
    float uOtherLine = determinant(thisDelta, vertex1Delta) / denominator;

    if (uThisLine < 0 || uOtherLine < 0 || uThisLine > 1 || uOtherLine > 1)
        return false;

    point = vertex1() + uThisLine * thisDelta;
    return true;
}
Example #24
0
QObject *Script_Edge::other(QObject *node)
{
    return node == vertex1() ? vertex2() : vertex1();
}
Example #25
0
bool Script_Edge::is_vertex(const QObject *node) const
{
    return  vertex1() == node || vertex2() == node ;
}
void convex_decomposition_hacd::ConvexDecompResult(unsigned int hvcount,const float *hvertices,unsigned int htcount,const unsigned int *hindices)
{
   btVector3	centroid=btVector3(0,0,0);
   btVector3   convexDecompositionObjectOffset(10,0,0);

	btTriangleMesh* trimesh = new btTriangleMesh();
	m_trimeshes.push_back(trimesh);

	//calc centroid, to shift vertices around center of mass
	centroid.setValue(0,0,0);

	btAlignedObjectArray<btVector3> vertices;
	if ( 1 )
	{
		//const unsigned int *src = result.mHullIndices;
		for (unsigned int i=0; i<hvcount; i++)
		{
			btVector3 vertex(hvertices[i*3],hvertices[i*3+1],hvertices[i*3+2]);
			centroid += vertex;
		}
	}

	centroid *= 1.f/(float(hvcount) );

	if ( 1 )
	{
		//const unsigned int *src = result.mHullIndices;
		for (unsigned int i=0; i<hvcount; i++)
		{
			btVector3 vertex(hvertices[i*3],hvertices[i*3+1],hvertices[i*3+2]);
			vertex -= centroid ;
			vertices.push_back(vertex);
		}
	}

	if ( 1 )
	{
		const unsigned int *src = hindices;
		for (unsigned int i=0; i<htcount; i++)
		{
			unsigned int index0 = *src++;
			unsigned int index1 = *src++;
			unsigned int index2 = *src++;


			btVector3 vertex0(hvertices[index0*3], hvertices[index0*3+1],hvertices[index0*3+2]);
			btVector3 vertex1(hvertices[index1*3], hvertices[index1*3+1],hvertices[index1*3+2]);
			btVector3 vertex2(hvertices[index2*3], hvertices[index2*3+1],hvertices[index2*3+2]);

			vertex0 -= centroid;
			vertex1 -= centroid;
			vertex2 -= centroid;


			trimesh->addTriangle(vertex0,vertex1,vertex2);

         //added for maya
         mMergedVertices.push_back(vertex0.x()); mMergedVertices.push_back(vertex0.y()); mMergedVertices.push_back(vertex0.z());
         mMergedVertices.push_back(vertex1.x()); mMergedVertices.push_back(vertex1.y()); mMergedVertices.push_back(vertex1.z());
         mMergedVertices.push_back(vertex2.x()); mMergedVertices.push_back(vertex2.y()); mMergedVertices.push_back(vertex2.z());

			index0+=mBaseCount;
			index1+=mBaseCount;
			index2+=mBaseCount;

         mMergedIndices.push_back(index0);
         mMergedIndices.push_back(index1);
         mMergedIndices.push_back(index2);
		}
	}

	btConvexHullShape* convexShape = new btConvexHullShape(&(vertices[0].getX()),vertices.size());

	convexShape->setMargin(0.01f);
	m_convexShapes.push_back(convexShape);
	m_convexCentroids.push_back(centroid);
	mBaseCount+=hvcount; // advance the 'base index' counter.
};
void PointSet::AddControlVolume ( std::vector<glm::vec3> *allvertices )
{
    Vector3DF pos;
	Point* p;	
	int dimx=5;
	int dimy=5;
	float dimz=10;
	int ccnt=0;
	//vec3 a = myvertices. ; 
	glm::vec3 startpoint(0,0.0,-5.0);
	glm::vec3 direction(0,0,1.0);
	glm::vec3 vertex1(0,1.0,2.0);
	glm::vec3 vertex2(-1.0,-1.0,0);
	glm::vec3 vertex3(1.0,-1.0,0);
	glm::vec3 v1,v2,v3;
	int a = allvertices->size();
	double value=0;
	value=PointSet::Test_RayPolyIntersect(startpoint,direction,vertex1,vertex2,vertex3);
	int count=0;
	float var=1.0;
	//glm::vec3 *a = myvertices;
	for (float x = -5; x < 18; x += 1.0)
	{
		for (float y = -5; y <= 14; y += 1.0)
		{	
			 for (float z = -5; z <= 25; z += var )
			 {
				 /*if(z>=-5.0 && z <2.0)
					 var =1.0;
				  else if(z>=2.0 && z < 8.0)
					 var =0.70;
				   else if(z>=8.0 && z < 15.0)
					 var =0.6;
				    else if(z >= 15.0 && z <=25.0)
					 var =0.3;*/

				 count = 0 ;
				 startpoint=glm::vec3((float)x,(float)y,(float)z);

				 direction=glm::vec3(1.0,0.1,0);
				 for(int v=0 ;v < a ; v+=3)
				 {
					 //checking each vertex in the grid with all the 192 triangles of mesh
					 v1=(*allvertices)[v];
					 v2=(*allvertices)[v+1];
					 v3=(*allvertices)[v+2];
					 vertex1= vec3(v1[0],v1[1],v1[2]);
					 vertex2= vec3(v2[0],v2[1],v2[2]);
					 vertex3= vec3(v3[0],v3[1],v3[2]);
					 value=PointSet::Test_RayPolyIntersect(startpoint,direction,vertex1,vertex2,vertex3);
						if(value != -1.0)
						{
							 count++;
						}

				 }

				 //odd
				 if( count % 2 == 1)
				 {
							 //inside the mesh
						p = GetPoint ( AddPointReuse () );
						pos.Set ( x,y,z+10.0f);
						p->pos = pos;	
						p->type = 1;
						p->clr = COLORA( 1.0,0.3,0.3, 0);  ///   0.1,0.3,1.0,1.0 
						
						ccnt++;
				 }
				 //var=var-0.1;
			}
			// var = 1.0;
			 
		}

	}	

}
Example #28
0
void ShaderNode::setPosition(const CCPoint &newPosition)
{
    CCNode::setPosition(newPosition);
    CCPoint position = getPosition();
    m_center = vertex2(position.x * CC_CONTENT_SCALE_FACTOR(), position.y * CC_CONTENT_SCALE_FACTOR());
}
Example #29
0
NS_CC_BEGIN

void ccVertexLineToPolygon(DPoint *points, float stroke, ccVertex2F *vertices, unsigned int offset, unsigned int nuPoints)
{
    nuPoints += offset;
    if(nuPoints<=1) return;

    stroke *= 0.5f;

    unsigned int idx;
    unsigned int nuPointsMinus = nuPoints-1;

    for(unsigned int i = offset; i<nuPoints; i++)
    {
        idx = i*2;
        DPoint p1 = points[i];
        DPoint perpVector;

        if(i == 0)
            perpVector = ccpPerp(ccpNormalize(ccpSub(p1, points[i+1])));
        else if(i == nuPointsMinus)
            perpVector = ccpPerp(ccpNormalize(ccpSub(points[i-1], p1)));
        else
        {
            DPoint p2 = points[i+1];
            DPoint p0 = points[i-1];

            DPoint p2p1 = ccpNormalize(ccpSub(p2, p1));
            DPoint p0p1 = ccpNormalize(ccpSub(p0, p1));

            // Calculate angle between vectors
            float angle = acosf(ccpDot(p2p1, p0p1));

            if(angle < CC_DEGREES_TO_RADIANS(70))
                perpVector = ccpPerp(ccpNormalize(ccpMidpoint(p2p1, p0p1)));
            else if(angle < CC_DEGREES_TO_RADIANS(170))
                perpVector = ccpNormalize(ccpMidpoint(p2p1, p0p1));
            else
                perpVector = ccpPerp(ccpNormalize(ccpSub(p2, p0)));
        }
        perpVector = ccpMult(perpVector, stroke);

        vertices[idx] = vertex2(p1.x+perpVector.x, p1.y+perpVector.y);
        vertices[idx+1] = vertex2(p1.x-perpVector.x, p1.y-perpVector.y);

    }

    // Validate vertexes
    offset = (offset==0) ? 0 : offset-1;
    for(unsigned int i = offset; i<nuPointsMinus; i++)
    {
        idx = i*2;
        const unsigned int idx1 = idx+2;

        ccVertex2F p1 = vertices[idx];
        ccVertex2F p2 = vertices[idx+1];
        ccVertex2F p3 = vertices[idx1];
        ccVertex2F p4 = vertices[idx1+1];

        float s;
        //BOOL fixVertex = !ccpLineIntersect(DPoint(p1.x, p1.y), DPoint(p4.x, p4.y), DPoint(p2.x, p2.y), DPoint(p3.x, p3.y), &s, &t);
        bool fixVertex = !ccVertexLineIntersect(p1.x, p1.y, p4.x, p4.y, p2.x, p2.y, p3.x, p3.y, &s);
        if(!fixVertex)
            if (s<0.0f || s>1.0f)
                fixVertex = true;

        if(fixVertex)
        {
            vertices[idx1] = p4;
            vertices[idx1+1] = p3;
        }
    }
}
Example #30
0
void TriangleWindow::generateTerrain()
{
    float scale = .2f;

    GLfloat y1;
    GLfloat y2;
    GLfloat y3;
    GLfloat y4;

    if (QFile::exists(":/heightmap-2.png")) {
        if(!m_image.load(":/heightmap-2.png"))
        {
            std::cout << "image non chargé ";
            exit(0);
        }
    }
    else
    {
        std::cout << "image not found ";
    }

    for(int x = 0; x < m_image.width() - 1; x++)
    {
        for(int z = 0; z < m_image.height() - 1; z++)
        {
            unsigned char* line = m_image.scanLine(z);
            unsigned char* line2 = m_image.scanLine(z+1);
            y1 = (((GLfloat)line[x*4])/255)*20;
            y2 = (((GLfloat)line[(x*4)+4])/255)*20;
            y3 = (((GLfloat)line2[(x*4)])/255)*20;
            y4 = (((GLfloat)line2[(x*4)+4])/255)*20;

            _texture.push_back(x/(m_image.width()*1.0)); _texture.push_back(z/(m_image.height()*1.0));
            _texture.push_back((x+1)/(m_image.width()*1.0)); _texture.push_back(z/(m_image.height()*1.0));
            _texture.push_back(x/(m_image.width()*1.0)); _texture.push_back((z+1)/(m_image.height()*1.0));

            _texture.push_back((x+1)/(m_image.width()*1.0)); _texture.push_back(z/(m_image.height()*1.0));
            _texture.push_back(x/(m_image.width()*1.0)); _texture.push_back((z+1)/(m_image.height()*1.0));
            _texture.push_back((x+1)/(m_image.width()*1.0)); _texture.push_back((z+1)/(m_image.height()*1.0));

            QVector3D vertex1(x*scale, y1, z*scale);
            _map.push_back(vertex1);
            _color.push_back(displayColor(y1));

            QVector3D vertex2((x+1)*scale, y2, z*scale);
            _map.push_back(vertex2);
            _color.push_back(displayColor(y2));

            QVector3D vertex3(x*scale, y3, (z+1)*scale);
            _map.push_back(vertex3);
            _color.push_back(displayColor(y3));

            QVector3D normal = QVector3D::normal(vertex1, vertex2, vertex3);
            _normal.push_back(normal);

            normal = QVector3D::normal(vertex2, vertex3, vertex1);
            _normal.push_back(normal);

            normal = QVector3D::normal(vertex3, vertex1, vertex2);
            _normal.push_back(normal);

            _map.push_back(vertex2);
            _color.push_back(displayColor(y2));

            QVector3D vertex4((x+1)*scale, y4, (z+1)*scale);
            _map.push_back(vertex4);
            _color.push_back(displayColor(y4));

            _map.push_back(vertex3);
            _color.push_back(displayColor(y3));

            normal = QVector3D::normal(vertex2, vertex4, vertex3);
            _normal.push_back(normal);

            normal = QVector3D::normal(vertex4, vertex3, vertex2);
            _normal.push_back(normal);

            normal = QVector3D::normal(vertex3, vertex2, vertex4);
            _normal.push_back(normal);
        }
    }
}