Пример #1
0
  inline Vector3D cross(const Vector3D &va, const Vector3D &vb) {
    return Vector3D(va.y*vb.z - va.z*vb.y,
				            va.z*vb.x - va.x*vb.z,
				            va.x*vb.y - va.y*vb.x);
  }
void COpenGLES2GrassRenderer::render(CSGPGrass* pGrass)
{	
	SGPVertex_GRASS_GLES2 tempData;
	if( m_GrassClusterInstanceArray.size() > 0 )
	{
		COpenGLES2GrassRenderer::Sorter CompareGrassInstance(m_pRenderDevice);
		m_GrassClusterInstanceArray.sort(CompareGrassInstance);
		
		uint32 nGrassClusterNum = jmin(m_GrassClusterInstanceArray.size(), INIT_GRASSCLUSTERINSTANCE_NUM);
		uint32 nSizeData = sizeof(SGPVertex_GRASS_GLES2) * nGrassClusterNum * (4*3);
		uint32 nVBOffset = (m_GrassClusterInstanceArray.size() <= INIT_GRASSCLUSTERINSTANCE_NUM) ? 0 : m_GrassClusterInstanceArray.size() - INIT_GRASSCLUSTERINSTANCE_NUM;
		SGPVertex_GRASS_Cluster* pGrassClusterSrc = m_GrassClusterInstanceArray.getRawDataPointer() + nVBOffset;
		
		// update Dynamic Grass Instance Buffer
		glBindBuffer(GL_ARRAY_BUFFER, m_nGrassClusterVBOID);
		glBufferData(GL_ARRAY_BUFFER, nSizeData, NULL, GL_STREAM_DRAW);
		SGPVertex_GRASS_GLES2* pGrassVertex = (SGPVertex_GRASS_GLES2*)m_pRenderDevice->extGlMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY_OES);

		for( uint32 i=0; i<nGrassClusterNum; i++ )
		{
			tempData.vNormal[0] = ( pGrassClusterSrc[i].vPackedNormal[0] / 255.0f - 0.5f ) * 2.0f;
			tempData.vNormal[1] = ( pGrassClusterSrc[i].vPackedNormal[1] / 255.0f - 0.5f ) * 2.0f;
			tempData.vNormal[2] = ( pGrassClusterSrc[i].vPackedNormal[2] / 255.0f - 0.5f ) * 2.0f;
			tempData.vNormal[3] = pGrassClusterSrc[i].vPackedNormal[3] / 255.0f;
			tempData.vColor[0] = pGrassClusterSrc[i].vColor[0];
			tempData.vColor[1] = pGrassClusterSrc[i].vColor[1];
			tempData.vColor[2] = pGrassClusterSrc[i].vColor[2];
			tempData.vColor[3] = pGrassClusterSrc[i].vColor[3];
			tempData.LMtu = pGrassClusterSrc[i].vPosition[0] / m_pRenderDevice->GetWorldSystemManager()->getTerrain()->GetTerrainWidth();
			tempData.LMtv = 1.0f - pGrassClusterSrc[i].vPosition[2] / m_pRenderDevice->GetWorldSystemManager()->getTerrain()->GetTerrainWidth();


			Matrix4x4 RotMatrix;
			RotMatrix.Identity();
			if( pGrassClusterSrc[i].vPackedNormal[1] < 250 )
			{
				Vector3D vTerrainNormal(tempData.vNormal[0], tempData.vNormal[1], tempData.vNormal[2]);
				vTerrainNormal.Normalize();

				float cost = tempData.vNormal[1];
				Vector3D v;
				v.Cross( Vector3D(0,1,0), vTerrainNormal );
				v.Normalize();
				float sint = std::sqrt(1-cost*cost);
				float one_sub_cost = 1 - cost;

				RotMatrix._11 = v.x * v.x * one_sub_cost + cost;
				RotMatrix._12 = v.x * v.y * one_sub_cost + v.z * sint;
				RotMatrix._13 = v.x * v.z * one_sub_cost - v.y * sint;
				RotMatrix._21 = v.x * v.y * one_sub_cost - v.z * sint;
				RotMatrix._22 = v.y * v.y * one_sub_cost + cost;
				RotMatrix._23 = v.y * v.z * one_sub_cost + v.x * sint;
				RotMatrix._31 = v.x * v.z * one_sub_cost + v.y * sint;
				RotMatrix._32 = v.y * v.z * one_sub_cost - v.x * sint;
				RotMatrix._33 = v.z * v.z * one_sub_cost + cost;
			}


			for( uint32 j=0; j<4*3; j++ )
			{
				tempData.tu = m_grassVertex[j].tu;
				tempData.tv = m_grassVertex[j].tv;

				Vector3D modelPos = Vector3D(m_grassVertex[j].x, m_grassVertex[j].y, m_grassVertex[j].z) * tempData.vNormal[3] * RotMatrix;
				modelPos += Vector3D(pGrassClusterSrc[i].vPosition[0], pGrassClusterSrc[i].vPosition[1], pGrassClusterSrc[i].vPosition[2]);

				float windAngle = m_vTimeParams.x * m_vTimeParams.y * Vector3D(pGrassClusterSrc[i].vPosition[0], pGrassClusterSrc[i].vPosition[1], pGrassClusterSrc[i].vPosition[2]).GetLength();
				Vector3D vCosSin = Vector3D( std::cos(windAngle), 0, std::sin(windAngle) );
				Vector3D vOffset(	pGrassClusterSrc[i].vWindParams[0] * m_vWindDirForce.x * m_vWindDirForce.w,
									pGrassClusterSrc[i].vWindParams[1] * m_vWindDirForce.y * m_vWindDirForce.w,
									pGrassClusterSrc[i].vWindParams[2] * m_vWindDirForce.z * m_vWindDirForce.w );

				vOffset.x += vCosSin.x * pGrassClusterSrc[i].vWindParams[0] * m_vWindDirForce.w;
				vOffset.y += vCosSin.y * pGrassClusterSrc[i].vWindParams[1] * m_vWindDirForce.w;
				vOffset.z += vCosSin.z * pGrassClusterSrc[i].vWindParams[2] * m_vWindDirForce.w;

				Vector3D vv = Vector3D(tempData.vNormal[0], tempData.vNormal[1], tempData.vNormal[2]) + vOffset;
				vv.Normalize();
				modelPos += vv * tempData.vNormal[3] * (1.0f - tempData.tv);	

				tempData.vPosition[0] = modelPos.x;
				tempData.vPosition[1] = modelPos.y;
				tempData.vPosition[2] = modelPos.z;
				tempData.vPosition[3] = pGrassClusterSrc[i].vPosition[3];

				(*pGrassVertex) = tempData;

				pGrassVertex++;
			}
		}

		m_pRenderDevice->extGlUnmapBuffer(GL_ARRAY_BUFFER);

	}
	
	m_vTextureAtlas.Set( pGrass->m_fTextureAtlasNbX, pGrass->m_fTextureAtlasNbY, pGrass->m_fTextureAtlasW, pGrass->m_fTextureAtlasH );
}
Пример #3
0
{
	return Vector2D(a.m_dX - b.m_dX, a.m_dY - b.m_dY);
}

