Exemple #1
0
int main()
{
	//**************//
	//** jVector2 **//
	//**************//

	// Create an "empty" jVector2:  (0,0)
	jVector2 vector1;
	// Create "partial" jVector2: (5,0)
	jVector2 vector2(5.0f);
	// Create "full" jVector2: (1,2)
	jVector2 vector3(1.0f, 2.0f);
	// print the vectors out
	std::cout << vector1.toString() << std::endl;
	std::cout << vector2.toString() << std::endl;
	std::cout << vector3.toString() << std::endl;
	// add two vectors together
	jVector2 sum23 = vector2 + vector3;
	std::cout << sum23.toString() << std::endl;
	// subtract two vectors
	jVector2 diff = jVector2(6.0f, 4.0f) - jVector2(10.0f, 2.0f);
	std::cout << diff.toString() << std::endl;
	// multiply vector by scalar
	std::cout << (vector3 * 1.25f).toString() << std::endl;
	// divide vector by scalar
	std::cout << (sum23 / 10.0f).toString() << std::endl;
	// test equality
	std::cout << (sum23 == diff) << std::endl;
	// test inequality
	std::cout << (diff != vector1) << std::endl;
	// get magnitude
	std::cout << vector3.magnitude_sqr() << std::endl;
	// normalize vector
	std::cout << (vector3.normalized()).toString() << std::endl;

	////////////////////////////////////////////////////

	// jVector3

	jVector3 vector_1;
	jVector3 vector_2(5.0f);
	jVector3 vector_3(1.0f, 2.0f, 3.0f);

	std::cout << vector_1.toString() << std::endl;
	std::cout << vector_2.toString() << std::endl;
	std::cout << vector_3.toString() << std::endl;

	// This will be put into the jDebug namespace/class.
/*	#ifdef linux
	#else
		// And this is why programming for Windows sucks...
		HANDLE h_stdout = GetStdHandle( STD_OUTPUT_HANDLE );
		CONSOLE_SCREEN_BUFFER_INFO csbi;
		GetConsoleScreenBufferInfo( h_stdout, &csbi );
		// Foreground B G R I
		// Colors     0 0 1 1
		// Background B G R I
		// Colors     0 0 0 1
		// All together, 00110001 is like this:
		SetConsoleTextAttribute( h_stdout, 0x31 );
		std::cout << vector_1 << std::endl;

		SetConsoleTextAttribute( h_stdout, csbi.wAttributes );
	#endif */

	jDebug::LogError("An error has occurred!");
	jDebug::LogWarning("A warning has occurred!");
	jDebug::Log("A notification has appeared.");


	jDebug::AddLogger("main", "logs/main.log");
	jDebug::LogError("main", "A test error to be found in main.log");
	jDebug::Log("main", "A test notification to be found in main.log");
	// Don't forget your cleanup!
	jDebug::DestructLoggers();

	return 0;
}
Exemple #2
0
 vector3 normalize() {
     float norm = sqrt(x*x + y*y + z*z);
     return vector3(x / norm, y / norm, z / norm);
 }
Exemple #3
0
 Vector4T&	normalize3   (double len = 1.0)		       { vector3().normalize(len); return *this; }
Exemple #4
0
//------------------------------------------------------------------------------
bool OBOpenDXCubeFormat::ReadMolecule( OBBase* pOb, OBConversion* pConv )
{
    OBMol* pmol = pOb->CastAndClear<OBMol>();
    if(pmol == 0)
      return false;

    istream& ifs = *pConv->GetInStream();

    const char* title = pConv->GetTitle();
    char buffer[BUFF_SIZE];

    stringstream errorMsg;

    if (!ifs)
      return false; // We are attempting to read past the end of the file

    pmol->SetTitle(title);

    while (ifs.good() && ifs.getline(buffer,BUFF_SIZE)) {
      if (buffer[0] == '#')
        continue; // comment line
      if (EQn(buffer, "object", 6))
        break;
    }
    if (!ifs)
      return false; // ran out of lines

    vector<string> vs;
    tokenize(vs, buffer);

    // Number of grid points (voxels)
    vector<int> voxels(3);
    if (!EQn(buffer, "object", 6) || vs.size() != 8)
      return false;
    else {
      voxels[0] = atoi(vs[5].c_str());
      voxels[1] = atoi(vs[6].c_str());
      voxels[2] = atoi(vs[7].c_str());
    }

    double x, y, z;
    if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "origin", 6))
      return false;
    else {
      tokenize(vs, buffer);
      if (vs.size() != 4)
        return false;
      x = atof(vs[1].c_str());
      y = atof(vs[2].c_str());
      z = atof(vs[3].c_str());
    }
    vector3 origin(x, y, z);

    // now three lines with the x, y, and z axes
    vector<vector3> axes;
    for (unsigned int i = 0; i < 3; ++i) {
      if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "delta", 5))
        return false;
      else {
        tokenize(vs, buffer);
        if (vs.size() != 4)
          return false;
        x = atof(vs[1].c_str());
        y = atof(vs[2].c_str());
        z = atof(vs[3].c_str());
        axes.push_back(vector3(x, y, z));
      }
    }

    // Two remaining header lines before the data:
    /*
      object 2 class gridconnections counts nx ny nz
      object 3 class array type double rank 0 times n data follows
    */
    if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "object", 6))
      return false;
    if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "object", 6))
      return false;

    pmol->BeginModify();
    pmol->SetDimension(3);

    OBGridData *gd = new OBGridData;
    gd->SetAttribute("OpenDX");

    // get all values as one vector<double>
    char *endptr;
    vector<double> values;
    int n = voxels[0]*voxels[1]*voxels[2];
    int line = 0;
    values.reserve(n);
    while (ifs.getline(buffer, BUFF_SIZE))
    {
      ++line;
      if (EQn(buffer, "attribute", 9))
        break; // we're finished with reading data -- although we should probably have a voxel check in here too

      tokenize(vs, buffer);
      if (vs.size() == 0)
      {
        errorMsg << "Problem reading the OpenDX grid file: cannot"
                 << " read line " << line
                 << ", there does not appear to be any data in it.\n"
                 << buffer << "\n";
        obErrorLog.ThrowError(__FUNCTION__, errorMsg.str(), obError);
        return false;
      }

      for (unsigned int l = 0; l < vs.size(); ++l)
      {
        values.push_back(strtod(static_cast<const char*>(vs[l].c_str()), &endptr));
      }
    }

    gd->SetNumberOfPoints(voxels[0], voxels[1], voxels[2]);
    gd->SetLimits(origin, axes[0], axes[1], axes[2]);
    gd->SetUnit(OBGridData::ANGSTROM);
    gd->SetOrigin(fileformatInput); // i.e., is this data from a file or determined by Open Babel
    gd->SetValues(values); // set the values
    pmol->SetData(gd); // store the grids in the OBMol
    pmol->EndModify();

    // Trailing control lines
    /*
     attribute "dep" string "positions"
     object "regular positions regular connections" class field
     component "positions" value 1
     component "connections" value 2
     component "data" value 3
    */
    if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "object", 6))
      return false;
    if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "component", 9))
      return false;
    if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "component", 9))
      return false;
    if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "component", 9))
      return false;

    // clean out any remaining blank lines
    std::streampos ipos;
    do
    {
      ipos = ifs.tellg();
      ifs.getline(buffer,BUFF_SIZE);
    }
    while(strlen(buffer) == 0 && !ifs.eof() );
    ifs.seekg(ipos);

    return true;
  }
