Example #1
0
void createSceneRayFilter()
{
	int idA = createBrick(PfxVector3(0.0f,2.0f,0.0f),PfxQuat::identity(),PfxVector3(5.0f,0.25f,5.0f),1.0f);
	int idB = createBrick(PfxVector3(0.0f,4.0f,0.0f),PfxQuat::identity(),PfxVector3(5.0f,0.25f,5.0f),1.0f);
	int idC = createBrick(PfxVector3(0.0f,6.0f,0.0f),PfxQuat::identity(),PfxVector3(5.0f,0.25f,5.0f),1.0f);
	int idD = createBrick(PfxVector3(0.0f,8.0f,0.0f),PfxQuat::identity(),PfxVector3(5.0f,0.25f,5.0f),1.0f);

	states[idA].setMotionType(kPfxMotionTypeFixed);
	states[idB].setMotionType(kPfxMotionTypeFixed);
	states[idC].setMotionType(kPfxMotionTypeFixed);
	states[idD].setMotionType(kPfxMotionTypeFixed);

	states[idA].setContactFilterSelf(0x01);
	states[idB].setContactFilterSelf(0x02);
	states[idC].setContactFilterSelf(0x04);
	states[idD].setContactFilterSelf(0x08);

	numRays = 5;
	for(int i=0;i<numRays;i++) {
		rayInputs[i].reset();
		rayInputs[i].m_startPosition = PfxVector3(-2.0f+i,10.0f,0.0f);
		rayInputs[i].m_direction = PfxVector3(0.0f,-10.0f,2.0f);
		rayInputs[i].m_contactFilterTarget = 1<<i;
	}
}
void createPyramid(const PfxVector3 &offsetPosition,int stackSize,const PfxVector3 &boxSize)
{
	PfxFloat space = 0.0001f;
	PfxVector3 pos(0.0f, boxSize[1], 0.0f);

	PfxFloat diffX = boxSize[0] * 1.02f;
	PfxFloat diffY = boxSize[1] * 1.02f;
	PfxFloat diffZ = boxSize[2] * 1.02f;

	PfxFloat offsetX = -stackSize * (diffX * 2.0f + space) * 0.5f;
	PfxFloat offsetZ = -stackSize * (diffZ * 2.0f + space) * 0.5f;
	while(stackSize) {
		for(int j=0;j<stackSize;j++) {
			pos[2] = offsetZ + (PfxFloat)j * (diffZ * 2.0f + space);
			for(int i=0;i<stackSize;i++) {
				pos[0] = offsetX + (PfxFloat)i * (diffX * 2.0f + space);
				createBrick(numRigidBodies++,offsetPosition+pos,PfxQuat::identity(),boxSize,1.0f);
			}
		}
		offsetX += diffX;
		offsetZ += diffZ;
		pos[1] += (diffY * 2.0f + space);
		stackSize--;
	}
}
Example #3
0
PtrSetPtrObj createSOMBricks(float meshSize){
	PtrSetPtrObj results(new SetPtrObj);
	int Location[3];
	int Dimensions[3];
	for(int i=0;i<20;i++){
		for(int j=0;j<20;j++){
			results->insert(createBrick(i,j,meshSize));
		}
	}
	return results;

}
Example #4
0
void createStack(const PfxVector3 &offsetPosition,int stackSize,const PfxVector3 &boxSize)
{
	PfxFloat bodyMass = 0.5f;
    
	PfxFloat diffX = boxSize[0] * 1.0f;
	PfxFloat diffY = boxSize[1] * 1.0f;
	PfxFloat diffZ = boxSize[2] * 1.0f;
    
	PfxVector3 pos(0.0f, diffY, 0.0f);
    
    for(int i=0;i<stackSize;i++) {
        createBrick(numRigidBodies++,offsetPosition+pos,PfxQuat::identity(),boxSize,bodyMass);
    	pos[1] += (diffY * 2.0f);
    }
	
}
void createSceneJoints()
{
	
	const int n = 10;

	int startId = numRigidBodies;

	PfxVector3 boxSize(1.0f);
	PfxFloat boxMass = 1.0f;

	for(int i=0;i<n;i++) {
		createBrick(numRigidBodies++,PfxVector3(0,3.0f+i*2.5f*boxSize[1],0),PfxQuat::identity(),boxSize,boxMass);
	}

	for(int i=startId;i<startId+n;i++) {
		PfxRigidState &stateA = states[i];
		PfxRigidState &stateB = states[(i+1)%numRigidBodies];
		PfxVector3 anchor;
		if(i == numRigidBodies-1) {
			anchor = stateA.getPosition() + PfxVector3(0,boxSize[1],0);
		}
		else {
			anchor = ( stateA.getPosition() + stateB.getPosition() ) * 0.5f;
		}

		PfxSwingTwistJointInitParam jparam;
		jparam.anchorPoint = anchor;
		jparam.twistAxis = PfxVector3(0,1,0);

		pfxInitializeSwingTwistJoint(joints[numJoints],stateA,stateB,jparam);
		joints[numJoints].m_constraints[4].m_damping = 0.1f;
		joints[numJoints].m_constraints[5].m_damping = 0.1f;


		SCE_PFX_ASSERT(numJoints<NUM_JOINTS);
		numJoints++;
	}

	states[startId].setLinearVelocity(PfxVector3(0,0,5));
	states[startId].setLinearDamping(0.95f);
	states[startId].setAngularDamping(0.95f);
	
}
void createTowerCircle(const PfxVector3 &offsetPosition,int stackSize,int rotSize,const PfxVector3 &boxSize)
{
	PfxFloat radius = 1.3f * rotSize * boxSize[0] / SCE_PFX_PI;

	// create active boxes
	PfxQuat rotY = PfxQuat::identity();
	PfxFloat posY = boxSize[1];

	for(int i=0;i<stackSize;i++) {
		for(int j=0;j<rotSize;j++) {
			createBrick(numRigidBodies++,offsetPosition+rotate(rotY,PfxVector3(0.0f , posY, radius)),rotY,boxSize,0.5f);

			rotY *= PfxQuat::rotationY(SCE_PFX_PI/(rotSize*0.5f));
		}

		posY += boxSize[1] * 2.0f;
		rotY *= PfxQuat::rotationY(SCE_PFX_PI/(PfxFloat)rotSize);
	}
}
Example #7
0
void createSceneFalling()
{
	int size = 6;
	const float cubeSize = 1.0f;
	float spacing = cubeSize * 5.0f;
	PfxVector3 pos(0.0f, cubeSize * 2, 0.0f);
	float offset = -size * (cubeSize * 2.0f + spacing) * 0.5f;

	for(int k=0;k<5;k++) {
		for(int j=0;j<size;j++) {
			pos[2] = offset + (float)j * (cubeSize * 2.0f + spacing);
			for(int i=0;i<size;i++) {
				pos[0] = offset + (float)i * (cubeSize * 2.0f + spacing);
				createBrick(pos,PfxQuat::identity(),PfxVector3(cubeSize),1.0f);
			}
		}
		offset -= 0.05f * spacing * (size-1);
		spacing *= 1.01f;
		pos[1] += (cubeSize * 2.0f + spacing);
	}
}
void createWall(const PfxVector3 &offsetPosition,int stackSize,const PfxVector3 &boxSize)
{
	PfxFloat bodyMass = 0.5f;

	PfxFloat diffX = boxSize[0] * 1.02f;
	PfxFloat diffY = boxSize[1] * 1.02f;
	PfxFloat diffZ = boxSize[2] * 1.02f;

	PfxFloat offset = -stackSize * (diffZ * 2.0f) * 0.5f;
	PfxVector3 pos(0.0f, diffY, 0.0f);

	while(stackSize) {
		for(int i=0;i<stackSize;i++) {
			pos[2] = offset + (PfxFloat)i * (diffZ * 2.0f);
		
			createBrick(numRigidBodies++,offsetPosition+pos,PfxQuat::identity(),boxSize,bodyMass);
		}
		offset += diffZ;
		pos[1] += (diffY * 2.0f);
		stackSize--;
	}
}
Example #9
0
/*---------------------------------------------------------------------*/
static int
pkteng_link(lua_State *L)
{
	TRACE_LUA_FUNC_START();
	PktEngine_Intf *pe = check_pkteng(L, 1);
	Linker_Intf *linker;
	Brick *first_brick;
	int nargs = lua_gettop(L);
	int i;

	/* check if args2 is user-data */
	luaL_checktype(L, 2, LUA_TUSERDATA);
	
	/* Retrieve linker data */
	linker = (Linker_Intf *)luaL_optudata(L, 2);

	/* set values as default */
	pe->batch = DEFAULT_BATCH_SIZE;
	pe->qid = -1;

	/* if 3rd arg is passed, fill it with batch size */
	if (nargs >= 3)
		pe->batch = luaL_checkint(L, 3);
	/* if 4th arg is passed, fill it with qid */
	if (nargs >= 4)
		pe->qid = luaL_checkint(L, 4);
	lua_settop(L, 1);

	TRACE_DEBUG_LOG("Engine info so far...:\n"
			"\tName: %s\n"
			"\tCpu: %d\n"
			"\tBatch: %d\n"
			"\tQid: %d\n",
			pe->eng_name,
			pe->cpu,
			pe->batch,
			pe->qid);
	
	for (i = 0; i < linker->input_count; i++) {
		/* link the source(s) with the packet engine */
		pktengine_link_iface((uint8_t *)pe->eng_name, 
				     (uint8_t *)linker->input_link[i], 
				     pe->batch, pe->qid);
		TRACE_LOG("Linking %s with link %s with batch size: %d and qid: %d\n",
			  pe->eng_name, linker->input_link[i], pe->batch, pe->qid);
	}
	first_brick = createBrick(linker->type);
	if (first_brick == NULL) {
		TRACE_LUA_FUNC_END();
		return 1;
	}

	first_brick->eng = engine_find((unsigned char *)pe->eng_name);
	first_brick->elib->init(first_brick, linker);
	if (first_brick->eng == NULL) {
		TRACE_LOG("Could not find engine with name: %s\n",
			  pe->eng_name);
		TRACE_LUA_FUNC_END();
		free(first_brick);
		return 1;
	}
	first_brick->elib->link(first_brick, linker);
	
	/* if there are pipelines, link them as well */
	while (linker->next_linker != NULL) {
		linker = linker->next_linker;
		first_brick->elib->link(first_brick, linker); 
	}

	TRACE_LUA_FUNC_END();
	return 1;
}
Example #10
0
void Model::brickOrganisation()
{
    for(int i = 0; i<background->size(); i++){
        if(background->at(i)->getRect().x() < - background->at(i)->getRect().width() + 2){
            background->removeAt(i);
            Background* b = new Background(1000,0);
            background->append(b);
        }
    }
    if(compteur->last()->getRect().x()<((NbrBrickVisible)*brickSize)){
        Brick *b=new Brick(compteur->last()->getRect().x()+brickSize,Hauteur+brickSize);
        createBrick(ligne1,1,compteur->last()->getRect().x());
        createBrick(ligne2,2,compteur->last()->getRect().x());
        createBrick(ligne3,3,compteur->last()->getRect().x());
        createBrick(ligne4,4,compteur->last()->getRect().x());
        createBrick(ligne5,5,compteur->last()->getRect().x());
        createBrick(ligne6,6,compteur->last()->getRect().x());
        compteur->append(b);
        mapPosition++;
    }

    if (compteur->first()->getRect().x()<=-brickSize){
        compteur->removeAt(compteur->indexOf(compteur->first()));
    }

    for(int i = 0; i<floors->size(); i++){
        if (floors->at(i)->getRect().x()<=-brickSize || floors->at(i)->isDestroyed()){
            floors->removeAt(i);
        }
    }

    for(int i = 0; i<safes->size(); i++){
        if (safes->at(i)->getRect().x()<=-brickSize || safes->at(i)->isDestroyed()){
            safes->removeAt(i);
        }
    }

    for(int i = 0; i<golds->size(); i++){
        if (golds->at(i)->getRect().x()<=-brickSize || golds->at(i)->isDestroyed()){
            golds->removeAt(i);
        }
    }

    for(int i = 0; i<mushroom->size(); i++){
        if (mushroom->at(i)->getRect().x()<=-brickSize || mushroom->at(i)->isDestroyed()){
            mushroom->removeAt(i);
        }
    }

    for(int i = 0; i<flames->size(); i++){
        if (flames->at(i)->getRect().x()<=-brickSize || flames->at(i)->isDestroyed()){
            flames->removeAt(i);
        }
    }

    for(int i = 0; i<darkEater->size(); i++){
        if (darkEater->at(i)->getRect().x()<=-brickSize ){
            darkEater->removeAt(i);
        }
    }
}
Example #11
0
void ClampNode::createGeode(void) {
    // Remove children
    removeChildren(0, getNumChildren());
    
    // Create geode
    osg::ref_ptr<osg::Geode> geode = new osg::Geode;
    addChild(geode);
    geode->addDrawable(createBrick());

    // Distance between two plot center
    double distPlot = Lego::length_unit;

    // Get the brick
    Clamp* clamp = static_cast<Clamp*>(_lego);

    // Get clamp bounding box
    clamp->calculateBoundingBox();
    BoundingBox bb = clamp->getBoundingBox();
    // Get integer sizes
    int width = bb.getWidth();
    int length = bb.getLength();
    int height = bb.getHeight();

    // Calculate x max and y max for plots
    double xminb = -(length-2)*Lego::length_unit/2;
    double yminb = -(width-1)*Lego::length_unit/2;

    double w = (-width)*Lego::length_unit/2+Lego::height_unit/2;
    double h = (height)*Lego::height_unit/2-Lego::height_unit/2;

    // Add cylinder parts

    // Create geode
    osg::ref_ptr<osg::Geode> cylinderGeode = new osg::Geode;

    // Create drawable cylinder
    osg::Drawable* cylinderPart = makeCylinder(0, w, h, length*Lego::length_unit, Lego::height_unit/2);
    // Add drawable to geode
    cylinderGeode->addDrawable(cylinderPart);

    // Create top and bottom cylinder
    osg::Drawable* topPart = makeDisk(0, w, h, Lego::height_unit/2, length*Lego::length_unit, true);
    osg::Drawable* bottomPart = makeDisk(0, w, h, Lego::height_unit/2, length*Lego::length_unit, false);
    // Add drawables to geode
    cylinderGeode->addDrawable(topPart);
    cylinderGeode->addDrawable(bottomPart);

    // Create matrix transform to rotate cylinder
    osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
    // Create matrix to handle rotation
    osg::Matrix matRot, matTrans;
    // Make PI/2 rotation according to y axis
    matRot.makeRotate(M_PI_2, osg::Vec3(0.f, 1.f, 0.f));
    // Translate
    matTrans.makeTranslate(-length*Lego::length_unit/4-Lego::height_unit/4, 0, 3*height*Lego::height_unit/8);
    // Set matrix transform matrix
    mt->setMatrix(matRot*matTrans);
    // Add geode to matrix transform
    mt->addChild(cylinderGeode.get());
    // Add matrix transform
    addChild(mt);

    // Add bottom cylinders iteratively
    for (int i = 0; i < length-1; i++) {
        for (int j = 0; j < width; j++) {
            double radiusX = xminb + i*distPlot;
            double radiusY = yminb + j*distPlot;

            addChild(createBottomCylinder(radiusX, radiusY, 0.5, true, (-height+0.5)*Lego::height_unit/2));
        }
    }
}