Vector2D operator/ (const Vector2D& a, const double scale)
{
	return Vector2D(a.m_dX / scale, a.m_dY / scale);
}

Vector2D operator* (const Vector2D& a, const double scale)
{
	return Vector2D(a.m_dX * scale, a.m_dY * scale);
}

// Vector 3D
Vector3D Vector3D::vec3Zero = Vector3D(0, 0, 0);

Vector3D::Vector3D():m_dX(0.0), m_dY(0.0), m_dZ(0.0)
{}

Vector3D::Vector3D(double x, double y, double z):m_dX(x),m_dY(y),m_dZ(z)
{}

Vector3D& Vector3D::operator+=(const Vector3D& b)
{
	this->m_dX += b.m_dX;
	this->m_dY += b.m_dY;
	this->m_dZ += b.m_dZ;

	return *this;
}
Пример #4
0
Vector3D Vector3D::operator+(Vector3D v) {
 return Vector3D((x + v.x), (y + v.y), (z + v.z));
}
Пример #5
0
//==============================================================================
JuceDemoPluginAudioProcessor::JuceDemoPluginAudioProcessor()
    : delayBuffer (2, 12000)
{
    // Set up our parameters. The base class will delete them for us.
    addParameter (offset  = new FloatParameter (defaultGain,  "Gain"));
    addParameter (springConstant = new FloatParameter (defaultDelay, "Delay"));
    addParameter (velocityFactor = new FloatParameter (defaultDelay, "Velocity"));

    lastUIWidth = 1000;
    lastUIHeight = 400;

    lastPosInfo.resetToDefault();
    delayPosition = 0;

    // Initialise the synth...
    for (int i = 4; --i >= 0;)
        synth.addVoice (new SineWaveVoice());   // These voices will play our custom sine-wave sounds..

    synth.addSound (new SineWaveSound());

    const int n = m_particleCount;
    for(int i = 0; i < 2; i++) {
        m_particles.push_back(std::deque<Particle>());
        m_springs.push_back(std::deque<Spring>());

        std::deque<Particle>& particles = m_particles.back();
        std::deque<Spring>& springs = m_springs.back();

//        particles.resize(n);
//        springs.resize(n*2);

        Particle *p = &particles.back();
        Particle *pprev = &particles.back();

        particles.push_back(Particle(Vector3D(0.0, 0.0, 0.0)));
        Particle* fixedParticle = &particles.back();
        m_fixedParticle.push_back(fixedParticle);


        particles.push_back(Particle(Vector3D(1.0, 0.0, 0.0)));
        Particle* outputParticle = &particles.back();
        m_outputParticle.push_back(outputParticle);

        pprev = fixedParticle;
        p = outputParticle;

        springs.push_back(Spring(pprev, p, 1.0, 1.0));

        pprev = p;
        for(int j = 2; j < n; j++) {
            particles.push_back(Particle(Vector3D(j, 0.0, 0.0)));
            p = &particles.back();
            springs.push_back(Spring(pprev, p, 1.0, 1.0));
            pprev = p;
        }

        particles.push_back(Particle(Vector3D(n, 0.0, 0.0)));
        Particle* pn = &particles.back();
        Particle* inputParticle = pn;
        m_inputParticle.push_back(inputParticle);
        springs.push_back(Spring(pprev, pn, 1.0, 1.0));
//        Spring &sn = springs.back();
    }
}
Пример #6
0
void MpViewAppearance::Accept (void)
{
  double d;

  // facet shape
  int s = shading_menu[ShadingSelector->GetCurrentItemPos()].value;
  data->GetActiveGraphPtr()->facet_rendering = s;
  data->raster_image = (s == Facet::Gouraud) || (s == Facet::Phong);

  // mesh drawing
  data->GetActiveGraphPtr()->facet_edges = mesh_menu[MeshSelector->GetCurrentItemPos()].value;

  // ambient reflectance
  if (Ambient->Get(d) && (d >= 0) && (d <= 1))
    data->GetActiveGraphPtr()->facet_ambient_reflectance = d;	//  assign new base
  else {
    MpViewDisplay::Message("Expected ambient reflectance within 0.0 to 1.0");
    return;
  }

  // specular reflectance
  if (Specular->Get(d) && (d >= 0) && (d <= 1))
    data->GetActiveGraphPtr()->facet_specular_reflectance = d;
  else {
    MpViewDisplay::Message("Expected specular reflectance within 0.0 to 1.0");
    return;
  }

  // shininess
  if (Shininess->Get(d) && (d >= 0) & (d <= 100))
    data->GetActiveGraphPtr()->facet_specular_exponent = d;
  else {
    MpViewDisplay::Message("Expected shininess exponent within 0.0 to 100.0");
    return;
  }
    
  // fog opacity
  if (FogOpacity->Get(d) && (d >= 0))
    data->GetActiveGraphPtr()->fog_opacity = d;
  else {
    MpViewDisplay::Message("Expected fog opacity >= 0.0");
    return;
  }
  
  // fog distance
  if (FogDistance->Get(d))
    data->GetActiveGraphPtr()->fog_distance = d;
  else {
    MpViewDisplay::Message("Expected real number for fog distance");
    return;
  }
  
  // parse all (!) light positions
  for (int i = 0; i < MpViewAppearanceData::MaxLights; i++) {
    float x,y,z;
    if (sscanf(LightPos[i]->Get().c_str(),
	       " %f , %f , %f ",&x,&y,&z) != 3) {
      MpViewDisplay::Message("Expected three comma-separated numbers for position");
      return;
    } else
      data->GetActiveGraphPtr()->light[i].position = Vector3D(x,y,z);
  }

  // finally always call method of base class
  MpViewPanel::Accept();  
}
Пример #7
0
Vector3D Vector3D::operator*(double w) {
 return Vector3D((x * w), (y * w), (z * w));
}
Пример #8
0
 inline Vector3D operator /(const Vector3D &v, const double &scal) {
   return Vector3D(v.x/scal, v.y/scal, v.z/scal);
 }