Tmpl8::Frustum::Frustum()
{
////////////////////////////////// Viewspace frustum ////////////////////////////////////////
// didn't quit finish it.

 	float top = -(SCRHEIGHT / 2) + 1;
 	float left = -(SCRWIDTH / 2) + 1;
 	float bottom = (SCRHEIGHT / 2) - 1;
 	float right = (SCRWIDTH / 2) - 1;
 	float nearp = 1.0f;
 	float farp = 50;
 	float FoV = 0.003;
 
 	for(unsigned int i = 0; i < 6; ++i)
 	{
 		m_Plane[i] = new Plane();
 	}
 
 	vector3 nv1, nv2, nv3, nv4;
 	vector3 fv1, fv2, fv3, fv4;
 
 	nv1.x = left * nearp / FoV;
 	nv1.y = top * nearp / FoV;
 	nv1.z = nearp;
 
 	nv2.x = left * nearp / FoV;
 	nv2.y = bottom * nearp / FoV;
 	nv2.z = nearp;
 
 	nv3.x = right * nearp / FoV;
 	nv3.y = top * nearp / FoV;
 	nv3.z = nearp;
 
 	nv4.x = right * nearp / FoV;
 	nv4.y = bottom * nearp / FoV;
 	nv4.z = nearp;
 
 	fv1.x = left * farp / FoV;
 	fv1.y = top * farp / FoV;
 	fv1.z = farp;
 
 	fv2.x = left * farp / FoV;
 	fv2.y = bottom * farp / FoV;
 	fv2.z = farp;
 
 	fv3.x = right * farp / FoV;
 	fv3.y = top * farp / FoV;
 	fv3.z = farp;
 
 	fv4.x = right * farp / FoV;
 	fv4.y = bottom * farp / FoV;
 	fv4.z = farp;
 
 	//Left
 	vector3 edge1 = nv1 - nv2;
 	vector3 edge2 = nv1 - fv1;
 	vector3 normal = edge1.Cross(edge2);
 	float length = normal.Length();
 	normal.Normalize();
 	m_Plane[Frustum::PLANE_LEFT]->SetNormal(normal);
 	m_Plane[Frustum::PLANE_LEFT]->SetDistance(0);
 
 
 	//Right
 	edge1 = nv4 - nv3;
 	edge2 = nv3 - fv3;
 	normal = edge1.Cross(edge2);
 	normal.Normalize();
 	m_Plane[Frustum::PLANE_RIGHT]->SetNormal(normal);
 	m_Plane[Frustum::PLANE_RIGHT]->SetDistance(0);
 
 	//Top
 	edge1 = nv4 - nv2;
 	edge2 = nv2 - fv2;
 	normal = edge2.Cross(edge1);
 	normal.Normalize();
 	m_Plane[Frustum::PLANE_TOP]->SetNormal(normal);
 	m_Plane[Frustum::PLANE_TOP]->SetDistance(0);
 
 	//bottom
 	edge1 = nv3 - nv1;
 	edge2 = nv1 - fv1;
 	normal = edge1.Cross(edge2);
 	normal.Normalize();
 	m_Plane[Frustum::PLANE_BOTTOM]->SetNormal(normal);
 	m_Plane[Frustum::PLANE_BOTTOM]->SetDistance(0);
 
 	m_Plane[Frustum::PLANE_NEAR]->SetNormal(vector3(0, 0, 1));
 	m_Plane[Frustum::PLANE_NEAR]->SetDistance(nearp);
 	m_Plane[Frustum::PLANE_FAR]->SetNormal(vector3(0, 0, -1));
 	m_Plane[Frustum::PLANE_FAR]->SetDistance(-farp);
}
CUniversalJoint::CUniversalJoint(): AxisParams(2)
{
	AxisParams[0].Axis = vector3(0.0f, 0.0f, 1.0f);
	AxisParams[1].Axis = vector3(0.0f, 1.0f, 0.0f);
}
Exemple #7
0
void AppClass::InitVariables(void)
{
	//Set the camera position
	m_pCameraMngr->SetPositionTargetAndView(
		vector3(0.0f, 2.5f, 15.0f),//Camera position
		vector3(0.0f, 2.5f, 0.0f),//What Im looking at
		REAXISY);//What is up
	m_pCameraMngr->SetCameraMode(CAMERAMODE::CAMROTHOZ);

	//Instance objects to display the game elements
	m_pMeshMngr->InstanceSphere(0.3f, 5, RERED, "Ball");

	m_pMeshMngr->InstanceCuboid(vector3(20, 1, 1), REPURPLE, "BoxT");
	m_pMeshMngr->InstanceCuboid(vector3(20, 1, 1), REPURPLE, "BoxB");
	m_pMeshMngr->InstanceCuboid(vector3(1, 11, 1), REGREEN, "BoxL");
	m_pMeshMngr->InstanceCuboid(vector3(1, 11, 1), REGREEN, "BoxR");
	
	m_pMeshMngr->InstanceCuboid(vector3(0.5, 3, 0.5), REBLUE, "PalletL");
	m_pMeshMngr->InstanceCuboid(vector3(0.5, 3, 0.5), REBLUE, "PalletR");

	//Create game objects based on the loaded objects
	m_pBall = new MyEntityClass("Ball");
	
	m_pBoxT = new MyEntityClass("BoxT");
	m_pBoxB = new MyEntityClass("BoxB");
	m_pBoxL = new MyEntityClass("BoxL");
	m_pBoxR = new MyEntityClass("BoxR");

	m_pPalletL = new MyEntityClass("PalletL");
	m_pPalletR = new MyEntityClass("PalletR");

	//Set properties of the objects
	m_pBall->SetVelocity(vector3(0.11f, 0.11f, 0.0f));

	m_pBoxT->SetModelMatrix(glm::translate(vector3(0, 5, 0)));
	m_pBoxB->SetModelMatrix(glm::translate(vector3(0, -5, 0)));
	m_pBoxR->SetModelMatrix(glm::translate(vector3(10.5, 0, 0)));
}
void AppClass::ProcessKeyboard(void)
{
	bool bModifier = false;
	float fSpeed = 0.01f;

#pragma region ON PRESS/RELEASE DEFINITION
	static bool	bLastF1 = false, bLastF2 = false, bLastF3 = false, bLastF4 = false, bLastF5 = false,
				bLastF6 = false, bLastF7 = false, bLastF8 = false, bLastF9 = false, bLastF10 = false,
				bLastEscape = false;
#define ON_KEY_PRESS_RELEASE(key, pressed_action, released_action){  \
			bool pressed = sf::Keyboard::isKeyPressed(sf::Keyboard::key);			\
			if(pressed){											\
				if(!bLast##key) pressed_action;}/*Just pressed? */\
			else if(bLast##key) released_action;/*Just released?*/\
			bLast##key = pressed; } //remember the state
#pragma endregion

#pragma region Modifiers
	if(sf::Keyboard::isKeyPressed(sf::Keyboard::LShift) || sf::Keyboard::isKeyPressed(sf::Keyboard::RShift))
		bModifier = true;
#pragma endregion

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::R))
	{
		m_v3Orientation = vector3(0.0f);
		something = quaternion(vector3(0.0f, 0.0f, 0.0f));
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::X))
	{
		if (!bModifier) {
			m_v3Orientation.x += 1.0f;
			something = something * quaternion(vector3(PI * 0.01f, 0, 0));
		}
		else {
			m_v3Orientation.x -= 1.0f;
			something = something * quaternion(-vector3(PI * 0.01f, 0, 0));
		}
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Y))
	{
		if (!bModifier) {
			m_v3Orientation.y += 1.0f;
			something = something * quaternion(vector3(PI * 0.01f, 0, 0));
		}
		else {
			m_v3Orientation.y -= 1.0f;
			something = something * quaternion(-vector3(0.0f, -PI * 0.01f, 0));
		}
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z))
	{
		if (!bModifier) {
			m_v3Orientation.z += 1.0f;
			something = something * quaternion(vector3(PI * 0.01f, 0, 0));
		}
		else {
			m_v3Orientation.z -= 1.0f;
			something = something * quaternion(-vector3(0, 0, -PI * 0.01f));
		}
	}

