Beispiel #1
0
VEF::VEF(QString *name)
{
    /* all the computation takes place here
     */

    m_nbThreads = 4;
    m_manifold = true;
    FileParser parser(this);
    parser.parseFile(name);    

    /* holes not computed */
    m_nbHoles = -1;
    m_connectedComponents = 0;


    /* fill the edge vector and compute neighborhood */
    edgeReconstruct(0);

    if (!computeFacesNormals(0))
        std::cerr<<"No normals have been computed."<<std::endl;

    if (!computeVerticesNormals(0))
        std::cerr<<"No normals have been computed."<<std::endl;

    /* create the bounding box */
    createBoundingBox();

    /* create the voxel grid */
    m_voxGrid = new VoxGrid(&m_boundingBox, this);
    computeConnectedComponents();
}
Beispiel #2
0
void Enemy::skillCallBackAction(Node* pSender)
{
	Hero* p_hero = global->hero;
	Rect attackReck = m_hitBox.actual;//怪物攻击区域
	Rect hurtReck = p_hero->getBodyBox().actual;


	if (attackReck.intersectsRect(hurtReck))
	{
		p_hero->setAllowMove(false);
		int damage = this->getDamageStrength();

		if (getMoveDirection().x > 0)
		{
			p_hero->setFlippedX(true);
			p_hero->runHurtFlyRightAction();
		}
		else
		{
			p_hero->setFlippedX(false);
			p_hero->runHurtFlyLeftAction();
		}
		//连击数归零
		p_hero->hitCount = 0;
		p_hero->setCurtLifeValue(p_hero->getCurtLifeValue() - damage);
	}
	if (p_hero->getCurtLifeValue() <= 0)
	{
		p_hero->runDeadAction();
		p_hero->setBodyBox(createBoundingBox(Vec2::ZERO, Size::ZERO));
	}
}
Beispiel #3
0
Branch::Branch(const std::string& name, int level, const double thickness, const double length, 
               double upDist, double upAngle, double zAngle)
  : SceneNode(name), m_boundingBox()
{
  double branchLength = length;
  if (level == 1) {
    branchLength /= 1.5;
  }

  createLeaves(level, thickness, length);

  createGeometryNode(branchLength, thickness, upDist, upAngle, zAngle);
  spawnSubBranches(level, branchLength, thickness);

  createBoundingBox();
}
Beispiel #4
0
 shared_ptr<TexturedMesh> GeometryFactory::getPrimitive(String name)
 {
     auto it = primitive_map.find(name);
     
     if(it != primitive_map.end())
         return it->second;
     
     // else create
     if (name == "plane")
         primitive_map[name] = createPlane();
     else if (name == "boundingBox")
         primitive_map[name] = createBoundingBox();
     else if (name == "box")
         primitive_map[name] = createBox();
     
     it = primitive_map.find(name);
     assert(it != primitive_map.end());
     return it->second;
 }