Пример #9
0
PPMImage PerformAA(const PPMImage& original, const PPMImage& filtered) {
    NetPBMLoader loader;
    PPMImage recovered(original.getLength(), original.getWidth());
    PPMImage maxVarDir(original.getLength(), original.getWidth());
    PPMImage sobel(original.getLength(), original.getWidth());

    for(int i = 0; i < recovered.getLength(); ++i) {
        for(int j = 0; j < recovered.getWidth(); ++j) {
            // don't treat border pixels
            if(i == 0 || j == 0 || i == recovered.getLength()-1 || j == recovered.getWidth()-1) {
                recovered(i,j) = filtered(i,j);
                continue;
            }
            PPMImage neighbors(3,3);
            PPMImage neighborsAliased(3,3);
            Vector3D pixel = original(i,j);
            Vector3D pixelAlias = filtered(i,j);
            // colors are changing most rapidly considering this direction
            Vector3D varDir;
            // the distance vector from the average value of neighbors
            Vector3D dAverage[9];
            // the average value computed considering the neighbors
            Vector3D average;

            // parameters to compute recovery
            float alpha = 0;
            float beta = 0;
            float dp = 0;
            float Gd = 0;
            float ep = 0;
            float Ge = 0;

            // construct neighbors of aliased and original images
            for(int k = i-1; k <= i+1; ++k) {
                for(int l = j-1; l <= j+1; ++l) {
                    neighbors((k-i)+1, (l-j)+1) = original(k,l);
                    neighborsAliased((k-i)+1, (l-j)+1) = filtered(k,l);
                }
            }

            // compute the average
            for(int k = 0; k < neighbors.getLength(); ++k) {
                for(int l = 0; l < neighbors.getWidth(); ++l) {
                    average += neighbors(k,l);
                }
            }
            average /= neighbors.getSize();
            // compute the distance from the average color value
            for(int k = 0; k < neighbors.getLength(); ++k) {
                for(int l = 0; l < neighbors.getWidth(); ++l) {
                    dAverage[k*neighbors.getLength()+l] = neighbors(k,l) - average;
                }
            }

            varDir = Vector3D(average.normalize() + EPSILON);
            EM(dAverage, 3, varDir, neighbors.getSize());


            Vector2D maxColorPos;
            Vector2D minColorPos;

            // compute the two maximum colors along the straight line directed by varDir
            if(ExtremeColors(neighbors, varDir, maxColorPos, minColorPos)) {
                Vector3D ca = neighbors(minColorPos.x, minColorPos.y);
                Vector3D cb = neighbors(maxColorPos.x, maxColorPos.y);
                Vector3D cacb = cb - ca;
                Vector3D d;

                alpha = (pixel - ca).dot(cacb) / cacb.dot(cacb);
                d = pixel - (alpha * cacb) - ca;
                dp = d.length();
                Gd = GAUSS(dp, SIGMA_D);
            }

            float eo = Sobel(neighbors);
            float ef = Sobel(neighborsAliased);
            ep = ef * eo;
            Ge = GAUSS(ep, SIGMA_E);

            Vector3D cbAliased = neighborsAliased(maxColorPos.x, maxColorPos.y);
            Vector3D caAliased = neighborsAliased(minColorPos.x, minColorPos.y);

            beta = Gd * (1- Ge);
            // final composition
            recovered(i,j) = beta * (caAliased * (1-alpha) + cbAliased * alpha) + (1-beta) * pixelAlias;
            maxVarDir(i,j) = varDir * 255;
            sobel(i,j) = Vector3D(sqrt(eo));
        }
    }   

    loader.savePPM(maxVarDir, "max_variance_direction");
    loader.savePPM(sobel, "sobel");

    return recovered;
}
Пример #10
0
 inline Vector3D operator /(const Vector3D &va, const Vector3D &vb) {
   return Vector3D(va.x/vb.x, va.y/vb.y, va.z/vb.z);
 }