#pragma region Camera Positioning
	if(bModifier)
		fSpeed *= 10.0f;
	if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
		m_pCameraMngr->MoveForward(fSpeed);

	if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
		m_pCameraMngr->MoveForward(-fSpeed);
	
	if(sf::Keyboard::isKeyPressed(sf::Keyboard::A))
		m_pCameraMngr->MoveSideways(-fSpeed);

	if(sf::Keyboard::isKeyPressed(sf::Keyboard::D))
		m_pCameraMngr->MoveSideways(fSpeed);
	m_pCameraMngr->CalculateView();
#pragma endregion

#pragma region Other Actions
	ON_KEY_PRESS_RELEASE(Escape, NULL, PostMessage(m_pWindow->GetHandler(), WM_QUIT, NULL, NULL))
#pragma endregion
}
Exemple #9
0
vector3 vector3::sym(vector3 v1)//V关于N的对称就是2(N*V)*N-V
{
	double k=2*(this->x*v1.x+this->y*v1.y+this->z*v1.z)/(v1.x*v1.x+v1.y*v1.y+v1.z*v1.z);
	return vector3(v1.x*k-this->x,v1.y*k-this->y,v1.z*k-this->z);
}
Exemple #10
0
  bool XSFFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
  {

    OBMol* pmol = pOb->CastAndClear<OBMol>();
    if(pmol==NULL)
      return false;

    //Define some references so we can use the old parameter names
    istream &ifs = *pConv->GetInStream();
    OBMol &mol = *pmol;
    const char* title = pConv->GetTitle();

    char buffer[BUFF_SIZE];
    string str;
    double x,y,z;
    OBAtom *atom;
    vector3 translationVectors[3];
    int numTranslationVectors = 0;
    vector<string> vs;
    vector<vector3> atomPositions;
    bool createdAtoms = false;
    int atomicNum;

    mol.BeginModify();

    while (ifs.getline(buffer, BUFF_SIZE))
      {
        if (buffer[0] == '#')
          continue; // comment
        if (strstr(buffer, "ATOMS") != NULL) {
          // Minimum of 4 columns -- AtNum, x, y, z (forces)
          // where AtNum stands for atomic number (or symbol), while X Y Z are
          ifs.getline(buffer, BUFF_SIZE);
          tokenize(vs, buffer);
          while (vs.size() >= 4) {
            if (!createdAtoms) {
              atom = mol.NewAtom();
              //set atomic number
              atomicNum = OBElements::GetAtomicNum(vs[0].c_str());
              if (atomicNum == 0) {
                atomicNum = atoi(vs[0].c_str());
              }
              atom->SetAtomicNum(atomicNum);
            }
            x = atof((char*)vs[1].c_str());
            y = atof((char*)vs[2].c_str());
            z = atof((char*)vs[3].c_str());
            atomPositions.push_back(vector3(x, y, z)); // we may have a movie or animation

            ifs.getline(buffer, BUFF_SIZE);
            tokenize(vs, buffer);
          }
          createdAtoms = true; // don't run NewAtom() anymore
        }
        else if ( strstr(buffer, "PRIMVEC")
                 || strstr(buffer, "CONVVEC") ) {
          // translation vectors
          numTranslationVectors = 0; // if we have an animation
          while (numTranslationVectors < 3 && ifs.getline(buffer,BUFF_SIZE)) {
            tokenize(vs,buffer); // we really need to check that it's 3 entries only
            if (vs.size() < 3) return false; // timvdm 18/06/2008
            x = atof((char*)vs[0].c_str());
            y = atof((char*)vs[1].c_str());
            z = atof((char*)vs[2].c_str());
            translationVectors[numTranslationVectors++].Set(x, y, z);
          }
        }
        else if (strstr(buffer, "PRIMCOORD") != NULL) {
          // read the coordinates
          ifs.getline(buffer, BUFF_SIZE);
          tokenize(vs, buffer);
          if (vs.size() < 2) return false;
          int numAtoms = atoi(vs[0].c_str());
          for (int a = 0; a < numAtoms; ++a) {
            if (!ifs.getline(buffer,BUFF_SIZE))
              break;
            tokenize(vs,buffer);
            if (vs.size() < 4)
              break;

            if (!createdAtoms) {
              atom = mol.NewAtom();
              //set atomic number
              atomicNum = OBElements::GetAtomicNum(vs[0].c_str());
              if (atomicNum == 0) {
                atomicNum = atoi(vs[0].c_str());
              }
              atom->SetAtomicNum(atomicNum);
            }
            x = atof((char*)vs[1].c_str());
            y = atof((char*)vs[2].c_str());
            z = atof((char*)vs[3].c_str());
            atomPositions.push_back(vector3(x, y, z));
          }
        }
      }

    mol.EndModify();

    int natom = mol.NumAtoms();
    int numConformers = atomPositions.size() / natom;
    for (int i = 0; i < numConformers; ++i) {
      double *coordinates = new double[natom * 3];
      for (int j = 0; j < natom; ++j) {
        vector3 currentPosition = atomPositions[i*natom + j];
        coordinates[j*3] = currentPosition.x();
        coordinates[j*3 + 1] = currentPosition.y();
        coordinates[j*3 + 2] = currentPosition.z();
      }
      mol.AddConformer(coordinates);
    }
    // Delete first conformer, created by EndModify, bunch of 0s
    mol.DeleteConformer(0);
    // Set geometry to last one
    mol.SetConformer(mol.NumConformers() - 1);

    if (!pConv->IsOption("b",OBConversion::INOPTIONS))
      mol.ConnectTheDots();
    if (!pConv->IsOption("s",OBConversion::INOPTIONS) && !pConv->IsOption("b",OBConversion::INOPTIONS))
      mol.PerceiveBondOrders();

    // Add final properties
    mol.SetTitle(title);
    if (numTranslationVectors == 3) {
      OBUnitCell *uc = new OBUnitCell;
      uc->SetOrigin(fileformatInput);
      uc->SetData(translationVectors[0],
                  translationVectors[1],
                  translationVectors[2]);
      mol.SetData(uc);
    }

    return(true);
  }
