コード例 #1
0
ファイル: qtree.c プロジェクト: btheobald/compa2
int insert(node* currentNode, body* pBody, int level) {
  // Return false if body does not belong in this node.
  if(!checkBounds(pBody, currentNode)) {
    return 0;
  }

  // Insert body into node
  if(currentNode->nodeBody == NULL) {
    currentNode->nodeBody = pBody;
    return 1;
  }

  // Prevent adding body to same location (Skip Parents)
  if((!currentNode->isParent) & ((currentNode->nodeBody->pX == pBody->pX) & (currentNode->nodeBody->pY == pBody->pY))) {
    return 0;
  }

  // Subdivide node
  if(currentNode->northWest == NULL) {
    subdivide(currentNode);
    currentNode->isParent = 1;
    insert(currentNode, currentNode->nodeBody, level+1);
    // TODO: Add body averaging
    currentNode->nodeBody = newBody(1,  -1,  -1,  0,  0);
  }

  // Put point into subtree
  if(insert(currentNode->northWest, pBody, level+1)) return 1;
  if(insert(currentNode->northEast, pBody, level+1)) return 1;
  if(insert(currentNode->southEast, pBody, level+1)) return 1;
  if(insert(currentNode->southWest, pBody, level+1)) return 1;

  // Return false if point cannot be inserted.
  return 0;
}
コード例 #2
0
void QMessage::appendAttachments(const QStringList &fileNames)
{
    if (d_ptr->_type == QMessage::Email) {
        ModestEngine::instance()->retrieveMessageMimeInformation(*(QMessage*)this);
    }

    if (!fileNames.isEmpty()) {
        d_ptr->_modified = true;

        QMessageContentContainerPrivate *container(((QMessageContentContainer *)(this))->d_ptr);

        if (container->_attachments.isEmpty()) {
            QMessageContentContainerId existingBodyId(bodyId());
            if (existingBodyId == QMessageContentContainerPrivate::bodyContentId()) {
                // The body content is in the message itself - move it to become the first attachment
                QMessageContentContainer newBody(*this);
                newBody.setDerivedMessage(0);

                container->setContentType("multipart", "mixed", "");
                d_ptr->_bodyId = container->prependContent(newBody);
            } else {
                // This message is now multipart
                container->setContentType("multipart", "mixed", "");
            }

            container->_available = true;
        }

        foreach (const QString &filename, fileNames) {
            QMessageContentContainer attachment;
            if (attachment.d_ptr->createAttachment(filename)) {
                container->appendContent(attachment);
            }
        }
コード例 #3
0
ファイル: physics.c プロジェクト: JamesClonk/Yay-Physics
void init() {
	srand(time(NULL));
	numUnitCircleVertices = 64;
	unitCircle = generateUnitCircle(numUnitCircleVertices);

	b = (Body *)malloc(bodies*sizeof(Body));
	int i;
	for(i=0;i<bodies;++i) {
		b[i] = newBody(
			newVector(
				1-2*(float)rand()/(float)RAND_MAX,
				1-2*(float)rand()/(float)RAND_MAX
			),
			newVector(
				0.002-0.004*(float)rand()/(float)RAND_MAX,
				0.002-0.004*(float)rand()/(float)RAND_MAX
			),
			100*(float)rand()/(float)RAND_MAX
		);
	}
	b[0] = newBody(newVector(0,0.0001),newVector(0,0),2000);
}
コード例 #4
0
//*****************************************************************************
//
// implementation of race.h
//
//*****************************************************************************
void init_races() {
  // create the table for holding race data
  race_table = newHashtable();

  // make the default human body
  BODY_DATA *body = newBody();
  bodySetSize(body, BODYSIZE_MEDIUM);
  bodyAddPosition(body, "right grip",              BODYPOS_HELD,          0);
  bodyAddPosition(body, "left grip",               BODYPOS_HELD,          0);
  bodyAddPosition(body, "right foot",              BODYPOS_RIGHT_FOOT,    2);
  bodyAddPosition(body, "left foot",               BODYPOS_LEFT_FOOT,     2);
  bodyAddPosition(body, "right leg",               BODYPOS_LEG,           9);
  bodyAddPosition(body, "left leg",                BODYPOS_LEG,           9);
  bodyAddPosition(body, "waist",                   BODYPOS_WAIST,         1);
  bodyAddPosition(body, "right finger",            BODYPOS_FINGER,        1);
  bodyAddPosition(body, "left finger",             BODYPOS_FINGER,        1);
  bodyAddPosition(body, "right hand",              BODYPOS_RIGHT_HAND,    2);
  bodyAddPosition(body, "left hand",               BODYPOS_LEFT_HAND,     2);
  bodyAddPosition(body, "right wrist",             BODYPOS_WRIST,         1);
  bodyAddPosition(body, "left wrist",              BODYPOS_WRIST,         1);
  bodyAddPosition(body, "right arm",               BODYPOS_ARM,           7);
  bodyAddPosition(body, "left arm",                BODYPOS_ARM,           7);
  bodyAddPosition(body, "about body",              BODYPOS_ABOUT,         0);
  bodyAddPosition(body, "torso",                   BODYPOS_TORSO,        50);
  bodyAddPosition(body, "neck",                    BODYPOS_NECK,          1);
  bodyAddPosition(body, "right ear",               BODYPOS_EAR,           0);
  bodyAddPosition(body, "left ear",                BODYPOS_EAR,           0);
  bodyAddPosition(body, "face",                    BODYPOS_FACE,          2);
  bodyAddPosition(body, "head",                    BODYPOS_HEAD,          2);
  bodyAddPosition(body, "floating about head",     BODYPOS_FLOAT,         0);
  //                                                                  ------
  //                                                                    100

  // add the basic races
  //add_race("human", "hum", body, TRUE);
  //********************************************************************
  // If you are wanting to add new, non-stock races it is suggested
  // you do so through a module and import them with add_race instead
  // of putting them directly into this folder. This will make your life
  // much easier whenever new versions of NakedMud are released and you
  // want to upgrade!
  //********************************************************************
}
コード例 #5
0
void CSimulation::initialiseBodies()
{
	
	std::cout << "Initialising Bodies..." << std::endl;
	
	std::ostringstream oss;
	char renderChar[100];
	std::string renderStr;
	
	oss.str("");
	oss << "bodies.txt";
	
	std::cout << "   " << oss.str() << std::endl;
			
	std::ifstream myfile (oss.str());
	
	
	if (myfile.is_open()) {
		std::cout << "   " << "Initialise bodies form file" << std::endl;
		//file = true;
		double x,y,velx,vely,mass,radius;
		
    
    while ( myfile.good() )
    {
			myfile >> x;
			myfile >> y;
			myfile >> velx;
			myfile >> vely;
			myfile >> mass;
			myfile >> radius;
			
			
			CBody newBody(x,y,velx,vely,mass,radius);
			bodiesList.push_back(newBody);
					
    }
    myfile.close();

	}