Пример #11
0
 inline Vector3D operator *(const double &scal, const Vector3D &v) {
   return Vector3D(v.x*scal, v.y*scal, v.z*scal);
 }
Пример #12
0
 inline Vector3D operator *(const Vector3D &va, const Vector3D &vb) {
   return Vector3D(va.x*vb.x, va.y*vb.y, va.z*vb.z);
 }
Пример #13
0
 inline Vector3D operator -(const Vector3D &va, const Vector3D &vb) {
   return Vector3D(va.x - vb.x, va.y - vb.y, va.z - vb.z);
 }
Пример #14
0
 inline Vector3D operator +(const Vector3D &va, const Vector3D &vb) {
   return Vector3D(va.x + vb.x, va.y + vb.y, va.z + vb.z);
 }
Пример #15
0
Vector3D operator*(const Vector3D& v1, const Vector3D& v2){
	return Vector3D(v1.y*v2.z-v1.z*v2.y,v1.z*v2.x-v1.x*v2.z,v1.x*v2.y-v1.y*v2.x);
}
Пример #16
0
AdeptOneSim::AdeptOneSim()
{
	name="SCARA Adept One Sim";
	
/***
Codo derecho   -> elbow = 1;
Codo izquierdo -> elbow = -1;
***/

//Configuracion inicial

	//Configuracion inicial = ELBOW_RIGHT

//Base =links[0]
	vector<Vector2D> list;
	Actuator* actuator;


	ComposedEntity *link=new ComposedEntity;
	link->setName("Base");
	PrismaticPart *auxPrism=new PrismaticPart;
	list.push_back(Vector2D(0.225,-0.225));
	list.push_back(Vector2D(0.225,0.225));
	list.push_back(Vector2D(-0.475,0.225));
	list.push_back(Vector2D(-0.475,-0.225));
	auxPrism->setPolygonalBase(list);
	list.clear();
	auxPrism->setHeight(0.04);
	auxPrism->setColor(0.445,0.601,0.352);
	(*link)+=auxPrism;

	CylindricalPart *auxCyl=new CylindricalPart(0.22,0.20);
	auxCyl->setColor(0.445,0.601,0.352);
	auxCyl->setRelativePosition(Vector3D(0,0,0.04));
	(*link)+=auxCyl;

	auxCyl=new CylindricalPart(0.05,0.16);
	auxCyl->setColor(0.445,0.601,0.352);
	auxCyl->setRelativePosition(Vector3D(0,0,0.22+0.04));
	(*link)+=auxCyl;

	auxCyl=new CylindricalPart(0.02,0.1);
	auxCyl->setColor(0.5,0.5,0.5);
	auxCyl->setRelativePosition(Vector3D(0,0,0.05+0.22+0.04));
	(*link)+=auxCyl;

	auxPrism=new PrismaticPart;
	list.push_back(Vector2D(0,-0.085));
	list.push_back(Vector2D(0,0.085));
	list.push_back(Vector2D(-0.07,0.085));
	list.push_back(Vector2D(-0.07,-0.085));
	auxPrism->setPolygonalBase(list);
	list.clear();
	auxPrism->setHeight(0.22);
	auxPrism->setColor(0.445,0.601,0.352);
	auxPrism->setRelativePosition(Vector3D(-0.17,0,0.04));
	(*link)+=auxPrism;

	auxPrism=new PrismaticPart;
	list.push_back(Vector2D(0,0.20));
	list.push_back(Vector2D(-0.135,0.20));
	list.push_back(Vector2D(-0.235,0.10));
	list.push_back(Vector2D(-0.235,-0.10));
	list.push_back(Vector2D(-0.135,-0.20));
	list.push_back(Vector2D(0,-0.20));
	auxPrism->setPolygonalBase(list);
	list.clear();
	auxPrism->setHeight(0.22);
	auxPrism->setColor(0.445,0.601,0.352);
	auxPrism->setRelativePosition(Vector3D(-0.24,0,0.04));
	(*link)+=auxPrism;
	
	(*this)+=link;
	links.push_back(link);


//Joint 0
	SimpleJoint *auxJoint=new SimpleJoint(5*PI/6,-5*PI/6,true,0,Z_AXIS,false);
	auxJoint->setRelativePosition(Vector3D(0,0,0.99));
	auxJoint->LinkTo(links[0]);

	actuator=new Actuator();
	actuator->linkTo(auxJoint);
	actuators.push_back(actuator);

	joints.push_back(auxJoint);
//Arm 1
	link=new ComposedEntity;
	link->setName("Link 1");
	auxCyl=new CylindricalPart(0.03,0.12);
	auxCyl->setColor(1,1,1);
	auxCyl->setRelativePosition(Vector3D(0,0,-0.66));
	(*link)+=auxCyl;

	auxCyl=new CylindricalPart(0.47,0.08);
	auxCyl->setColor(1,1,1);
	auxCyl->setRelativePosition(Vector3D(0,0,-0.63));
	(*link)+=auxCyl;

	auxCyl=new CylindricalPart(0.10,0.10);
	auxCyl->setColor(1,1,1);
	auxCyl->setRelativePosition(Vector3D(0,0,-0.16));
	(*link)+=auxCyl;

	auxPrism=new PrismaticPart;
	list.push_back(Vector2D(0.43358588,-0.08858489));
	list.push_back(Vector2D(0.46492273,-0.07954354));
	list.push_back(Vector2D(0.49089819,-0.05981997));
	list.push_back(Vector2D(0.50802391,-0.03206291));
	list.push_back(Vector2D(0.514,0));
	list.push_back(Vector2D(0.50802391,0.03206291));
	list.push_back(Vector2D(0.49089819,0.05981997));
	list.push_back(Vector2D(0.46492273,0.07954354));
	list.push_back(Vector2D(0.43358588,0.08858489));

	list.push_back(Vector2D(0.01254118,0.12939366));
	list.push_back(Vector2D(-0.02343779,0.12786974));
	list.push_back(Vector2D(-0.05761828,0.11653383));
	list.push_back(Vector2D(-0.08737748,0.09625579));
	list.push_back(Vector2D(-0.11043183,0.06859163));
	list.push_back(Vector2D(-0.12501227,0.03566415));
	list.push_back(Vector2D(-0.13,0));//Radio
	list.push_back(Vector2D(-0.12501227,-0.03566415));
	list.push_back(Vector2D(-0.11043183,-0.06859163));
	list.push_back(Vector2D(-0.08737748,-0.09625579));
	list.push_back(Vector2D(-0.05761828,-0.11653383));
	list.push_back(Vector2D(-0.02343779,-0.12786974));
	list.push_back(Vector2D(0.01254118,-0.12939366));
	auxPrism->setPolygonalBase(list);
	list.clear();
	auxPrism->setHeight(0.12);
	auxPrism->setColor(1,1,1);
	auxPrism->setRelativePosition(Vector3D(0,0,-0.06));
	(*link)+=auxPrism;

	auxCyl=new CylindricalPart(0.08,0.10);
	auxCyl->setColor(1,1,1);
	auxCyl->setRelativePosition(Vector3D(0,0,0.06));
	(*link)+=auxCyl;

	auxCyl=new CylindricalPart(0.01,0.07);
	auxCyl->setColor(0.5,0.5,0.5);
	auxCyl->setRelativePosition(Vector3D(0.425,0,0.06));
	(*link)+=auxCyl;
	link->LinkTo(joints[0]);
	links.push_back(link);
//joint 1
	auxJoint=new SimpleJoint(49*PI/60,-49*PI/60,true,0,Z_AXIS,false);
	auxJoint->setRelativePosition(Vector3D(0.425,0,0));
	auxJoint->LinkTo(joints[0]);

	actuator=new Actuator();
	actuator->linkTo(auxJoint);
	actuators.push_back(actuator);

	joints.push_back(auxJoint);
//Arm 2
	link=new ComposedEntity;
	link->setName("Link 2");

	auxPrism=new PrismaticPart;
	list.push_back(Vector2D(0.380088,-0.05275521));
	list.push_back(Vector2D(0.39875741,-0.04737705));
	list.push_back(Vector2D(0.41423432,-0.0356324));
	list.push_back(Vector2D(0.42443895,-0.01909949));
	list.push_back(Vector2D(0.428,0));
	list.push_back(Vector2D(0.42443895, 0.01909949));
	list.push_back(Vector2D(0.41423432, 0.0356324));
	list.push_back(Vector2D(0.39875741, 0.04737705));
	list.push_back(Vector2D(0.380088, 0.05275521));

	list.push_back(Vector2D(0.008544,0.08858894));
	list.push_back(Vector2D(-0.01608036,0.08753526));
	list.push_back(Vector2D(-0.03947151,0.07976842));
	list.push_back(Vector2D(-0.05983554,0.06588405));
	list.push_back(Vector2D(-0.07561073,0.04694697));
	list.push_back(Vector2D(-0.08558725,0.02440948));
	list.push_back(Vector2D(-0.089,0));//Radio
	list.push_back(Vector2D(-0.08558725,-0.02440948));
	list.push_back(Vector2D(-0.07561073,-0.04694697));
	list.push_back(Vector2D(-0.05983554,-0.06588405));
	list.push_back(Vector2D(-0.03947151,-0.07976842));
	list.push_back(Vector2D(-0.01608036,-0.08753526));
	list.push_back(Vector2D(0.008544,-0.08858894));

	auxPrism->setPolygonalBase(list);
	list.clear();
	auxPrism->setHeight(0.12);
	auxPrism->setColor(1,1,1);
	auxPrism->setRelativePosition(Vector3D(0,0,0.07));
	(*link)+=auxPrism;

	auxCyl=new CylindricalPart(0.06,0.089);
	auxCyl->setColor(1,1,1);
	auxCyl->setRelativePosition(Vector3D(0,0,0.19));
	(*link)+=auxCyl;

	auxCyl=new CylindricalPart(0.59,0.04);
	auxCyl->setColor(1,1,1);
	auxCyl->setRelativePosition(Vector3D(0.375,0,0));
	(*link)+=auxCyl;
	link->LinkTo(joints[1]);
	links.push_back(link);
//joint 2
	auxJoint=new SimpleJoint(0,-0.5,true,0,Z_AXIS,true);//Prismatica
	auxJoint->setRelativePosition(Vector3D(0.375,0,0));
	auxJoint->LinkTo(joints[1]);

	actuator=new Actuator();
	actuator->linkTo(auxJoint);
	actuators.push_back(actuator);

	joints.push_back(auxJoint);
	
//Arm 3


	auxCyl=new CylindricalPart(0.58,0.035);
	auxCyl->setName("Link 3");
	auxCyl->setColor(0.6,0.6,0.6);
	auxCyl->LinkTo(joints[2]);
	links.push_back(auxCyl);

//joint 3
	auxJoint=new SimpleJoint(277*PI/180,-277*PI/180,true,0,Z_AXIS,false);
	auxJoint->LinkTo(joints[2]);

	actuator=new Actuator();
	actuator->linkTo(auxJoint);
	actuators.push_back(actuator);

	joints.push_back(auxJoint);
//Arm 4
	auxCyl=new CylindricalPart(0.02,0.05);
	auxCyl->setName("Link 4");
	auxCyl->setColor(0.3,0.3,0.3);
	auxCyl->setRelativePosition(Vector3D(0,0,-0.02));
	auxCyl->LinkTo(joints[3]);
	links.push_back(auxCyl);

//Tcp
	tcp=new Tcp();
	tcp->setRelativePosition(Vector3D(0,0,-0.02));
	tcp->LinkTo(joints[3]);

	(*this)+=links[0];
//initial position
	setJointValue(0,0.56549);
	setJointValue(0,1.5708);
	setJointValue(0,-0.44);
	setJointValue(0,0.75398);


	
	actuators[0]->setSimulationParameters(23*PI/12);//	115º/seg Moidficated->before was 15º/seg
	actuators[1]->setSimulationParameters(5*PI/3);//	300º/seg
	actuators[2]->setSimulationParameters(0.5);//	500 mm/seg
	actuators[3]->setSimulationParameters(50*PI/9);//	1000º/seg

//Ficha técnica Máx speed
	//Joint 1 540°/sec
	//Joint 2 540°/sec
	//Joint 3 500 mm/sec (19.7 in./sec)
	//Joint 4 3600°/sec
}
Пример #17
0
Vector3D interpretate(const Vector3D & v1, const Vector3D& v2, float t)
{
	return Vector3D(v1.x+t*(v2.x-v1.x), v1.y+t*(v2.y-v1.y),v1.z+t*(v2.z-v1.z));
}
Пример #18
0
Vector3D operator+(const Vector3D& v1,const Vector3D& v2){
	return Vector3D(v1.x+v2.x,v1.y+v2.y,v1.z+v2.z);
}
Пример #19
0
int main(int argc, char* argv[])
{
	// Build your scene and setup your camera here, by calling
	// functions from Raytracer.  The code here sets up an example
	// scene and renders it from two different view points, DO NOT
	// change this if you're just implementing part one of the
	// assignment.
	Raytracer raytracer;
	int width = 320;
	int height = 240;

	if (argc == 3) {
		width = atoi(argv[1]);
		height = atoi(argv[2]);
	}

	if (argc == 4) {
		width = atoi(argv[1]);
		height = atoi(argv[2]);
		antiAliasing = atoi(argv[3]);
	}

	// Camera parameters.
	Point3D eye(0, 0, 1);
	Vector3D view(0, 0, -1);
	Vector3D up(0, 1, 0);
	double fov = 60;

	// Defines a material for shading.
	Material gold( Colour(0.3, 0.3, 0.3), Colour(0.75164, 0.60648, 0.22648),
			Colour(0.628281, 0.555802, 0.366065),
			51.2 );
	Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63),
			Colour(0.316228, 0.316228, 0.316228),
			12.8 );

	// Defines a point light source.
	raytracer.addLightSource( new PointLight(Point3D(0, 0, 5),
				Colour(0.9, 0.9, 0.9) ) );

	// Add a unit square into the scene with material mat.
	SceneDagNode* sphere = raytracer.addObject( new UnitSphere(), &gold );
	SceneDagNode* plane = raytracer.addObject( new UnitSquare(), &jade );

	// Apply some transformations to the unit square.
	double factor1[3] = { 1.0, 2.0, 1.0 };
	double factor2[3] = { 6.0, 6.0, 6.0 };
	raytracer.translate(sphere, Vector3D(0, 0, -5));
	raytracer.rotate(sphere, 'x', -45);
	raytracer.rotate(sphere, 'z', 45);
	raytracer.scale(sphere, Point3D(0, 0, 0), factor1);

	raytracer.translate(plane, Vector3D(0, 0, -7));
	raytracer.rotate(plane, 'z', 45);
	raytracer.scale(plane, Point3D(0, 0, 0), factor2);

	// Render the scene, feel free to make the image smaller for
	// testing purposes.
	raytracer.render(width, height, eye, view, up, fov, "view1.bmp");

	// Render it from a different point of view.
	Point3D eye2(4, 2, 1);
	Vector3D view2(-4, -2, -6);
	raytracer.render(width, height, eye2, view2, up, fov, "view2.bmp");

	return 0;
}
Пример #20
0
Vector3D operator-(const Vector3D& v1,const Vector3D& v2){
	return Vector3D(v1.x-v2.x,v1.y-v2.y,v1.z-v2.z);
}
Пример #21
0
Vector3D Vector3D::operator/(double w) {
 return Vector3D((x / w), (y / w), (z / w));
}
Пример #22
0
Vector3D operator-(const Vector3D& v){
	return Vector3D(-v.x,-v.y,-v.z);
}
Пример #23
0
Vector3D Vector3D::operator-(Vector3D v) {
 return Vector3D((x - v.x), (y - v.y), (z - v.z));
}
Пример #24
0
Vector3D operator*(const Vector3D& v,float l){
	return Vector3D(v.x*l,v.y*l,v.z*l);
}
void COpenGLES2GrassRenderer::update(float fDeltaTimeInSecond, const Vector4D& camPos, const Frustum& viewFrustum, CSGPGrass* pGrass)
{
	m_vCameraPos = camPos;

	m_GrassClusterInstanceArray.clearQuick();

	if( !pGrass )
		return;

	SGPVertex_GRASS_Cluster tempData;

	CSGPTerrainChunk** pChunkEnd = pGrass->m_TerrainGrassChunks.end();
	for( CSGPTerrainChunk** pChunkStart = pGrass->m_TerrainGrassChunks.begin(); pChunkStart < pChunkEnd; pChunkStart++ )
	{
		if( !m_pRenderDevice->GetWorldSystemManager()->isTerrainChunkVisible( *pChunkStart ) )
			continue;

		for(uint32 i=0; i<(*pChunkStart)->GetGrassClusterDataCount(); i++ )
		{
			// None Flag, skip this Cluster
			uint32 nGrassSetFlag = (*pChunkStart)->GetGrassClusterData()[i].nData;
			if( nGrassSetFlag == 0 )
				continue;

			tempData.vPosition[0] = (*pChunkStart)->GetGrassClusterData()[i].fPositionX;
			tempData.vPosition[1] = (*pChunkStart)->GetGrassClusterData()[i].fPositionY;
			tempData.vPosition[2] = (*pChunkStart)->GetGrassClusterData()[i].fPositionZ;
			tempData.vPosition[3] = float( (nGrassSetFlag & 0x00FF0000) >> 16 );

			// GrassCluster is not inside the camera Frustum, skip this Cluster
			AABBox GrassClusterAABB;
			GrassClusterAABB += Vector3D(tempData.vPosition[0] - m_vDefaultGrassSize.x, tempData.vPosition[1], tempData.vPosition[2] - m_vDefaultGrassSize.x);
			GrassClusterAABB += Vector3D(tempData.vPosition[0] + m_vDefaultGrassSize.x, tempData.vPosition[1] + m_vDefaultGrassSize.y, tempData.vPosition[2] + m_vDefaultGrassSize.x);
			if( !GrassClusterAABB.Intersects(viewFrustum) )
				continue;

			// GrassCluster is too far from the Grass Far Fading distance, skip this Cluster
			float fGrassDis = (m_vCameraPos - Vector4D(tempData.vPosition[0], tempData.vPosition[1], tempData.vPosition[2])).GetLength();
			if( fGrassDis > CSGPWorldConfig::getInstance()->m_fGrassFarFadingEnd )
				continue;

			tempData.vPackedNormal[0] = (uint8)(((*pChunkStart)->GetGrassClusterData()[i].nPackedNormal & 0xFF000000) >> 24);
			tempData.vPackedNormal[1] = (uint8)(((*pChunkStart)->GetGrassClusterData()[i].nPackedNormal & 0x00FF0000) >> 16);
			tempData.vPackedNormal[2] = (uint8)(((*pChunkStart)->GetGrassClusterData()[i].nPackedNormal & 0x0000FF00) >> 8);
			tempData.vPackedNormal[3] = (uint8)((nGrassSetFlag & 0xFF000000) >> 24);

			tempData.vColor[0] = tempData.vColor[1] = tempData.vColor[2] = 1.0f;
			tempData.vColor[3] = 1.0f - jlimit(0.0f, 1.0f, (fGrassDis - CSGPWorldConfig::getInstance()->m_fGrassFarFadingStart) / (CSGPWorldConfig::getInstance()->m_fGrassFarFadingEnd - CSGPWorldConfig::getInstance()->m_fGrassFarFadingStart));
			
			tempData.vWindParams[0] = ((nGrassSetFlag & 0x0000FF00) >> 8) / 255.0f;
			tempData.vWindParams[1] = 0.0f;
			tempData.vWindParams[2] = (nGrassSetFlag & 0x000000FF) / 255.0f;
			tempData.vWindParams[3] = 0.0f;
				
			m_GrassClusterInstanceArray.add( tempData );
		}
	}

	// update grass rendering params
	m_vTimeParams.x += fDeltaTimeInSecond;
	m_vTimeParams.y = pGrass->m_fGrassPeriod;
	m_vWindDirForce = pGrass->m_vWindDirectionAndStrength;
}
Пример #26
0
Vector3D operator*(float l, const Vector3D & v){
	return Vector3D(v.x*l,v.y*l,v.z*l);
}
Пример #27
0
// EGC
// Laborator 5
//-------------------------------------------------

