示例#1
0
void World::initIK(double x, double y)
{
	Body* stat,* arm,* forearm;
	stat = addBox(x, y, .2, .2, true);
	arm = addBox(x+1, y, 2, .4, false);
	mPolygon poly;
	mShape* shape = &poly;
	Vector2D vertices[] = {
		Vector2D(-1, -.2),
		Vector2D(1, 0),
		Vector2D(-1, .2),
	};
	poly.Set(vertices, 3);
	forearm = new Body(&shape, 1, x+3, y, 1, false);
	solver.addBody(forearm);
	Joint* shoulder,* elbow;
	stat->filtergroup = f;
	arm->filtergroup = f;
	forearm->filtergroup = f++;
	shoulder = new RevJoint(stat, arm, Vector2D(0,0), Vector2D(-.9,0));
	elbow = new RevJoint(arm, forearm, Vector2D(.9,0), Vector2D(-.9,0));
	solver.addJoint(shoulder);
	solver.addJoint(elbow);
	ik = new IKJoint((RevJoint*)elbow, Vector2D(1, 0));
	ik->AddJoint((RevJoint*)shoulder);
}
示例#2
0
void World::addDynBridge(Vector2D a, Vector2D b)
{
	if (a.x > b.x)
		std::swap(a,b);
	Body* b1 = addBox(a.x, a.y, 2, .5, true);
	Body* b2 = addBox(b.x, b.y, 2, .5, true);
	b1->filtergroup = f;
	b2->filtergroup = f;
	double x = a.x;
	a.x += 1;
	b.x -= 1;
	Body* bp = b1;
	double dist = mag(a - b);
	double l = dist / int(dist/2);
	double lp = 2;
	double xdiff = (b.x-a.x+2) / (dist/2);
	double ydiff = (b.y-a.y) / (dist/2);
	for (int i = 1; i < dist/2; i++)
	{
		Body* bc = addBox(x+(i*xdiff), a.y + (i*ydiff), l, .5, false);
		RevJoint* j = new RevJoint(bp, bc, Vector2D(lp/2, 0), Vector2D(-l/2, 0));
		solver.addJoint(j);
		bp = bc;
		bc->filtergroup = f;
		lp = l;
	}
	RevJoint* j = new RevJoint(bp, b2, Vector2D(l/2, 0), Vector2D(-1, 0));
	solver.addJoint(j);
	f++;
}
示例#3
0
KWStatisticsDialog::KWStatisticsDialog( QWidget *parent, KWDocument *document )
    : KDialogBase(parent, "statistics", true, i18n("Statistics"),KDialogBase::Ok, KDialogBase::Ok, false )
{
    QWidget *page = new QWidget( this );
    setMainWidget(page);
    QVBoxLayout *topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() );

    QTabWidget *tab = new QTabWidget( page );
    QFrame *pageAll = 0;
    QFrame *pageGeneral = 0;
    QFrame *pageSelected = 0;
    for (int i=0; i < 7; ++i) {
        m_resultLabelAll[i] = 0;
        m_resultLabelSelected[i] = 0;
        if ( i < 6 )
            m_resultGeneralLabel[i]=0;
    }
    m_doc = document;
    m_parent = parent;
    m_canceled = true;


    // add Tab "General"
    pageGeneral = new QFrame( this );
    tab->addTab( pageGeneral,  i18n( "General" ) );

    addBoxGeneral( pageGeneral, m_resultGeneralLabel );
    calcGeneral( m_resultGeneralLabel );

    // add Tab "All"
    pageAll = new QFrame( this );
    tab->addTab( pageAll,  i18n( "Text" ) );

    addBox( pageAll, m_resultLabelAll, true );

    m_canceled = true;
    pageSelected = new QFrame( this );
    tab->addTab( pageSelected,  i18n( "Selected Text" ) );
    // let's see if there's selected text
    bool b = docHasSelection();
    tab->setTabEnabled(pageSelected, b);
    if ( b ) {
        addBox( pageSelected, m_resultLabelSelected,  false);
        // assign results to 'selected' tab.
        if ( !calcStats( m_resultLabelSelected, true,true ) )
            return;
        if ( !calcStats( m_resultLabelAll, false,false ) )
            return;
        showPage( 2 );
    } else {
        // assign results
        if ( !calcStats( m_resultLabelAll, false, false ) )
            return;
        showPage( 1 );
    }
    topLayout->addWidget( tab );
    m_canceled = false;

}
示例#4
0
void World::addLinked(double x, double y)
{
	Body* b1 = addBox(x-.5, y, 1, 1, false);
	Body* b2 = addBox(x+.5, y, 1, 1, false);
	b1->restitution = .3;
	b2->restitution = .3;
	RevJoint* j = new RevJoint(b1, b2, Vector2D(.5, -.5), Vector2D(-.5, -.5));
	solver.addJoint(j);
}
示例#5
0
void World::addRope(double x, double y)
{
	Body* b1 = addBox(x, y, .5, 1, true);
	Body* bp = b1;
	b1->filtergroup = f;
	for (int i = 1; i < 20; i++)
	{
		Body* b2 = addBox(x, y-i, .5, 1, false);
		RevJoint* j = new RevJoint(bp, b2, Vector2D(0, -.5), Vector2D(0, .5));
		solver.addJoint(j);
		b2->filtergroup = f;
		bp = b2;
	}
	f++;
}
示例#6
0
ofxLiteBox* ofxLiteGroup::setValue(string name, string value){
	if(boxes.count(name) <= 0)
		addBox(name, new ofxLiteBox(name, value));
	else
		boxes[name]->setValue(value);
	return boxes[name];
}
示例#7
0
PhysicsWidget::PhysicsWidget() 
	: QWidget(0)
{

	physicsLbl = new QLabel("Physics:");
	physicsLbl->setFixedHeight(28);
	addBoxBtn = new QPushButton("Add Box");
	addSphereBtn = new QPushButton("Add Sphere");
	addCylinderBtn = new QPushButton("Add Cylinder");

	QVBoxLayout *mainLayout = new QVBoxLayout;

	mainLayout->addWidget(physicsLbl);
	mainLayout->addWidget(addBoxBtn);
	mainLayout->addWidget(addSphereBtn);
	mainLayout->addWidget(addCylinderBtn);

	setLayout(mainLayout);
	layout()->setContentsMargins(5,0,0,0);

	connect(addBoxBtn, SIGNAL(clicked()),this, SLOT(addBox()));
	connect(addSphereBtn, SIGNAL(clicked()),this, SLOT(addSphere()));
	connect(addCylinderBtn, SIGNAL(clicked()),this, SLOT(addCylinder()));

	setFixedHeight(sizeHint().height());
	setFixedWidth(150);
}
medDatabaseSearchPanel::medDatabaseSearchPanel( QWidget *parent /*= 0*/ ) : medToolBox(parent), d(new medDatabaseSearchPanelPrivate)
{
    d->page = new QWidget(this);

    d->columnBox = new QComboBox();
	d->columnBox->setToolTip(tr("Search criteria"));

    d->addButton = new QPushButton("+");
    d->addButton->setFocusPolicy(Qt::NoFocus);
	d->addButton->setToolTip(tr("Add a search criterion"));
	
    d->removeButton = new QPushButton("-");
    d->removeButton->setFocusPolicy(Qt::NoFocus);
	d->removeButton->setToolTip(tr("Remove a search criterion"));

    QHBoxLayout *vlayout = new QHBoxLayout();
    vlayout->addWidget(d->columnBox);
    vlayout->addWidget(d->addButton);
    vlayout->addWidget(d->removeButton);

    d->layout = new QVBoxLayout();

    this->setTitle(tr("Filter"));

    QVBoxLayout *mainLayout = new QVBoxLayout();
    mainLayout->addLayout(vlayout);
    mainLayout->addLayout(d->layout);

    d->page->setLayout(mainLayout);
    this->addWidget(d->page);

    connect(d->addButton, SIGNAL(clicked()),this, SLOT(addBox()));
    connect(d->removeButton, SIGNAL(clicked()),this, SLOT(removeBox()));

}
//! [2]
void MainWindow::createActions()
{
    deleteAction = new QAction(tr("&Delete Item"), this);
    deleteAction->setShortcut(tr("Del"));
    connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem()));