Beispiel #5
0
wall::wall(GLfloat width, GLfloat height, GLuint text){

	name = "wall" ;
	texture = text ;

	int i ;
	for(i = 0 ; i < 16; ++i){ //split for better texturing
		
		points.push_back(vec4(width * i/16, 0.0, 0.0, 1.0));  // Point 1 (bottom-left)
		points.push_back(vec4(width * (i + 1)/16, 0, 0, 1.0));  // Point 1 (bottom-right)
		points.push_back(vec4(width * (i + 1)/16, height, 0, 1.0));  // Point 1 (top-right)
		points.push_back(vec4(width * i/16, height, 0, 1.0));  // Point 1 (top-left)
		
		normal = vec3(0.0, 0.0, 1.0) ;
		
		createBoundingBox() ;
	}

	
};
Beispiel #6
0
void Enemy::attackCallBackAction(Node* pSender)
{
    Hero* t_hero = global->hero;
    Rect attackRect = m_hitBox.actual;
    Rect hurtRect = t_hero->getBodyBox().actual;
    //敌人攻击英雄
    if (attackRect.intersectsRect(hurtRect)) {
        t_hero->setAllowMove(false);
        int damage = this->getDamageStrenth();
        t_hero->runHurtAction();
        t_hero->setCurtLifeValue(t_hero->getCurtLifeValue() - damage);
    }
    if (t_hero->getCurtLifeValue() <= 0) {
        t_hero->runDeadAction();
//        m_attackArea = 0;
        t_hero->setBodyBox(createBoundingBox(Vec2::ZERO, Size::ZERO));
       
        t_hero->setPosition(Point(-10000, -10000));
    }
}
Beispiel #7
0
Branch::Branch(const std::string& name, int level, const double thickness, const double length)
  : SceneNode(name), m_boundingBox()
{
  createLeaves(level, thickness, length);

  double upDist = 0.0;
  double upAngle = 0.0;
  double zAngle = 0.0;
  if (level != 0) {
    upDist = rand(1.0/3.0, 2.0/3.0, prevLength(length, level));

    upAngle = rand(1.0/3.0, 8.0/9.0, 90.0);
    zAngle = rand(0.0, 1.0, 360.0);
  }

  createGeometryNode(length, thickness, upDist, upAngle, zAngle);
  spawnSubBranches(level, length, thickness);

  createBoundingBox();
}
void Rasterization( GzRender * render, GzCoord * vertex, GzCoord * normXY)
{
	float temp1=0.0,temp2=0.0,temp3=0.0,temp4=0.0,m=0.0,midPoint=0.0;
	triEdge tEdges[3];
	int flag =0;
	int defVertex[3]={0,1,2};
	
float xDiffE0,yDiffE0,zDiffE0,xDiffE1,yDiffE1,zDiffE1,xDiffE2,yDiffE2,zDiffE2;
float A,B,C,D;
float a0,b0,c0,a1,b1,c1,a2,b2,c2;
float lowerX=99999999.0,lowerY=99999999.0,upperX=0.0,upperY=0.0;
float v0,v1,v2,v;
GzIntensity r,g,b,a;
GzDepth z;
	//First sort the vertices by Y if Y is same sort it according to X

sortTriangle(vertex,&defVertex[0]);

	//Assign edge in CCW
	if(vertex[0][1]== vertex[1][1])
	{
		tEdges[0].x1= vertex[1][0];
		tEdges[0].x2= vertex[0][0];
		tEdges[0].y1= vertex[1][1];
		tEdges[0].y2= vertex[0][1];
		tEdges[0].z1= vertex[1][2];
		tEdges[0].z2= vertex[0][2];
		

		tEdges[1].x1= vertex[0][0];
		tEdges[1].x2= vertex[2][0];
		tEdges[1].y1= vertex[0][1];
		tEdges[1].y2= vertex[2][1];
		tEdges[1].z1= vertex[0][2];
		tEdges[1].z2= vertex[2][2];
		

		tEdges[2].x1= vertex[2][0];
		tEdges[2].x2= vertex[1][0];
		tEdges[2].y1= vertex[2][1];
		tEdges[2].y2= vertex[1][1];
		tEdges[2].z1= vertex[2][2];
		tEdges[2].z2= vertex[1][2];

		tEdges[0].tl= defVertex[1];		
		tEdges[0].hd= defVertex[0];
		tEdges[1].tl= defVertex[0];		
		tEdges[1].hd= defVertex[2];
		tEdges[2].tl= defVertex[2];		
		tEdges[2].hd= defVertex[1];

		
	}


	if(vertex[1][1]== vertex[2][1])
	{

		
		tEdges[0].x1= vertex[0][0];
		tEdges[0].x2= vertex[1][0];
		tEdges[0].y1= vertex[0][1];
		tEdges[0].y2= vertex[1][1];
		tEdges[0].z1= vertex[0][2];
		tEdges[0].z2= vertex[1][2];
		


		tEdges[1].x1= vertex[1][0];
		tEdges[1].x2= vertex[2][0];
		tEdges[1].y1= vertex[1][1];
		tEdges[1].y2= vertex[2][1];
		tEdges[1].z1= vertex[1][2];
		tEdges[1].z2= vertex[2][2];
		


		tEdges[2].x1= vertex[2][0];
		tEdges[2].x2= vertex[0][0];
		tEdges[2].y1= vertex[2][1];
		tEdges[2].y2= vertex[0][1];
		tEdges[2].z1= vertex[2][2];
		tEdges[2].z2= vertex[0][2];

		tEdges[0].tl= defVertex[0];	
		tEdges[0].hd= defVertex[1];
		tEdges[1].tl= defVertex[1];		
		tEdges[1].hd= defVertex[2];
		tEdges[2].tl= defVertex[2];	
		tEdges[2].hd= defVertex[0];

		
	}

	else
	{
		
	float slope=0.0;
	slope= ( vertex[2][1] - vertex[0][1] ) / ( vertex[2][0] - vertex[0][0] );
		midPoint=vertex[0][0]+( ( vertex[1][1] - vertex[0][1] ) / slope )  ;
		if( vertex[1][0]< midPoint )
		{
			tEdges[0].x1= vertex[0][0];
			tEdges[0].x2= vertex[1][0];
			tEdges[0].y1= vertex[0][1];
			tEdges[0].y2= vertex[1][1];
			tEdges[0].z1= vertex[0][2];
			tEdges[0].z2= vertex[1][2];
			


			tEdges[1].x1= vertex[1][0];
			tEdges[1].x2= vertex[2][0];
			tEdges[1].y1= vertex[1][1];
			tEdges[1].y2= vertex[2][1];
			tEdges[1].z1= vertex[1][2];
			tEdges[1].z2= vertex[2][2];
			


			tEdges[2].x1= vertex[2][0];
			tEdges[2].x2= vertex[0][0];
			tEdges[2].y1= vertex[2][1];
			tEdges[2].y2= vertex[0][1];
			tEdges[2].z1= vertex[2][2];
			tEdges[2].z2= vertex[0][2];

			tEdges[0].tl= defVertex[0];			
			tEdges[0].hd= defVertex[1];
			tEdges[1].tl= defVertex[1];			
			tEdges[1].hd= defVertex[2];
			tEdges[2].tl= defVertex[2];			
			tEdges[2].hd= defVertex[0];
		}

		else if( vertex[1][0]>midPoint  )
		{
			tEdges[0].x1= vertex[0][0];
			tEdges[0].x2= vertex[2][0];
			tEdges[0].y1= vertex[0][1];
			tEdges[0].y2= vertex[2][1];
			tEdges[0].z1= vertex[0][2];
			tEdges[0].z2= vertex[2][2];
			


			tEdges[1].x1= vertex[2][0];
			tEdges[1].x2= vertex[1][0];
			tEdges[1].y1= vertex[2][1];
			tEdges[1].y2= vertex[1][1];
			tEdges[1].z1= vertex[2][2];
			tEdges[1].z2= vertex[1][2];
			


			tEdges[2].x1= vertex[1][0];
			tEdges[2].x2= vertex[0][0];
			tEdges[2].y1= vertex[1][1];
			tEdges[2].y2= vertex[0][1];
			tEdges[2].z1= vertex[1][2];
			tEdges[2].z2= vertex[0][2];

			tEdges[0].tl= defVertex[0];			
			tEdges[0].hd= defVertex[2];
			tEdges[1].tl= defVertex[2];			
			tEdges[1].hd= defVertex[1];
			tEdges[2].tl= defVertex[1];			
			tEdges[2].hd= defVertex[0];

		}

		
	}

	
	xDiffE0=tEdges[0].x2 - tEdges[0].x1;
	xDiffE1= tEdges[1].x2 - tEdges[1].x1;
	xDiffE2=tEdges[2].x2 - tEdges[2].x1;

	yDiffE0= tEdges[0].y2 - tEdges[0].y1;
	yDiffE1=tEdges[1].y2 - tEdges[1].y1;
	yDiffE2=tEdges[2].y2 - tEdges[2].y1;

	zDiffE0= tEdges[0].z2 - tEdges[0].z1;
	zDiffE1= tEdges[1].z2 - tEdges[1].z1;
	zDiffE2=tEdges[2].z2-tEdges[1].z1;
	
	//Find ABC value for the line equation
	a0 = yDiffE0;
	a1 = yDiffE1;
	a2 =yDiffE2;

	 b0 = -xDiffE0;
	 b1 = -xDiffE1;
	 b2 = -xDiffE2;

	 c0 = xDiffE0 * tEdges[0].y1  - yDiffE0 * tEdges[0].x1 ;	
	 c1 = xDiffE1 * tEdges[1].y1 - yDiffE1 * tEdges[1].x1 ;	
	 c2 =  xDiffE2* tEdges[2].y1  - yDiffE2 * tEdges[2].x1 ;

	 //Find Ax+By+Cz+d=0
	 float temp=0.0;
	A = yDiffE0 * zDiffE1 - zDiffE0 * yDiffE1;
	B = - xDiffE0 * zDiffE1 + zDiffE0 * xDiffE1 ;
	C = xDiffE0 * yDiffE1 - yDiffE0 * xDiffE1;
	temp=A* vertex[0][0] + B* vertex[0][1] + C* vertex[0][2];
	D=-temp;

	//Find the bounding box for the triangle
	
	//construct bounding box
	createBoundingBox(vertex,&lowerX,&lowerY,&upperX,&upperY);
	

	 if(render->interp_mode== GZ_NORMALS)
	{
		getPlaneCoeff(tEdges,normXY);
	}
	else if(render->interp_mode== GZ_COLOR)
	{
		GzColor c[3];
		memset(c,0,sizeof(GzColor)*3);

		for( int p =0; p <3; p++ )
		doShading(render,c[p],normXY[p]);
		
		getPlaneCoeff(tEdges,c);

	}
	

	//Check for each pixel within the bounding box whether it lies in the triangle
	for(int i=lowerY;i<= upperY; i++ )
	{
		for(int j=lowerX;j<= upperX; j++ )
		{
			GzIntensity r, g, b, a;
			GzDepth z;

			v =-(A*j+B*i+D)/C;

			 v0 = a0 * j + b0 * i + c0;
			 v1 = a1 * j + b1 * i + c1;
			 v2 = a2 * j + b2 * i + c2;
			

			if(v<0||v0<0||v1<0||v2<0)
			continue;

			
			GzGetDisplay( render->display, j, i, &r, &g, &b, &a, &z );
			//Check with prev Z vaule
			GzColor q;

			
				
				 for(int k=0;k<3;k++)
				q[k] = -( pCof[k].planeA * j + pCof[k].planeB * i  + pCof[k].planeD ) / pCof[k].planeC;
				

				if(render->interp_mode == GZ_FLAT)
				{
					for(int k=0;k<3;k++)
					q[k] = render->flatcolor[k];
						if( v < z || z==0)
					GzPutDisplay(render->display,j,i,ctoi(q[0]),ctoi(q[1]),ctoi(q[2]),a,(GzDepth )v);
				}
				if(render->interp_mode == GZ_COLOR)
				{
						if( v < z || z==0)
					GzPutDisplay(render->display,j,i,ctoi(q[0]),ctoi(q[1]),ctoi(q[2]),a,(GzDepth )v);
				}
				else if(render->interp_mode == GZ_NORMALS)
				{
					GzColor c;
					memset(c,0,sizeof(GzColor));
					getNormal(q);
					doShading(render,c,q);
						if( v < z || z==0)
					GzPutDisplay(render->display,j,i,ctoi(c[0]),ctoi(c[1]),ctoi(c[2]),a,(GzDepth )v);
				}
				

			
		} 
	} 

}
Beispiel #9
0
void Hero::normalAttackCallBackAction(Node* pSender)
{
	/*
	//play sound effect
	if (this->currActionState == ACTION_STATE_NOMAL_ATTACK_A || 
		this->currActionState == ACTION_STATE_NOMAL_ATTACK_B ||
		this->currActionState == ACTION_STATE_NOMAL_ATTACK_C ||
		this->currActionState == ACTION_STATE_NOMAL_ATTACK_D )
		CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("Sound/BladeBig2.mp3");
	*/

	__Array *pEnemies;
	if (global->sceneInfoVector[global->sceneIndex]->bossFormatStr == NULL)
	{
		pEnemies = global->enemies;
	}
	else
	{
		pEnemies = global->bosses;
	}

	Ref *enemyObj = NULL;
	Size visibleSize = Director::getInstance()->getVisibleSize();

	//判断是否可以放大招
	if (this->getCurrMagicPoint() >= 100)
	{
		addUltimateSkill();
		
		this->setCurrMagicPoint(0.0f);
	}

	CCARRAY_FOREACH(pEnemies, enemyObj)
	{
		Enemy *pEnemy = (Enemy*)enemyObj;
		if (fabsf(this->getPosition().y - pEnemy->getPosition().y < 20))
		{
			Rect attackRect = m_hitBox.actual;//英雄攻击区域
			Rect hurtRect = pEnemy->getBodyBox().actual;//怪物受伤区域
			if (attackRect.intersectsRect(hurtRect))
			{
				pEnemy->setAllowMove(false);
				//此处可处理怪物被攻击后的后续,产生伤害数字
				int damage = random(this->getDamageStrength()*0.7, this->getDamageStrength()*1.3);
				hitCounter();
				Vec2 point = pEnemy->getBodyBox().actual.origin;
				damageDisplay(damage, Vec2(point.x , point.y + 80));
				pEnemy->runHurtAction();
				enemyBloodDisplay(Vec2(point.x-10,point.y-10));
				

				if (this->getCurrActionState() == ACTION_STATE_NOMAL_ATTACK_C || this->getCurrActionState() == ACTION_STATE_NOMAL_ATTACK_D)
				{
					if (getRoleDirection())
					{
						pEnemy->setFlippedX(false);
						pEnemy->runHurtFlyLeftAction();
					}
					else
					{
						pEnemy->setFlippedX(true);
						pEnemy->runHurtFlyRightAction();
					}
				}
				//pEnemy->runHurtFlyLeftAction();

				if (hitCount > 1)
				{
					combosDisplay(hitCount, Vec2(visibleSize.width *0.15, visibleSize.height * 0.75));
				}

				
				
				pEnemy->setCurtLifeValue(pEnemy->getCurtLifeValue() - damage);
				if (pEnemy->getCurtLifeValue() <= 0)
				{
					pEnemy->runDeadAction();
					pEnemy->setBodyBox(createBoundingBox(Vec2::ZERO, Size::ZERO));
					pEnemy->setOpacity(124);

					float temp = this->getPosition().x - visibleSize.width / 2;
					float destX = (temp > 0) ? temp : 0;
					addDeadFire(Vec2(destX,visibleSize.height) ,pEnemy->getPosition());
					pEnemy->setVisible(false);
					
				}
			}
		}
	}
AxisAlignedCutPlane::AxisAlignedCutPlane()
    : Processor()
    , volume_("volume")
    , imageInport_("imageInport_")
    , outport_("outport")
    , xSlide_("x", "X Slide")
    , ySlide_("y", "Y Slide")
    , zSlide_("z", "Z Slide")
    , disableTF_("disableTF", "Disable transfer function", false,
                 InvalidationLevel::InvalidResources)
    , tf_("transferfunction", "Transfer function", TransferFunction(), &volume_)
    , sliceShader_("geometryrendering.vert", "axisalignedcutplaneslice.frag", false)
    , boundingBoxShader_("geometryrendering.vert", "axisalignedcutplaneboundingbox.frag")
    , showBoundingBox_("boundingBox", "Show Bounding Box", true)
    , boundingBoxColor_("boundingBoxColor", "Bounding Box Color", vec4(0.0f, 0.0f, 0.0f, 1.0f))
	, renderPointSize_("renderPointSize", "Point Size", 1.0f, 0.001f, 15.0f, 0.001f)
	, renderLineWidth_("renderLineWidth", "Line Width", 1.0f, 0.001f, 15.0f, 0.001f)
    , nearestInterpolation_("nearestInterpolation", "Use nearest neighbor interpolation", false)
    , camera_("camera", "Camera")
    , trackball_(&camera_) {
    addPort(volume_);
    addPort(imageInport_);
    addPort(outport_);

    addProperty(xSlide_);
    addProperty(ySlide_);
    addProperty(zSlide_);
    addProperty(disableTF_);
    addProperty(tf_);
    addProperty(showBoundingBox_);
	addProperty(boundingBoxColor_);
	addProperty(renderPointSize_);
	addProperty(renderLineWidth_);

    addProperty(camera_);
    addProperty(trackball_);

    imageInport_.setOptional(true);

    tf_.get().clearPoints();
    tf_.get().addPoint(vec2(0.0f, 1.0f), vec4(0.0f, 0.0f, 0.0f, 1.0f));
    tf_.get().addPoint(vec2(1.0f, 1.0f), vec4(1.0f, 1.0f, 1.0f, 1.0f));

    tf_.setCurrentStateAsDefault();

    xSlide_.onChange([&]() {
        if (volume_.hasData()) xSlide_.createDrawer(volume_.getData());
    });
    ySlide_.onChange([&]() {
        if (volume_.hasData()) ySlide_.createDrawer(volume_.getData());
    });
    zSlide_.onChange([&]() {
        if (volume_.hasData()) zSlide_.createDrawer(volume_.getData());
    });

    volume_.onChange([&]() {
        if (!volume_.hasData()) return;
        auto vol = volume_.getData();
        xSlide_.onVolumeChange(vol);
        ySlide_.onVolumeChange(vol);
        zSlide_.onVolumeChange(vol);
        if (!boundingBoxMesh_) {
            createBoundingBox();
        }
        boundingBoxMesh_->setModelMatrix(vol->getModelMatrix());
        boundingBoxMesh_->setWorldMatrix(vol->getWorldMatrix());
    });

    boundingBoxColor_.setSemantics(PropertySemantics::Color);

    setAllPropertiesCurrentStateAsDefault();

    createBoundingBox();

}