#include "Object3D.h"

/*
Declaratiile clasei Object3D
Clasa pentru desenare si modificare a unui obiect 3d.
*/

// VARIABILE STATICE
//-------------------------------------------------
//float *Vector3D::arr = new float[3];
Vector3D Object3D::SelectedColor = Vector3D(1,0,1);		// culoarea obiectului selectat
Vector3D Object3D::ColorIncrement = Vector3D(0.04,0.04,0.04);	// valoarea cu care creste/scade in timp culoarea de mai sus


// CONSTRUCTORI
//-------------------------------------------------

// constructor de baza
Object3D::Object3D()
{
	defaultSettings();
}

// seteaza si tipul obiectului
Object3D::Object3D(ObjectType _Type)
{
	defaultSettings();
Пример #28
0
Vector3D operator/(const Vector3D& v,float l){
	return Vector3D(v.x/l,v.y/l,v.z/l);
}
Пример #29
0
Vector3D operator+(const Vector3D& a, const Vector3D& b)
{
	return Vector3D(a.m_dX + b.m_dX, a.m_dY + b.m_dY, a.m_dZ + b.m_dZ);
}
Пример #30
0
Vector3D operator* (const double a,const Vector3D & v)
{
    return Vector3D(v.X*a,v.Y*a,v.Z*a);
}