Exemple #11
0
	vector3 rotate_vector( vector3 const& v, quat const& q )
	{
		quat p = quat(v.x(), v.y(), v.z(), 0);
		quat tp = q * p * q.inverse();
		return vector3(tp.qx(), tp.qy(), tp.qz());
	}
void AppClass::Update(void)
{
	//Sets the camera
	m_pCameraMngr->SetPositionTargetAndView(vector3(0.0f, 25.0f, 0.0f), vector3(0.0f, 0.0f, 0.0f), -REAXISZ);

	//Update the system's time
	m_pSystem->UpdateTime();

	//Update the mesh manager's time without updating for collision detection
	m_pMeshMngr->Update();

	//First person camera movement
	if (m_bFPC == true)
		CameraRotation();

	//Call the arcball method
	ArcBall();

	//Adds all loaded instance to the render list
	m_pMeshMngr->AddInstanceToRenderList("ALL");

	//This matrices will just orient the objects to the camera
	matrix4 rotateX = glm::rotate(IDENTITY_M4, 90.0f, vector3(1.0f, 0.0f, 0.0f));
	matrix4 rotateY = glm::rotate(IDENTITY_M4, 90.0f, vector3(0.0f, 1.0f, 0.0f));

	//This matrices will hold the relative transformation of the Moon and the Earth
	matrix4 distanceEarth = glm::translate(11.0f, 0.0f, 0.0f);
	matrix4 distanceMoon = glm::translate(2.0f, 0.0f, 0.0f);

	//Earth's orbit around the Sun
	matrix4 orbitEarth = glm::rotate(IDENTITY_M4, m_fEarthTimer, vector3(0.0f, 1.0f, 0.0f));
	//Earth's rotation on its own axis
	matrix4 rotationEarth = glm::rotate(IDENTITY_M4, m_fEarthTimer * 28.0f, vector3(0.0f, 1.0f, 0.0f));

	//Moon's orbit around the Earth
	matrix4 orbitMoon = glm::rotate(IDENTITY_M4, m_fMoonTimer, vector3(0.0f, -1.0f, 0.0f));
	//Moon's rotation around its own axis
	matrix4 rotationMoon = glm::rotate(IDENTITY_M4, m_fMoonTimer, vector3(0.0f, 1.0f, 0.0f));

	//I will calculate the Earth position in space relative to the Sun (which is in global space)
	matrix4 earthsSpace = orbitEarth * distanceEarth;//the translation depends on the orientation of the space (Earths orbit)
	m_m4Earth = earthsSpace * rotationEarth;//the rotation of the Earth will depend on the new space
	m_m4Earth = m_m4Earth * rotateX;//Will orient the Earth to the camera now

	//I will calculate the moon's position in space relative to the Earth (earthsSpace)
	matrix4 moonsSpace = orbitMoon * distanceMoon;//the moon's translation depends on its orientation (Moons orbit)
	m_m4Moon = earthsSpace * moonsSpace;//Then we place the moons space in therms of the earth space
	m_m4Moon = m_m4Moon * rotateY * rotateX;//Then we orient the Moon to the camera)

	printf("Earth Day: %.3f, Moon Day: %.3f\r", m_fEarthTimer, m_fMoonTimer);//print the Frames per Second

	//Indicate the FPS
	int nFPS = m_pSystem->GetFPS();
	//Print info on the screen
	m_pMeshMngr->PrintLine(m_pSystem->GetAppName(), REYELLOW);
	m_pMeshMngr->Print("Earth Day: ", REWHITE);
	m_pMeshMngr->PrintLine(std::to_string(m_fEarthTimer), REBLUE);
	m_pMeshMngr->Print("Moon Day: ", REWHITE);
	m_pMeshMngr->PrintLine(std::to_string(m_fMoonTimer), REBLUE);
	m_pMeshMngr->Print("FPS:");
	m_pMeshMngr->Print(std::to_string(nFPS), RERED);

	m_fMoonTimer++;//Increase moon timer
	m_fEarthTimer = m_fMoonTimer / 28.0f; //divide by the moon's day
}
glm::mat4 Camera::GetView()
{
    return glm::lookAt(vector3(position.x, position.y, position.z),
        vector3(target.x, target.y, target.z),
        vector3(up.x, up.y, up.z));
}
//	dir3D conversions to/from different RHCoordSyst3's
vector3	dirWCStoLCS(vector3 vDir1, RHCoordSys3 LCS)
{
	normalize(vDir1);
	return vector3(dot(vDir1,LCS[0]),dot(vDir1,LCS[1]),dot(vDir1,LCS[2]));
}
void ApplicationClass::GenerateBoundingBox(matrix4 a_mModelToWorld, String a_sInstanceName)
{
	if(m_pMeshMngr->IsInstanceCreated(a_sInstanceName))
	{
		static bool bInitialized = false;
		static vector3 vCenterPoint;
		static float fDistance;
		if(!bInitialized)
		{
			std::vector<vector3> lVertices = m_pMeshMngr->m_pModelMngr->GetVertices(a_sInstanceName);
			unsigned int nVertices = lVertices.size();
			vCenterPoint = lVertices[0];
			vector3 v3Max(lVertices[0]);
			vector3 v3Min(lVertices[0]);
			for(unsigned int nVertex = 1; nVertex < nVertices; nVertex++)
			{
				//m_v3Centroid += lVertices[nVertex];
				if(v3Min.x > lVertices[nVertex].x)
					v3Min.x = lVertices[nVertex].x;
				else if(v3Max.x < lVertices[nVertex].x)
					v3Max.x = lVertices[nVertex].x;
			
				if(v3Min.y > lVertices[nVertex].y)
					v3Min.y = lVertices[nVertex].y;
				else if(v3Max.y < lVertices[nVertex].y)
					v3Max.y = lVertices[nVertex].y;

				if(v3Min.z > lVertices[nVertex].z)
					v3Min.z = lVertices[nVertex].z;
				else if(v3Max.z < lVertices[nVertex].z)
					v3Max.z = lVertices[nVertex].z;
			}
			vCenterPoint = (v3Min + v3Max) / 2.0f;

			m_pMeshMngr->AddAxisToQueue(a_mModelToWorld * glm::translate(vCenterPoint));

			fDistance = glm::distance(vCenterPoint, lVertices[0]);
			for(unsigned int nVertex = 1; nVertex < nVertices; nVertex++)
			{
				float fDistanceNew = glm::distance(vCenterPoint, lVertices[nVertex]);
				if(fDistance < fDistanceNew)
					fDistance = fDistanceNew;
			}

			bInitialized = true;
		}
		m_pMeshMngr->AddCubeToQueue(a_mModelToWorld * glm::translate(vCenterPoint) * glm::scale(vector3(fDistance * 2.0f)), MERED, MERENDER::WIRE);
	}
}
Exemple #16
0
vector3 vector3::operator*(double t)
{
	return vector3(x*t,y*t,z*t);
}
void ApplicationClass::Update (void)
{
	m_pSystem->UpdateTime(); //Update the system

	m_pMeshMngr->Update(); //Updates the mesh information

	float fTimeSpan = m_pSystem->StopClock(); //Check the time difference between this method calls
	static float fRunTime = 0.0f;

	fRunTime += fTimeSpan; //update the run time count
	//matrix4 m4Steve = glm::rotate(matrix4(IDENTITY), fRunTime * 15, vector3( 0.0f,-1.0f, 0.0f));
	matrix4 m4Steve = glm::translate(vector3( 0.0f,0.0f, 0.0f));
	matrix4 m4Zombie = glm::translate(vector3(-6.0f, 0.0f, 0.0f));
	matrix4 m4Cow = glm::translate(vector3(-3.0f, 0.0f, 0.0f));
	matrix4 m4Pig = glm::translate(vector3(6.0f, 0.0f, 0.0f));
	
	m_pMeshMngr->SetModelMatrix(m4Steve, "Steve");
	m_pMeshMngr->SetModelMatrix(m_m4Creeper, "Creeper");
	m_pMeshMngr->SetModelMatrix(m4Pig, "Pig");
	m_pMeshMngr->SetModelMatrix(m4Zombie, "Zombie");
	m_pMeshMngr->SetModelMatrix(m4Cow, "Cow");

#pragma region Method
	//GenerateBoundingBox(mA,"A");
#pragma endregion

#pragma region Bounding Box Class
	//pBoundingBox1->GenerateBoundingBox("Steve");
	//pBoundingBox2->GenerateBoundingBox("Creeper");
	
	//pBoundingBox1->AddBoxToRenderList(m4Steve, MEYELLOW, true);
	//pBoundingBox2->AddBoxToRenderList(m_m4Creeper, MEYELLOW, true);
#pragma endregion

#pragma region Bounding Box Manager
	m_pBSMngr->GenerateBoundingBox("Steve");
	m_pBSMngr->GenerateBoundingBox("Creeper");
	m_pBSMngr->GenerateBoundingBox("Cow");
	m_pBSMngr->GenerateBoundingBox("Zombie");
	m_pBSMngr->GenerateBoundingBox("Pig");

	m_pBSMngr->SetBoundingBoxSpace(m4Steve, "Steve");
	m_pBSMngr->SetBoundingBoxSpace(m_m4Creeper, "Creeper");
	m_pBSMngr->SetBoundingBoxSpace(m4Cow, "Cow");
	m_pBSMngr->SetBoundingBoxSpace(m4Pig, "Pig");
	m_pBSMngr->SetBoundingBoxSpace(m4Zombie, "Zombie");

	m_pBSMngr->CalculateCollision();

	m_pBSMngr->AddBoxToRenderList("ALL");
#pragma endregion

	m_pMeshMngr->AddInstanceToRenderList();
	
	//First person camera movement
	if(m_bFPC == true)
		CameraRotation();

	m_pCamera->PrintInfo();

	printf("FPS: %d\r", m_pSystem->FPS);//print the Frames per Second
}
Exemple #18
0
vector3 vector3::operator-(vector3 t)
{
	return vector3(x-t.x,y-t.y,z-t.z);
}
Exemple #19
0
	Intersection Cylindre::intersect(Rayon* r)
{
	Intersection inter;
	double a;
	double b;
	double c;
	double delta;
	double t, t1, t2;

	/* equation du Cylindre y²+z²=rayon² avec 0<x<longueur=height
	 * (dy.t+py)²+(dz.t+pz)²=rayon²
	 * (dy²+dz²)t²+(dy.py+dz.pz)t+(py²+pz²-rayon²)=0
	 * at²+bt+c=0
	 */
	 
	 inter.setObjet(this);
  
	 a=pow(r->getDirection().y,2)+pow(r->getDirection().z,2);
	 b=(r->getDirection().y*r->getPosition().y)+(r->getDirection().z*r->getPosition().z);
	 c=pow(r->getPosition().y,2)+pow(r->getPosition().z,2)-pow(this->r,2);
	 //calcul du discriminant
	 delta = pow(b,2)-4*a*c;
	 
  if (delta <= 0) {
	  inter.setDistance(DBL_MAX); //distance infinie (pas d'intersection)
	//si py²+pz²-rayon²<=0 ou c<0
	//on se situe sur l'alignement du cylindre
	  if(c<0){
		  if( (this->height!=0) 
			  && (r->getPosition().x>this->height 
			  || (r->getPosition().x>=0.0 && r->getPosition().x<this->height))){

				  if(r->getDirection().x!=0.0){
					  t = (this->height-r->getPosition().x)/r->getDirection().x;
					  inter.setPoint( vector3(this->height,
						  t * r->getDirection().y + r->getPosition().y,
						  t * r->getDirection().z + r->getPosition().z) );
					  if(t>EPSILON && c<=0){
						  inter.setDistance ( (inter.getPoint()-r->getPosition()).Length() );
					  }else{
						  inter.setDistance(DBL_MAX);
					  }
				  }else{
					  inter.setDistance ( DBL_MAX );
				  }
		  }
			
		  if( (this->height!=0) 
			  && (r->getPosition().x<this->height 
			  || (r->getPosition().x>0.0 && r->getPosition().x<=this->height))){
				  if(r->getDirection().x!=0.0){
					  t = (-r->getPosition().x)/r->getDirection().x;
					  inter.setPoint(vector3(0.0,
						  t * r->getDirection().y + r->getPosition().y,
						  t * r->getDirection().z + r->getPosition().z) );
					  if(t>EPSILON && c<=0){
						  inter.setDistance ( (inter.getPoint()-r->getPosition()).Length() );
					  }else{
						  inter.setDistance(DBL_MAX);
					  }
				  }else{
					  inter.setDistance(DBL_MAX);
				  }
		  }
	  }

     }else{ //deux solutions

      t1 = (-b + sqrt (delta)) / 2*a;
      t2 = (-b - sqrt (delta)) / 2*a;

      if (t1 <= EPSILON && t2 <= EPSILON){
	    inter.setDistance(DBL_MAX);
	  }else{

	  if ((t1 <= t2 && t1 > EPSILON) || (t2 < t1 && t2 < EPSILON)){
	    t = t1;
	  }else if ((t2 < t1 && t2 > EPSILON) || (t1 < t2 && t1 < EPSILON)){
	    t = t2;
	  }

	  inter.setPoint(vector3(t * r->getDirection().x + r->getPosition().x,
							 t * r->getDirection().x + r->getPosition().x,
						     t * r->getDirection().z + r->getPosition().z));

	  inter.setDistance ( (inter.getPoint()-r->getPosition()).Length() );

	  if( (this->height!=0) && (inter.getPoint().x>this->height)
			  || (r->getPosition().x>this->height && c<=0)){
				  if(r->getDirection().x!=0.0){
					  t = (this->height-r->getPosition().x)/r->getDirection().x;
					  inter.setPoint(vector3(this->height,
						  t * r->getDirection().y + r->getPosition().y,
						  t * r->getDirection().z + r->getPosition().z) );
					  if(t>EPSILON && c<=0){
						  inter.setDistance ( (inter.getPoint()-r->getPosition()).Length() );
					  }else{
						  inter.setDistance(DBL_MAX);
					  }
				  }else{
					 inter.setDistance(DBL_MAX);
				  }
		  }
			
		  if( (this->height!=0) 
			  && (inter.getPoint().x<0.0) 
			  || (r->getPosition().x<0.0 && c<=0)){
				  if(r->getDirection().x!=0.0){
					  t = (-r->getPosition().x)/r->getDirection().x;
					  inter.setPoint(vector3(0.0,
						  t * r->getDirection().y + r->getPosition().y,
						  t * r->getDirection().z + r->getPosition().z)  );
					  if(t>EPSILON){
						  inter.setDistance ( (inter.getPoint()-r->getPosition()).Length() );
					  }else{
						  inter.setDistance(DBL_MAX);
					  }
				  }else{
					  inter.setDistance(DBL_MAX);
				  }
		  }
	  }
  }
		
	  	 //TODO: la normale 
	    return (inter);
  }