//! [2] //! [3]

//! [3] //! [4]
    addBoxAction = new QAction(tr("Add &Box"), this);
//! [4]
    addBoxAction->setShortcut(tr("Ctrl+O"));
    connect(addBoxAction, SIGNAL(triggered()), this, SLOT(addBox()));

    addTriangleAction = new QAction(tr("Add &Triangle"), this);
    addTriangleAction->setShortcut(tr("Ctrl+T"));
    connect(addTriangleAction, SIGNAL(triggered()), this, SLOT(addTriangle()));

//! [5]
    undoAction = undoStack->createUndoAction(this, tr("&Undo"));
    undoAction->setShortcuts(QKeySequence::Undo);

    redoAction = undoStack->createRedoAction(this, tr("&Redo"));
    redoAction->setShortcuts(QKeySequence::Redo);
//! [5]

    exitAction = new QAction(tr("E&xit"), this);
    exitAction->setShortcuts(QKeySequence::Quit);
    connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));

    aboutAction = new QAction(tr("&About"), this);
    QList<QKeySequence> aboutShortcuts;
    aboutShortcuts << tr("Ctrl+A") << tr("Ctrl+B");
    aboutAction->setShortcuts(aboutShortcuts);
    connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
}
示例#10
0
void World::addMagnet(double x, double y)
{
	Body* b = addBox(x, y, 1, 2, false);
	Magnet* m1 = new Magnet(b, Vector2D(0, .8), 1, true);
	Magnet* m2 = new Magnet(b, Vector2D(0, -.8), 1, false);
	solver.addMagnet(m1);
	solver.addMagnet(m2);
}
Instructions::Instructions(const std::string& simpleInstructions)
{
    if (!simpleInstructions.empty())
    {
        int lines = 1;
        std::string wrapped = StringUtils::wrap(simpleInstructions, FONT_SIZE_12, 300);
        for (auto i = wrapped.begin(); i != wrapped.end(); i++)
        {
            if (*i == '\n')
            {
                lines++;
            }
        }
        int height = fontGetInfo()->lineFeed * FONT_SIZE_12 * lines + 20;
        addBox(true, 40, 220 - height, 320, height, COLOR_GREY);
        addBox(true, 44, 224 - height, 312, height - 8, COLOR_DARKGREY, wrapped, COLOR_WHITE);
    }
}
示例#12
0
Editor::Editor(unsigned int maxSceneWidth)
{
	m_mainCSP = new CSP();
	m_nextBoxId = ROOT_BOX_ID;
	m_nextRelationId = 1;
	m_nextTriggerId = 1;

	addBox(0, maxSceneWidth, NO_ID);
}
示例#13
0
///////////////////////////////////////////////////////////////////////
// Class				:	CDelayedInstance
// Method				:	CDelayedInstance
// Description			:
/// \brief					Ctor
// Return Value			:	-
// Comments				:
CDelayedInstance::CDelayedInstance(CAttributes *a,CXform *x,CObject *in) : CObject(a,x) {
	atomicIncrement(&stats.numDelayeds);

	instance		=	in;
	processed		=	FALSE;

	initv(bmin,C_INFINITY);
	initv(bmax,-C_INFINITY);

	CObject	*cObject;
	for (cObject=instance;cObject!=NULL;cObject=cObject->sibling) {
		addBox(bmin,bmax,cObject->bmin);
		addBox(bmin,bmax,cObject->bmax);
	}

	xform->transformBound(this->bmin,this->bmax);
	makeBound(this->bmin,this->bmax);
}
示例#14
0
void World::addBridge(double x, double y)
{
	Body* b1 = addBox(x, y, 2, .5, true);
	Body* b2 = addBox(x+20, y, 2, .5, true);
	b1->filtergroup = f;
	b2->filtergroup = f;
	Body* bp = b1;
	for (int i = 1; i < 10; i++)
	{
		Body* bc = addBox(x+(i*2), y, 2, .5, false);
		RevJoint* j = new RevJoint(bp, bc, Vector2D(1, 0), Vector2D(-1, 0));
		solver.addJoint(j);
		bp = bc;
		bc->filtergroup = f;
	}
	RevJoint* j = new RevJoint(bp, b2, Vector2D(1, 0), Vector2D(-1, 0));
	solver.addJoint(j);
	f++;
}
示例#15
0
///////////////////////////////////////////////////////////////////////
// Class				:	CXform
// Method				:	updateBound
// Description			:	Update the bounding box
// Return Value			:	-
// Comments				:
void		CXform::updateBound(float *bmin,float *bmax,int numPoints,const float *P) {
	vector		tmp;
	int			i;
	const float	*cP;
	
	for (i=numPoints,cP=P;i>0;i--,cP+=3) {
		mulmp(tmp,from,cP);
		addBox(bmin,bmax,tmp);
	}
	
	if (next != NULL)	next->updateBound(bmin,bmax,numPoints,P);
}
IfcSchema::IfcProductDefinitionShape* IfcHierarchyHelper::addBox(double w, double d, double h, IfcSchema::IfcAxis2Placement2D* place, 
	IfcSchema::IfcAxis2Placement3D* place2, IfcSchema::IfcDirection* dir, IfcSchema::IfcRepresentationContext* context) 
{
	IfcSchema::IfcRepresentation::list::ptr reps (new IfcSchema::IfcRepresentation::list);
	IfcSchema::IfcRepresentationItem::list::ptr items (new IfcSchema::IfcRepresentationItem::list);		
	IfcSchema::IfcShapeRepresentation* rep = new IfcSchema::IfcShapeRepresentation(
		context ? context : getRepresentationContext("Model"), std::string("Body"), std::string("SweptSolid"), items);
	reps->push(rep);
	IfcSchema::IfcProductDefinitionShape* shape = new IfcSchema::IfcProductDefinitionShape(boost::none, boost::none, reps);
	addEntity(rep);
	addEntity(shape);
	addBox(rep, w, d, h, place, place2, dir, context);
	return shape;
}
void HelloWorld::onEnter(){
    
    Layer::onEnter();
    
    auto bounds = Node::create();
    bounds->setContentSize(visibleSize);
    bounds->setPhysicsBody(PhysicsBody::createEdgeBox(bounds->getContentSize()));
    bounds->getPhysicsBody()->setContactTestBitmask(EDGE_BIT_MASK);
    bounds->setPosition(visibleSize/2);
    addChild(bounds);
    
    addBox(Vec2(visibleSize.width/2, visibleSize.height/2));
    
}
示例#18
0
World::World()
{
	r(-241, 4);
	solver.addRay(&ray);
	addCar(-240, 3);
	addBox(0,0,600,.5,true);
	// man.Initialize(-230, 3);
	// Body* b; Joint* j;
	// while (b = man.RegisterBodies())
		// solver.addBody(b);
	// while (j = man.RegisterJoints())
		// solver.addJoint(j);
	//initIK(-2350, 30);
	//solver.SetGravityFunc(gravity);
}
示例#19
0
int PhysicsWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: addBox(); break;
        case 1: addSphere(); break;
        case 2: addCylinder(); break;
        default: ;
        }
        _id -= 3;
    }
    return _id;
}
示例#20
0
TB_PokemonBoxes::TB_PokemonBoxes(Team *_team)
{
    m_team = _team;
    currentPoke = 0;
    QVBoxLayout * ml = new QVBoxLayout(this);
    QHBoxLayout *firstline = new QHBoxLayout();
    ml->addLayout(firstline);

    firstline->addWidget(m_details = new TB_PokemonDetail());
    firstline->addSpacing(20);
    firstline->addWidget(new TitledWidget(tr("Change Order"), m_buttons = new TB_PokemonButtons()),0,Qt::AlignVCenter);

    QVBoxLayout *thirdColumn = new QVBoxLayout();
    firstline->addLayout(thirdColumn);
    QPushButton *bstore, *bwithdraw, /* *bswitch, */ *bdelete, *bboxname, *addbox, *deletebox;

    thirdColumn->addStretch(100);
    thirdColumn->addWidget(bstore = new QPushButton(tr("&Store")));
    thirdColumn->addWidget(bwithdraw = new QPushButton(tr("&Withdraw")));
    //thirdColumn->addWidget(bswitch = new QPushButton(tr("Switc&h")));
    thirdColumn->addWidget(bdelete = new QPushButton(tr("Dele&te")));
    thirdColumn->addWidget(bboxname = new QPushButton(tr("&Edit Box Name...")));
    thirdColumn->addWidget(addbox = new QPushButton(tr("&Add New Box")));
    thirdColumn->addWidget(deletebox = new QPushButton(tr("&Delete Current Box")));
    thirdColumn->addStretch(100);

    firstline->addStretch(100);

    bstore->setFixedWidth(132);


    QHBoxLayout *secondline = new QHBoxLayout();
    ml->addLayout(secondline);

    secondline->addWidget(m_boxes = new TB_BoxContainer(), 100);

    QDir directory = QDir(PokemonBox::getBoxPath());

    QStringList files = directory.entryList(QStringList() << "*.box", QDir::Files | QDir::NoSymLinks | QDir::Readable, QDir::Name);

    if (files.size() == 0) {
        files.push_back("First Box.box");
    }

    foreach (QString file, files) {
        addBox(file);
    }
示例#21
0
/**
 * @brief Remove all boxes from cubical volume - service callback function
 * @param req Request
 * @param res Response
 */
bool srs_env_model::CCMapPlugin::addBoxCallback( srs_env_model::RemoveCube::Request & req, srs_env_model::RemoveCube::Response & res )
{
	// Test frame id
	if (req.frame_id != m_cmapFrameId)
	{
		// Transform size
		geometry_msgs::PointStamped vs, vsout;
		vs.header.frame_id = req.frame_id;
		vs.header.stamp = m_mapTime;
		POINT_ADD( vs.point, req.size, req.pose.position );
		m_tfListener.transformPoint(m_cmapFrameId, vs, vsout);

		// Transform pose
		geometry_msgs::PoseStamped ps, psout;
		ps.header.frame_id = req.frame_id;
		ps.header.stamp = m_mapTime;
		ps.pose = req.pose;

		m_tfListener.transformPose(m_cmapFrameId, ps, psout);
		req.pose = psout.pose;

		// Finalize size transform
		POINT_SUB(req.size, vsout.point, psout.pose.position);
		POINT_ABS(req.size, req.size);

	}


	tBoxPoint center, size;

	// Convert point type
	center.x = req.pose.position.x; center.y = req.pose.position.y; center.z = req.pose.position.z;
	size.x = req.size.x; size.y = req.size.y; size.z = req.size.z;

	// Add box
//	std::cerr << "Adding box. " << m_data->boxes.size() << " -> ";
	addBox( center, size, m_data->boxes );
//	std::cerr << m_data->boxes.size() << std::endl;

	invalidate();

	return true;
}
示例#22
0
文件: World.cpp 项目: tbastos/solid
void World::load() {
  sql::connection db(getDbConfig());
  db.execute(R"(
    CREATE TABLE IF NOT EXISTS `box` (
      `x`     REAL NOT NULL DEFAULT 0,
      `y`     REAL NOT NULL DEFAULT 0,
      `z`     REAL NOT NULL DEFAULT 0,
      `yaw`   REAL NOT NULL DEFAULT 0,
      `pitch` REAL NOT NULL DEFAULT 0,
      `roll`  REAL NOT NULL DEFAULT 0,
      `red`   REAL NOT NULL DEFAULT 1,
      `green` REAL NOT NULL DEFAULT 0,
      `blue`  REAL NOT NULL DEFAULT 0
    );)");
  box_db::Box tbl;
  for (const auto& row : db(select(all_of(tbl)).from(tbl).unconditionally())) {
    addBox(btVector3(row.x, row.y, row.z), row.yaw, row.pitch, row.roll,
           glm::vec3(row.red, row.green, row.blue));
  }
}
示例#23
0
	/*
	 * Default 2D vectorization method
	 */
	void Barcode2dBase::vectorize( const Matrix<bool>& encodedData,
				       double&             w,
				       double&             h )
	{

		/* determine size and establish scale */
		double scale;
		double minW = MIN_CELL_SIZE*encodedData.nx() + 2*MIN_CELL_SIZE;
		double minH = MIN_CELL_SIZE*encodedData.ny() + 2*MIN_CELL_SIZE;

		if ( (w <= minW) || (h <= minH) )
		{
			scale = 1;
			w     = minW;
			h     = minH;
		}
		else
		{
			scale = std::min( w / minW, h / minH );
			w     = scale * minW;
			h     = scale * minH;
		}
		double cellSize  = scale * MIN_CELL_SIZE;
		double quietSize = scale * MIN_CELL_SIZE;
		
		
		for ( int iy = 0; iy < encodedData.ny(); iy++ )
		{
			for ( int ix = 0; ix < encodedData.nx(); ix++ )
			{
				if ( encodedData[iy][ix] )
				{
					addBox( quietSize + ix*cellSize,
						quietSize + iy*cellSize,
						cellSize,
						cellSize );
				}
			}
		}

	}
示例#24
0
void ScriptedPhysicsBodyDefinition::receiveMessage(const tyr::script::Message& inMessage, tyr::script::Message& outMessage)
{
    if(inMessage.hasValue("func", tyr::ValueType::String))
    {
        std::string func = inMessage.getValue("func").string;
        if(func == "addBox")
        {
            float x, y, z;
            x = inMessage.getValue("x").number;
            y = inMessage.getValue("y").number;
            z = inMessage.getValue("z").number;

            addBox(glm::vec3(x, y, z));
        }
        if(func == "setBodyType")
        {
            int type = inMessage.getValue("type").number;

            setBodyType(static_cast<tyr::physics::BodyType>(type));
        }
    }
}
IfcSchema::IfcProductDefinitionShape* IfcHierarchyHelper::addAxisBox(double w, double d, double h, IfcSchema::IfcRepresentationContext* context) 
{
	IfcSchema::IfcRepresentation::list::ptr reps(new IfcSchema::IfcRepresentation::list);
	IfcSchema::IfcRepresentationItem::list::ptr body_items(new IfcSchema::IfcRepresentationItem::list);
	IfcSchema::IfcRepresentationItem::list::ptr axis_items(new IfcSchema::IfcRepresentationItem::list);
	IfcSchema::IfcShapeRepresentation* body_rep = new IfcSchema::IfcShapeRepresentation(
		context ? context : getRepresentationContext("Model"), std::string("Body"), std::string("SweptSolid"), body_items);

	IfcSchema::IfcShapeRepresentation* axis_rep = new IfcSchema::IfcShapeRepresentation(
		context ? context : getRepresentationContext("Plan"), std::string("Axis"), std::string("Curve2D"), axis_items);

	reps->push(axis_rep);
	reps->push(body_rep);

	IfcSchema::IfcProductDefinitionShape* shape = new IfcSchema::IfcProductDefinitionShape(boost::none, boost::none, reps);
	addEntity(shape);
	addEntity(body_rep);
	addBox(body_rep, w, d, h, 0, 0, 0, context);
	addEntity(axis_rep);
	addAxis(axis_rep, w);
	
	return shape;
}
示例#26
0
///////////////////////////////////////////////////////////////////////
// Class				:	CXform
// Method				:	transformBound
// Description			:	This function is used to transform a bounding box
// Return Value			:	-
// Comments				:
void	transformBound(float *lbmin,float *lbmax,const float *to,const float *bmin,const float *bmax) {
	vector		corners[8];
	int			i;
	vector		vtmp;

	// Compute & transfer the corners to the dest space
	initv(vtmp,bmin[COMP_X],bmin[COMP_Y],bmin[COMP_Z]);
	mulmp(corners[0],to,vtmp);

	initv(vtmp,bmin[COMP_X],bmin[COMP_Y],bmax[COMP_Z]);
	mulmp(corners[1],to,vtmp);

	initv(vtmp,bmin[COMP_X],bmax[COMP_Y],bmax[COMP_Z]);
	mulmp(corners[2],to,vtmp);

	initv(vtmp,bmin[COMP_X],bmax[COMP_Y],bmin[COMP_Z]);
	mulmp(corners[3],to,vtmp);

	initv(vtmp,bmax[COMP_X],bmin[COMP_Y],bmin[COMP_Z]);
	mulmp(corners[4],to,vtmp);

	initv(vtmp,bmax[COMP_X],bmin[COMP_Y],bmax[COMP_Z]);
	mulmp(corners[5],to,vtmp);

	initv(vtmp,bmax[COMP_X],bmax[COMP_Y],bmax[COMP_Z]);
	mulmp(corners[6],to,vtmp);

	initv(vtmp,bmax[COMP_X],bmax[COMP_Y],bmin[COMP_Z]);
	mulmp(corners[7],to,vtmp);

	movvv(lbmin,corners[0]);
	movvv(lbmax,corners[0]);

	for (i=1;i<8;i++) {
		addBox(lbmin,lbmax,corners[i]);
	}
}
示例#27
0
文件: menu.cpp 项目: serman/muncyt
void menu::initParticles() {
	ofLogNotice("oooooooooo ----- initParticles()");
	// add objects
	removeParticles();	// primero borrar las que pudiera haber, porsiaca.
	for (int i=0; i<150; i++) {
		// circulos
		float distR = ofRandom(W_HEIGHT/2)*0.8;
		float angTmp = ofRandom(TWO_PI);
//		addCircle(ofPoint(ofGetWidth()/2+ofRandom(200)-100, W_HEIGHT/2+ofRandom(200)-100));
		addCircle(ofPoint(ofGetWidth()/2+distR*cos(angTmp), W_HEIGHT/2+distR*sin(angTmp)));
		
		distR = ofRandom(W_HEIGHT/2)*0.8;
		angTmp = ofRandom(TWO_PI);
		// rectangulos
//		addBox(ofPoint(ofGetWidth()/2+ofRandom(200)-100, W_HEIGHT/2+ofRandom(200)-100));
		addBox(ofPoint(ofGetWidth()/2+distR*cos(angTmp), W_HEIGHT/2+distR*sin(angTmp)));
	}
	ptoMed_circles = ptoMedio(circles);
	ptoMed_boxes = ptoMedio(boxes);
	
	bAddCircle = false;
	bAddBox = false;

}
示例#28
0
void wiBULLET::registerObject(Object* object){
	if(object->rigidBody && rigidBodyPhysicsEnabled){
		//XMVECTOR s,r,t;
		//XMMatrixDecompose(&s,&r,&t,XMLoadFloat4x4(&object->world));
		XMFLOAT3 S,T;
		XMFLOAT4 R;
		//XMStoreFloat3(&S,s);
		//XMStoreFloat4(&R,r);
		//XMStoreFloat3(&T,t);
		object->applyTransform();
		object->attachTo(object->GetRoot());

		S = object->scale;
		T = object->translation;
		R = object->rotation;

		if(!object->collisionShape.compare("BOX")){
			addBox(
				S,R,T
				,object->mass,object->friction,object->restitution
				,object->damping,object->kinematic
			);
			object->physicsObjectI=++registeredObjects;
		}
		if(!object->collisionShape.compare("SPHERE")){
			addSphere(
				S.x,T
				,object->mass,object->friction,object->restitution
				,object->damping,object->kinematic
			);
			object->physicsObjectI=++registeredObjects;
		}
		if(!object->collisionShape.compare("CAPSULE")){
			addCapsule(
				S.x,S.y,R,T
				,object->mass,object->friction,object->restitution
				,object->damping,object->kinematic
			);
			object->physicsObjectI=++registeredObjects;
		}
		if(!object->collisionShape.compare("CONVEX_HULL")){
			addConvexHull(
				object->mesh->vertices,
				S,R,T
				,object->mass,object->friction,object->restitution
				,object->damping,object->kinematic
			);
			object->physicsObjectI=++registeredObjects;
		}
		if(!object->collisionShape.compare("MESH")){
			addTriangleMesh(
				object->mesh->vertices,object->mesh->indices,
				S,R,T
				,object->mass,object->friction,object->restitution
				,object->damping,object->kinematic
			);
			object->physicsObjectI=++registeredObjects;
		}
	}

	if(object->mesh->softBody && softBodyPhysicsEnabled){
		XMFLOAT3 s,t;
		XMFLOAT4 r;
		if(object->mesh->hasArmature()){
			s=object->mesh->armature->scale;
			r=object->mesh->armature->rotation;
			t=object->mesh->armature->translation;
		}
		else{
			s=object->scale;
			r=object->rotation;
			t=object->translation;
		}
		addSoftBodyTriangleMesh(
			object->mesh
			,s,r,t
			,object->mass,object->mesh->friction,object->restitution,object->damping
		);
		object->physicsObjectI=++registeredObjects;
	}
}
示例#29
0
文件: test.cpp 项目: janoldsen/Onager
void Test::init()
{
	m_world = new World(vec3(0.0f, -10.0f, 0.0f));
	//m_world = new World(vec3(0.0f, 0.0f, 0.0f));


	gBox = ShapePtr();
	gCapsule = ShapePtr();
	gFloor = ShapePtr();
	gSlope = ShapePtr();
	gSphere = ShapePtr();

	Material m;
	m.density = 10.0f;
	m.friction = 1.0f;
	m.restitution = 0.0f;

	Material* material = m_world->createMaterial(m);

	BodyDescription descr;
	descr.type = BodyType::Dynamic;
	descr.transform = Transform(vec3(0.0f, 5.0f, -4.0f), QuatFromAxisAngle(vec3(1.0f, 2.0f, 3.0f), 1.0f));
	descr.linearMomentum = vec3(0.0f, 0.0f, 0.0f);
	descr.angularMomentum = vec3(0.0f, 0.0f, 0.0f);

	m_entities.push_back(addBox(m_world, descr, material));

	ShapeDescription shapeDescr;
	shapeDescr.shapeType = ShapeType::CAPSULE;
	shapeDescr.capsule.r = 0.5f;
	shapeDescr.capsule.c1 = vec3(0.0f, 0.5f, 0.0f);
	shapeDescr.capsule.c2 = vec3(0.0f, -0.5f, 0.0f);

	gCapsule = m_world->createShape(shapeDescr);

	ColliderDescription colliderDescr;
	colliderDescr.material = material;
	colliderDescr.transform = Transform(vec3(0, 0, 0), QuatFromAxisAngle(vec3(1, 0, 0), 0));
	colliderDescr.shape = gCapsule;
	colliderDescr.isSensor = false;

	descr.transform.p.x += 3.0f;

	Collider* c = m_world->createCollider(colliderDescr);
	Body* b = m_world->createBody(descr);
	b->addCollider(c);
	m_entities.push_back(new Entity(b, vec3(0, 0, 1)));



	// spherestack
	{

		shapeDescr.shapeType = ShapeType::SPHERE;
		shapeDescr.sphere.r = 1.0f;
		shapeDescr.sphere.c = vec3(0, 0, 0);
		gSphere = m_world->createShape(shapeDescr);

		colliderDescr.shape = gSphere;

		descr.transform.p.x += 3.0f;
		Collider* c = m_world->createCollider(colliderDescr);
		Body* b = m_world->createBody(descr);
		b->addCollider(c);
		m_entities.push_back(new Entity(b, vec3(0, 0, 1)));




		descr.transform = Transform(vec3(-10.0f, 3.0f, -10.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));

		for (int i = 0; i < 4; ++i)
		{
			Collider* c = m_world->createCollider(colliderDescr);

			Body* b = m_world->createBody(descr);
			b->addCollider(c);
			m_entities.push_back(new Entity(b, vec3(0, 0, 1)));

			descr.transform.p.y += 3.0f;
		}
	}

	colliderDescr.shape = gCapsule;
	descr.transform = Transform(vec3(-10.0f, 3.0f, 10.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));

	for (int i = 0; i < 4; ++i)
	{
		Collider* c = m_world->createCollider(colliderDescr);

		Body* b = m_world->createBody(descr);
		b->addCollider(c);
		m_entities.push_back(new Entity(b, vec3(0, 0, 1)));

		descr.transform.p.y += 3.0f;
	}

	
	//pyramid
	descr.transform = Transform(vec3(10.0f, 0.0f, 0.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform = Transform(vec3(10.0f, 0.0f, -2.5f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform = Transform(vec3(10.0f, 0.0f, +2.5f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m_entities.push_back(addBox(m_world, descr, material));

	descr.transform = Transform(vec3(10.0f, 2.125f, -1.25f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform = Transform(vec3(10.0f, 2.125f, +1.25f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m_entities.push_back(addBox(m_world, descr, material));

	descr.transform = Transform(vec3(10.0f, 4.25f, 0.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m_entities.push_back(addBox(m_world, descr, material));






	descr.transform = Transform(vec3(-10.0f, 3.0f, 0.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform.p.y += 3.0;
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform.p.y += 3.0;
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform.p.y += 3.0;
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform.p.y += 3.0;
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform.p.y += 3.0;
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform.p.y += 3.0;
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform.p.y += 3.0;
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform.p.y += 3.0;
	m_entities.push_back(addBox(m_world, descr, material));

	
	for (int i = -1; i <= 1; ++i)
	{
		for (int j = -1; j <= 1; ++j)
		{
			m_entities.push_back(addFloor(m_world, material, vec3(i *60, 0, j*60)));

		}
	}
	m_entities.push_back(addSlope(m_world, Transform(vec3(0, 0, -4), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f)), material));
	m_entities.push_back(addSlope(m_world, Transform(vec3(0, 0, 4), QuatFromAxisAngle(vec3(0.0f, 1.0f, 0.0f), ong_PI)), material));
	
	descr.transform = Transform(vec3(-3.0f, 5.0f, 5.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m_entities.push_back(addBox(m_world, descr, material));
	m.friction /= 2.0f;
	material = m_world->createMaterial(m);
	descr.transform = Transform(vec3(0.0f, 5.0f, 5.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m.friction /= 2.0f;
	material = m_world->createMaterial(m);
	m_entities.push_back(addBox(m_world, descr, material));
	descr.transform = Transform(vec3(3.0f, 5.0f, 5.0f), QuatFromAxisAngle(vec3(1.0f, 0.0f, 0.0f), 0.0f));
	m.friction /= 2.0f;
	material = m_world->createMaterial(m);
	m_entities.push_back(addBox(m_world, descr, material));

	
	//player
	Transform t = Transform(vec3(0.0f, 8.0f, -10.0f), QuatFromAxisAngle(vec3(1, 0, 0), 0));
	m_player = addPlayer(m_world, t);
	m_entities.push_back(m_player);



	static int gNumSteps = 0;
	int numSteps = 0;
	for (int i = 0; i < numSteps; ++i)
	{
		printf("%d\n", gNumSteps);
		m_world->step(1.0f / 60.0f);
		++gNumSteps;
	}


}
示例#30
0
///////////////////////////////////////////////////////////////////////
// Class				:	CPointHierarchy
// Method				:	cluster
// Description			:
/// \brief					Cluster the items
// Return Value			:	-
// Comments				:
int			CPointHierarchy::cluster(int numItems,int *indices) {

	// Sanity check
	assert(numItems > 0);

	if (numItems == 1) {
		// Create a leaf
		return -indices[0];

	} else if (numItems == 2) {
		// Easy case
		int			nodeIndex	=	average(numItems,indices);
		CMapNode	*node		=	nodes.array + nodeIndex;
		node->child0			=	-indices[0];
		node->child1			=	-indices[1];
		return nodeIndex;

	} else {
		// Allocate temp memory
		int	*membership,*subItems;
		
		// Use alloca if the allocation size is low enough
		if (numItems >= ALLOCA_MAX_ITEMS)	membership	=	new int[numItems*2];
		else								membership	=	(int *) alloca(numItems*2*sizeof(int));

		subItems	=	membership	+	numItems;

		vector	bmin,bmax;

		initv(bmin,C_INFINITY);
		initv(bmax,-C_INFINITY);
		
		// The membership is dummy ... Also compute the bounding box of the point set
		for (int i=0;i<numItems;i++) {
			membership[i]	=	-1;
			addBox(bmin,bmax,CMap<CPointCloudPoint>::items[indices[i]].P);
		}
		
		vector	C0,C1;		// The cluster centers
		vector	N0,N1;		// The cluster normals

		// Create random cluster centers
		initv(C0,	_urand()*(bmax[0]-bmin[0]) + bmin[0],
					_urand()*(bmax[1]-bmin[1]) + bmin[1],
					_urand()*(bmax[2]-bmin[2]) + bmin[2]);
		initv(C1,	_urand()*(bmax[0]-bmin[0]) + bmin[0],
					_urand()*(bmax[1]-bmin[1]) + bmin[1],
					_urand()*(bmax[2]-bmin[2]) + bmin[2]);

		// Create random cluster normals
		initv(N0,	_urand()*2-1,	_urand()*2-1,	_urand()*2-1);
		initv(N1,	_urand()*2-1,	_urand()*2-1,	_urand()*2-1);
		normalizevf(N0);
		normalizevf(N1);

		// Perform the clustering iterations
		int		num0,num1;
		for (int iterations=0;iterations<5;iterations++) {	// Try 5 times ... Not until convergence
			int		changed	=	FALSE;
			vector	nC0,nC1;
			vector	nN0,nN1;

			// Clear the data
			initv(nC0,0);
			initv(nC1,0);
			initv(nN0,0);
			initv(nN1,0);
			num0	=	0;
			num1	=	0;
			
			// iterate over items
			for (int i=0;i<numItems;i++) {
				vector						D;
				const	CPointCloudPoint	*cItem	=	CMap<CPointCloudPoint>::items + indices[i];
				
				// Compute the distance to the first cluster
				subvv(D,cItem->P,C0);
				const float d0	=	dotvv(D,D) / max(dotvv(N0,cItem->N),C_EPSILON);
				
				// Compute the distance to the second cluster
				subvv(D,cItem->P,C1);
				const float d1	=	dotvv(D,D) / max(dotvv(N1,cItem->N),C_EPSILON);
				
				// Change the membership if necessary
				if (d0 < d1) {
					if (membership[i] != 0) {
						changed			=	TRUE;
						membership[i]	=	0;
					}

					addvv(nC0,cItem->P);
					addvv(nN0,cItem->N);
					num0++;
				} else {
					if (membership[i] != 1) {
						changed			=	TRUE;
						membership[i]	=	1;
					}

					addvv(nC1,cItem->P);
					addvv(nN1,cItem->N);
					num1++;
				}
			}
			
			// Check for degenerate cases
			if ((num0 == 0) || (num1 == 0)) {
				initv(C0,	_urand()*(bmax[0]-bmin[0]) + bmin[0],
							_urand()*(bmax[1]-bmin[1]) + bmin[1],
							_urand()*(bmax[2]-bmin[2]) + bmin[2]);
				initv(C1,	_urand()*(bmax[0]-bmin[0]) + bmin[0],
							_urand()*(bmax[1]-bmin[1]) + bmin[1],
							_urand()*(bmax[2]-bmin[2]) + bmin[2]);

				initv(N0,	_urand()*2-1,	_urand()*2-1,	_urand()*2-1);
				initv(N1,	_urand()*2-1,	_urand()*2-1,	_urand()*2-1);
				normalizevf(N0);
				normalizevf(N1);
			} else {
				if (changed == FALSE)	break;

				mulvf(C0,nC0,1 / (float) num0);
				mulvf(C1,nC1,1 / (float) num1);

				// Normalize the normal vectors
				normalizevf(N0,nN0);
				normalizevf(N1,nN1);
			}	
		}
		
		// Do we have a bad clustering?
		while (num0 == 0 || num1 == 0) {

			// Clustering failed - probably coincident points, make an arbitrary split
			num0 = num1 = 0;
			for (int i=0;i<numItems;i++) {
				const int which = i & 1;
				if (which)	num1++;
				else		num0++;
				membership[i] = which;
			}

			// FIXME: A smarter thing to do would be to sort the items in one dimension and split it in half
		}
		
		assert((num0 + num1) == numItems);

		// Average the items and create an internal node
		const int	nodeIndex	=	average(numItems,indices);
		
		// OK, split the items into two
		int	i,j;
		
		// Collect the items in the first child
		for (i=0,j=0;i<numItems;i++)	if (membership[i] == 0)	subItems[j++]	=	indices[i];
		assert(j == num0);
		const int	child0	=	cluster(num0,subItems);
		
		// Collect the items in the second child
		for (i=0,j=0;i<numItems;i++)	if (membership[i] == 1)	subItems[j++]	=	indices[i];
		assert(j == num1);
		const int	child1	=	cluster(num1,subItems);
		
		// NOTE: There's an important subtlety here...
		// We can not access cNode before the child nodes are created because the creation of children
		// may change the nodes.array field
		CMapNode *cNode	=	nodes.array + nodeIndex;
		cNode->child0	=	child0;
		cNode->child1	=	child1;

		// Reclaim the memory if applicable
		if (numItems >= ALLOCA_MAX_ITEMS)	delete [] membership;

		// Return the index of the node
		return nodeIndex;
	}
}