Exemple #20
0
vector3 vector3::operator+(vector3 t)
{
	return vector3(x+t.x,y+t.y,z+t.z);
}
void CCharEntity::OnStepBefore()
{
	if (IsCollisionEnabled() && !IsRagdollActive())
	{
		CEnvInfo EnvInfo;
		vector3 Pos = GetTransform().pos_component();
		Pos.y += Height;

		float DistanceToGround;
		if (EnvQueryMgr->GetEnvInfoAt(Pos, EnvInfo, Height + 0.1f, GetUniqueID()))
		{
			DistanceToGround = Pos.y - Height - EnvInfo.WorldHeight;
			GroundMtl = EnvInfo.Material;
		}
		else
		{
			DistanceToGround = FLT_MAX;
			GroundMtl = InvalidMaterial;
		}

		CRigidBody* pMasterBody = Composite->GetMasterBody();
		bool BodyIsEnabled = IsEnabled();
		vector3 AngularVel = pMasterBody->GetAngularVelocity();
		vector3 LinearVel = pMasterBody->GetLinearVelocity();
		vector3 DesiredLVelChange = DesiredLinearVel - LinearVel;

 		if (DistanceToGround <= 0.f)
		{
			// No torques now, angular velocity changes by impulse immediately to desired value
			bool Actuated = DesiredAngularVel != AngularVel.y;
			if (Actuated)
			{
				if (!BodyIsEnabled) SetEnabled(true);
				pMasterBody->SetAngularVelocity(vector3(0.f, DesiredAngularVel, 0.f));
			}

			if (!DesiredLVelChange.isequal(vector3::Zero, 0.0001f))
			{
				if (!Actuated)
				{
					Actuated = true;
					SetEnabled(true);
				}

				// Vertical movement for non-flying actors is impulse (jump).
				// Since speed if already clamped to actor caps, we save vertical desired velocity as is.
				// Spring force pushes us from below the ground.
				
				//!!!!!!!!!!!!!!!
				//!!!calc correct impulse for the spring!
				//!!!!!!!!!!!!!!!
				
				float VerticalDesVelChange = DesiredLVelChange.y - (50.0f * DistanceToGround);

				float Mass = pMasterBody->GetMass();

				//!!!remove calcs for Y, it is zero (optimization)!
				dVector3 ODEForce;
				dWorldImpulseToForce(Level->GetODEWorldID(), dReal(Level->GetStepSize()),
					DesiredLVelChange.x * Mass, 0.f, DesiredLVelChange.z * Mass, ODEForce);
				float SqForceMagnitude = (float)dCalcVectorLengthSquare3(ODEForce);
				if (SqForceMagnitude > 0.f)
				{
					float MaxForceMagnitude = Mass * MaxHorizAccel;
					float SqMaxForceMagnitude = MaxForceMagnitude * MaxForceMagnitude;
					if (SqForceMagnitude > SqMaxForceMagnitude)
						dScaleVector3(ODEForce, MaxForceMagnitude / n_sqrt(SqForceMagnitude));
					dBodyAddForce(pMasterBody->GetODEBodyID(), ODEForce[0], ODEForce[1], ODEForce[2]);
				}
				
				if (VerticalDesVelChange != 0.f)
				{
					dWorldImpulseToForce(Level->GetODEWorldID(), dReal(Level->GetStepSize()),
						0.f, VerticalDesVelChange * Mass, 0.f, ODEForce);
					dBodyAddForce(pMasterBody->GetODEBodyID(), ODEForce[0], ODEForce[1], ODEForce[2]);
				}
			}

			if (BodyIsEnabled && !Actuated && DistanceToGround > -0.002f)
			{
				const float FreezeThreshold = 0.00001f; //???use TINY?

				bool AVelIsAlmostZero = n_fabs(AngularVel.y) < FreezeThreshold;
				bool LVelIsAlmostZero = n_fabs(LinearVel.x) * (float)Level->GetStepSize() < FreezeThreshold &&
										n_fabs(LinearVel.z) * (float)Level->GetStepSize() < FreezeThreshold;

				if (AVelIsAlmostZero)
					pMasterBody->SetAngularVelocity(vector3::Zero);

				if (LVelIsAlmostZero)
					pMasterBody->SetLinearVelocity(vector3::Zero);

				if (AVelIsAlmostZero && LVelIsAlmostZero) SetEnabled(false);
			}
		}
		//???!!!else (when falling) apply damping?!
	}
	// NOTE: do NOT call the parent class, we don't need any damping
}
Exemple #22
0
vector3 vector3::cross(vector3 t)//可能有叉乘出的方向问题
{
	return vector3(y*t.z-z*t.y,z*t.x-x*t.z,x*t.y-y*t.x);
}
void AppClass::ProcessKeyboard(void)
{
	bool bModifier = false;
	float fSpeed = 0.01f;

#pragma region ON_KEY_PRESS_RELEASE
	static bool	bLastF1 = false, bLastF2 = false, bLastF3 = false, bLastF4 = false, bLastF5 = false,
				bLastF6 = false, bLastF7 = false, bLastF8 = false, bLastF9 = false, bLastF10 = false,
				bLastEscape = false, bLastF = false;
#define ON_KEY_PRESS_RELEASE(key, pressed_action, released_action){  \
			bool pressed = sf::Keyboard::isKeyPressed(sf::Keyboard::key);			\
			if(pressed){											\
				if(!bLast##key) pressed_action;}/*Just pressed? */\
			else if(bLast##key) released_action;/*Just released?*/\
			bLast##key = pressed; } //remember the state
#pragma endregion

#pragma region Modifiers
	if(sf::Keyboard::isKeyPressed(sf::Keyboard::LShift) || sf::Keyboard::isKeyPressed(sf::Keyboard::RShift))
		bModifier = true;
#pragma endregion

#pragma region Camera Positioning
	if(bModifier)
		fSpeed *= 10.0f;
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
		m_pCameraMngr->MoveForward(fSpeed);
		CameraManager->MoveForward(fSpeed);
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
		m_pCameraMngr->MoveForward(-fSpeed);
		CameraManager->MoveForward(-fSpeed);
	}
	
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
		m_pCameraMngr->MoveSideways(-fSpeed);
		CameraManager->MoveHorizontal(-fSpeed);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
		m_pCameraMngr->MoveSideways(fSpeed);
		CameraManager->MoveHorizontal(fSpeed);
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q)) {
		m_pCameraMngr->MoveVertical(-fSpeed);
		CameraManager->MoveVertical(fSpeed);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::E)) {
		m_pCameraMngr->MoveVertical(fSpeed);
		CameraManager->MoveVertical(-fSpeed);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::X)) {
		CameraManager->ChangePitch(fSpeed);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z)) {
		CameraManager->ChangeRoll(fSpeed);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Y)) {
		CameraManager->ChangeYaw(fSpeed);
	}
#pragma endregion

#pragma region Model Positioning
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::X))
	{
		if (!bModifier)
			m_v3Rotation += vector3( 1.0f, 0.0f, 0.0f);
		else
			m_v3Rotation += vector3(-1.0f, 0.0f, 0.0f);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Y))
	{
		if (!bModifier)
			m_v3Rotation += vector3( 0.0f, 1.0f, 0.0f);
		else
			m_v3Rotation += vector3( 0.0f,-1.0f, 0.0f);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z))
	{
		if (!bModifier)
			m_v3Rotation += vector3(0.0f, 0.0f, 1.0f);
		else
			m_v3Rotation += vector3(0.0f, 0.0f,-1.0f);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::R))
	{
		m_v3Rotation = vector3(0.0f, 0.0f, 0.0f);
	}
#pragma endregion

#pragma region Other Actions
	ON_KEY_PRESS_RELEASE(Escape, NULL, PostMessage(m_pWindow->GetHandler(), WM_QUIT, NULL, NULL));
	ON_KEY_PRESS_RELEASE(F1, NULL, m_pCameraMngr->SetCameraMode(CAMPERSP));
	ON_KEY_PRESS_RELEASE(F2, NULL, m_pCameraMngr->SetCameraMode(CAMROTHOZ));
	ON_KEY_PRESS_RELEASE(F3, NULL, m_pCameraMngr->SetCameraMode(CAMROTHOY));
	ON_KEY_PRESS_RELEASE(F4, NULL, m_pCameraMngr->SetCameraMode(CAMROTHOX));
	static bool bFPSControll = false;
	ON_KEY_PRESS_RELEASE(F, bFPSControll = !bFPSControll, m_pCameraMngr->SetFPS(bFPSControll));
#pragma endregion
}
Exemple #24
0
void bigTree::subdivideTree(MeshManagerSingleton* m_pMeshMngr, std::vector<BoundingObjectClass*> objectsList)
{
	//Recursively divides the space in the world
	//Might as well check for collisions here, too
	//They only collide if they are in the same box

	for(std::size_t i = 0; i < objectsList.size(); i++){
		if (objectsList[i]->IsColliding(*octBO))
		{
			objectsInside.push_back(objectsList[i]);
		}
	}

	if (objectsInside.size() == maxObjects)
	{
		isLeaf = true;
	}

	else if (objectsInside.size() > maxObjects)
	{
		if (treeLevel < maxLevels && isLeaf == false)
		{
			vector3 childCentroid;
			float childSize = octSize/4.0f;

			//I believe collision calls would be made in here?
			for (int i = 0; i < 8; i++)
			{
				childCentroid = centroid;
				
				//	  Front
				//	---------
				//	| 3 | 2 |
				//	---------
				//	| 0 | 1 |
				//	---------  
				
				if(i == 0){
					childCentroid += vector3(-childSize, -childSize, childSize);
				}
				else if(i == 1){
					childCentroid += vector3(childSize, -childSize, childSize);
				}
				else if(i == 2){
					childCentroid += vector3(childSize, childSize, childSize); 
				}
				else if(i == 3){
					childCentroid += vector3(-childSize, childSize, childSize);
				}

				//	  Back
				//	---------
				//	| 7 | 6 |
				//	---------
				//	| 4 | 5 |
				//	---------	
				
				else if(i == 4){
					childCentroid += vector3(-childSize, -childSize, -childSize);
				}
				else if(i == 5){
					childCentroid += vector3(childSize, -childSize, -childSize);
				}
				else if(i == 6){
					childCentroid += vector3(childSize, childSize, -childSize);
				}
				else if(i == 7){
					childCentroid += vector3(-childSize, childSize, -childSize);
				}

				children[i] = new bigTree(m_pMeshMngr, objectsInside, treeLevel + 1, octID + i, childCentroid, childSize * 2.0f);
			}
		}
	}
}
Exemple #25
0
GLuint createSpherePositions() {
    int nfloats = sphereAttributeCount(n)*3; // number of floats in the buffer
    int bufferSize = nfloats*sizeof(float);
    positions = (float*) malloc(bufferSize);
    float* p = positions;
    GLuint spherePositionsId;

    //
    // we refine each side of an octahedron
    // cf http://paulbourke.net/miscellaneous/sphere_cylinder/
    //
    refine(0, triangle(vector3(0.0f, 1.0f, 0.0f), vector3(0.0f, 0.0f, 1.0f), vector3(1.0f, 0.0f, 0.0f)), &p);
    refine(0, triangle(vector3(0.0f, 1.0f, 0.0f), vector3(1.0f, 0.0f, 0.0f), vector3(0.0f, 0.0f, -1.0f)), &p);
    refine(0, triangle(vector3(0.0f, 1.0f, 0.0f), vector3(0.0f, 0.0f, -1.0f), vector3(-1.0f, 0.0f, 0.0f)), &p);
    refine(0, triangle(vector3(0.0f, 1.0f, 0.0f), vector3(-1.0f, 0.0f, 0.0f), vector3(0.0f, 0.0f, 1.0f)), &p);
    refine(0, triangle(vector3(0.0f, -1.0f, 0.0f), vector3(1.0f, 0.0f, 0.0f), vector3(0.0f, 0.0f, 1.0f)), &p);
    refine(0, triangle(vector3(0.0f, -1.0f, 0.0f), vector3(0.0f, 0.0f, 1.0f), vector3(-1.0f, 0.0f, 0.0f)), &p);
    refine(0, triangle(vector3(0.0f, -1.0f, 0.0f), vector3(-1.0f, 0.0f, 0.0f), vector3(0.0f, 0.0f, -1.0f)), &p);
    refine(0, triangle(vector3(0.0f, -1.0f, 0.0f), vector3(0.0f, 0.0f, -1.0f), vector3(1.0f, 0.0f, 0.0f)), &p);

    glGenBuffers(1, &spherePositionsId);
    glBindBuffer(GL_ARRAY_BUFFER, spherePositionsId);
    glBufferData(GL_ARRAY_BUFFER, nfloats*sizeof(float), positions, GL_STATIC_DRAW);
    //free(positions);
    return spherePositionsId;
}
Exemple #26
0
void bigTree::Render(MeshManagerSingleton* m_pMeshMngr)
{
	m_pMeshMngr->AddCubeToQueue(glm::translate(centroid) * glm::scale(vector3(octSize, octSize, octSize)), MERED, MERENDER::WIRE);
}
Exemple #27
0
vector3 midPoint(vector3 p1, vector3 p2) {
    return vector3((p1.x + p2.x) / 2, (p1.y + p2.y) / 2, (p1.z + p2.z) / 2);
}
Exemple #28
0
void bigTree::createTree(MeshManagerSingleton* m_pMeshMngr, std::vector<BoundingObjectClass*> objectsList, std::vector<float> objectSizes)
{
	vector3 minPos;
	vector3 maxPos;

	minPos = objectsList[0]->GetCentroidGlobal() - objectSizes[0];
	maxPos = objectsList[0]->GetCentroidGlobal() + objectSizes[0];

	for(std::size_t i = 0; i < objectsList.size(); i++){
		if (minPos.x > objectsList[i]->GetCentroidGlobal().x - objectSizes[i]){
			minPos.x = objectsList[i]->GetCentroidGlobal().x - objectSizes[i];
		}
		else if (maxPos.x < objectsList[i]->GetCentroidGlobal().x + objectSizes[i]){
			maxPos.x = objectsList[i]->GetCentroidGlobal().x + objectSizes[i];
		}

		if (minPos.y > objectsList[i]->GetCentroidGlobal().y - objectSizes[i]){
			minPos.y = objectsList[i]->GetCentroidGlobal().y - objectSizes[i];
		}
		else if (maxPos.y < objectsList[i]->GetCentroidGlobal().y + objectSizes[i]){
			maxPos.y = objectsList[i]->GetCentroidGlobal().y + objectSizes[i];
		}

		if (minPos.z > objectsList[i]->GetCentroidGlobal().z - objectSizes[i]){
			minPos.z = objectsList[i]->GetCentroidGlobal().z - objectSizes[i];
		}
		else if (maxPos.z < objectsList[i]->GetCentroidGlobal().z + objectSizes[i]){
			maxPos.z = objectsList[i]->GetCentroidGlobal().z + objectSizes[i];
		}
	}
	
	centroid = (minPos + maxPos) / 2.0f;

	if (octSize < glm::distance(vector3(minPos.x, 0, 0), vector3(maxPos.x, 0, 0))){
		octSize = glm::distance(vector3(minPos.x, 0, 0), vector3(maxPos.x, 0, 0));
	}
	if (octSize < glm::distance(vector3(minPos.y, 0, 0), vector3(maxPos.y, 0, 0))){
		octSize = glm::distance(vector3(minPos.y, 0, 0), vector3(maxPos.y, 0, 0));
	}
	if (octSize < glm::distance(vector3(minPos.z, 0, 0), vector3(maxPos.z, 0, 0))){
		octSize = glm::distance(vector3(minPos.z, 0, 0), vector3(maxPos.z, 0, 0));
	}
	
}
Exemple #29
0
void AppClass::Update(void)
{
	//Update the system's time
	m_pSystem->UpdateTime();

	//Update the mesh manager's time without updating for collision detection
	m_pMeshMngr->Update();

	//First person camera movement
	if (m_bFPC == true)
		CameraRotation();

	//Call the arcball method
	ArcBall();

	//Lets us know how much time has passed since the last call
	double fTimeSpan = m_pSystem->LapClock();

	//cumulative time
	static double fRunTime = 0.0f;
	fRunTime += fTimeSpan;

	static int nIndex = 0;

	if (fRunTime > fDuration)
	{
		fRunTime = 0.0f;
		nIndex++;
		if (nIndex == static_cast<int>(m_lPositions.size()))
		{
			nIndex = 0;
		}
	}

	vector3 v3Vector1;
	vector3 v3Vector2;
	if (nIndex >= static_cast<int>(m_lPositions.size()) - 1)
	{
		v3Vector1 = m_lPositions[static_cast<int>(m_lPositions.size()) - 1];
		v3Vector2 = m_lPositions[0];
	}
	else
	{
		v3Vector1 = m_lPositions[nIndex];
		v3Vector2 = m_lPositions[nIndex + 1];
	}

	float fPercent = MapValue(static_cast<float>(fRunTime), 0.0f, fDuration, 0.0f, 1.0f);
	vector3 v3Position = glm::lerp(v3Vector1, v3Vector2, fPercent);
	m_pMeshMngr->SetModelMatrix(glm::translate(v3Position), "WallEye");

	for (int i = 0; i < static_cast<int>(m_lPositions.size()); i++)
	{
		m_pMeshMngr->AddSphereToRenderList(glm::translate(m_lPositions[i]) * glm::scale(vector3(0.1f)), RERED, SOLID);
	}

	//Adds all loaded instance to the render list
	m_pMeshMngr->AddInstanceToRenderList("ALL");

	//Indicate the FPS
	int nFPS = m_pSystem->GetFPS();
	//print info into the console
	printf("\rfTimeSpan: %.3f, fRunSpan: %.3f, fDuration: %.3f                 ", fTimeSpan, fRunTime, fDuration);
	//Print info on the screen
	m_pMeshMngr->PrintLine(m_pSystem->GetAppName(), REYELLOW);

	m_pMeshMngr->Print("nIndex: ");
	m_pMeshMngr->PrintLine(std::to_string(nIndex));

	m_pMeshMngr->Print("fTimeSpan: ");
	m_pMeshMngr->PrintLine(std::to_string(fTimeSpan));

	m_pMeshMngr->Print("fRunSpan: ");
	m_pMeshMngr->PrintLine(std::to_string(fRunTime));

	m_pMeshMngr->Print("fDuration: ");
	m_pMeshMngr->PrintLine(std::to_string(fDuration));

	m_pMeshMngr->Print("FPS:");
	m_pMeshMngr->Print(std::to_string(nFPS), RERED);
}
matrix4 MyCameraSingleton::GetCameraPlane(void)
{
	SystemSingleton* pSystem = SystemSingleton::GetInstance();
	float fSize = pSystem->GetWindowWidth() / static_cast<float>(pSystem->GetWindowHeight());
	return GetCameraSpaceAdjusted() * glm::translate(vector3(0.0f, 0.0f, -1.2085f)) * glm::scale(vector3(fSize, 1.0f, 0.0f));
}