Ejemplo n.º 1
0
Particle PlaneParticleEmitter::newParticle(int anim, int time)
{
    Particle p;
	// TODO: maybe evaluate these outside the spawn function, since they will be common for a given frame?
	float w = sys->areal.getValue(anim, time) * 0.5f;
	float l = sys->areaw.getValue(anim, time) * 0.5f;
	float spd = sys->speed.getValue(anim, time);
	float var = sys->variation.getValue(anim, time);

	p.pos = sys->pos + Vec3D(randfloat(-l,l), 0, randfloat(-w,w));
	p.pos = sys->parent->mat * p.pos;

	Vec3D dir = sys->parent->mrot * Vec3D(0,1,0);
	p.down = Vec3D(0,-1.0f,0); // dir * -1.0f;
	//p.speed = dir.normalize() * randfloat(spd1,spd2);   // ?
	p.speed = dir.normalize() * spd * (1.0f+randfloat(-var,var));

	p.life = 0;
	p.maxlife = sys->lifespan.getValue(anim, time);

	p.origin = p.pos;

	p.tile = randint(0, sys->rows*sys->cols-1);
	return p;
}
Ejemplo n.º 2
0
toxi::geom::Triangle3D toxi::geom::Triangle3D::createEquilateralFrom( Vec3D & a, Vec3D & b )
{
    Vec3D c = a.interpolateTo( b, 0.5 );
    Vec3D dir = b.sub( a );
    Vec3D n = a.cross( dir.normalize( ) );
    c.addSelf( n.normalizeTo( dir.magnitude() * toxi::math::MathUtils::SQRT3 / 2 ) );
    return Triangle3D( a, b, c );
}
Ejemplo n.º 3
0
Vec3D CSceneData::getVertexNormal(int x, int y)const
{
	float a = getVertexHeight(x,	y);
	float b = getVertexHeight(x,	y+1);
	float c = getVertexHeight(x+1,	y);
	Vec3D vVector0(0,(b-a),1);
	Vec3D vVector1(1,(c-a),0);
	Vec3D vN = vVector0.cross(vVector1);
	return vN.normalize();
}
Ejemplo n.º 4
0
Vec3D CTerrainData::getVertexNormal(int nCellX, int nCellY)const
{
	float a = getVertexHeight(nCellX,	nCellY);
	float b = getVertexHeight(nCellX,	nCellY+1);
	float c = getVertexHeight(nCellX+1,	nCellY);
	Vec3D vVector0(0,(b-a),1);
	Vec3D vVector1(1,(c-a),0);
	Vec3D vN = vVector0.cross(vVector1);
	return vN.normalize();
}
Ejemplo n.º 5
0
void RibbonEmitter::setup(int anim, int time)
{
	Vec3D ntpos = parent->mat * pos;
	Vec3D ntup = parent->mat * (pos + Vec3D(0, 0, 1));
	ntup -= ntpos;
	ntup.normalize();
	float dlen = (ntpos - tpos).length();

	manim = anim;
	mtime = time;

	// move first segment
	RibbonSegment &first = *segs.begin();
	if (first.len > seglen) {
		// add new segment
		first.back = (tpos - ntpos).normalize();
		first.len0 = first.len;
		RibbonSegment newseg;
		newseg.pos = ntpos;
		newseg.up = ntup;
		newseg.len = dlen;
		segs.push_front(newseg);
	}
	else {
		first.up = ntup;
		first.pos = ntpos;
		first.len += dlen;
	}

	// kill stuff from the end
	float l = 0;
	bool erasemode = false;
	for (std::list<RibbonSegment>::iterator it = segs.begin(); it != segs.end();) {
		if (!erasemode) {
			l += it->len;
			if (l > length) {
				it->len = l - length;
				erasemode = true;
			}
		}
		else {
			segs.erase(it);
		}
		++it;
	}

	tpos = ntpos;
	tcolor = Vec4D(color.getValue(anim, time), opacity.getValue(anim, time));

	tabove = above.getValue(anim, time);
	tbelow = below.getValue(anim, time);
}
Ejemplo n.º 6
0
void ArcBallCamera::updatePosition()
{
  //LOG_INFO << "m_inclination = " << m_inclination << " / m_azimuth = " << m_azimuth;
  //LOG_INFO << "BEFORE - m_position = " << m_position.x << " " << m_position.y << " " << m_position.z;

  Vec3D viewDir = m_position - m_lookAt;

  viewDir.x = sinf(m_inclination * PI / 180.) * sinf(m_azimuth * PI / 180.);
  viewDir.y = cosf(m_inclination * PI / 180.);
  viewDir.z = sinf(m_inclination * PI / 180.) * cosf(m_azimuth * PI / 180.);

  viewDir.normalize();
  m_position = viewDir * m_distance + m_lookAt;

  //LOG_INFO << "AFTER - m_position = " << m_position.x << " " << m_position.y << " " << m_position.z;
}
Ejemplo n.º 7
0
Particle SphereParticleEmitter::newParticle(int anim, int time)
{
    Particle p;
	float l = sys->areal.getValue(anim, time);
	float w = sys->areaw.getValue(anim, time);
	float spd = sys->speed.getValue(anim, time);
	float var = sys->variation.getValue(anim, time);

	float t = randfloat(0,2*PI);

	// TODO: fix shpere emitters to work properly

	//Vec3D bdir(l*cosf(t), 0, w*sinf(t));
	Vec3D bdir(0, l*cosf(t), w*sinf(t));

	/*
	float theta_range = sys->spread.getValue(anim, time);
	float theta = -0.5f* theta_range + randfloat(0, theta_range);
	Vec3D bdir(0, l*cosf(theta), w*sinf(theta));

	float phi_range = sys->lat.getValue(anim, time);
	float phi = randfloat(0, phi_range);
	rotate(0,0, &bdir.z, &bdir.x, phi);
	*/

	p.pos = sys->pos + bdir;
	p.pos = sys->parent->mat * p.pos;

	if (bdir.lengthSquared()==0) p.speed = Vec3D(0,0,0);
	else {
		Vec3D dir = sys->parent->mrot * (bdir.normalize());
		p.speed = dir.normalize() * spd * (1.0f+randfloat(-var,var));   // ?
	}

	p.down = sys->parent->mrot * Vec3D(0,-1.0f,0);

	p.life = 0;
	p.maxlife = sys->lifespan.getValue(anim, time);

	p.origin = p.pos;

	p.tile = randint(0, sys->rows*sys->cols-1);
	return p;
}
Ejemplo n.º 8
0
void Test::tick(float t, float dt)
{
    Vec3D dir(1,0,0);
    rotate(0,0, &dir.x,&dir.y, av*PI/180.0f);
    rotate(0,0, &dir.x,&dir.z, ah*PI/180.0f);

    if (moving != 0) world->camera += dir * dt * movespd * moving;
    if (strafing != 0) {
        Vec3D right = dir % Vec3D(0,1,0);
        right.normalize();
        world->camera += right * dt * movespd * strafing;
    }
    if (updown != 0) world->camera += Vec3D(0, dt * movespd * updown, 0);
    world->lookat = world->camera + dir;

    world->time += (world->modelmanager.v * /*360.0f*/ 90.0f * dt);
    world->animtime += dt * 1000.0f;
    globalTime = (int)world->animtime;

    world->tick(dt);
}
Ejemplo n.º 9
0
void load3ds(Lib3dsFile *f)
{
	int i,j,meshV,meshT,meshNum;
	Lib3dsMesh *m;
	Lib3dsMaterial *mat;
	//First thing need to count all the vertices and triangles;
	nVertices=0;
	nTriangles=0;
	nSubmeshes=0;
	printf("Loading 3ds File\n");
	

	extractMaterialData(f);

	for (m=f->meshes; m; m=m->next)
	{
		nVertices+=m->points;
		nTriangles+=m->faces;
		for(i=1;i<m->faces;i++)
			if(strcmp(m->faceL[i-1].material,m->faceL[i].material)!=0)
				nSubmeshes++;
		nSubmeshes++;
	}
	printf("Vertices: %d Triangles: %d Submeshes: %d\n",nVertices,nTriangles,nSubmeshes);
	dVertices=new ModelVertex[nVertices];
	dTriangles=new uint16[nTriangles*3];
	dSubmeshes=new ModelGeoset[nSubmeshes];
	nTextureUnits=nSubmeshes;
	dTextureUnits=new ModelTexUnit[nTextureUnits];

	//Load initial vertex & triangle data
	meshV=0;
	meshT=0;
	meshNum=0;
	Matrix meshMat;
	for (m=f->meshes; m; m=m->next)
	{
		printf("Processing Mesh %d\n",meshNum);
		
		//This mesh must have something in it
		
		dSubmeshes[meshNum].id=0;
		dSubmeshes[meshNum].vstart=meshV;
		dSubmeshes[meshNum].vcount=m->points;
		dSubmeshes[meshNum].istart=meshT*3;
		dSubmeshes[meshNum].icount=m->faces*3;
		dSubmeshes[meshNum].d2=0;
		dSubmeshes[meshNum].d3=1;
		dSubmeshes[meshNum].d4=0;
		dSubmeshes[meshNum].d5=1;
		dSubmeshes[meshNum].d6=0;
		dSubmeshes[meshNum].v.x=0.001168764;
		dSubmeshes[meshNum].v.y=5.960465E-9;
		dSubmeshes[meshNum].v.z=0.6214849;
		
		//For now we are going to fake the texture unit data
		int matNum=materialNumber(m->faceL[0].material,f);
		dTextureUnits[meshNum].flags=0;
		dTextureUnits[meshNum].order=0;
		dTextureUnits[meshNum].op=meshNum;
		dTextureUnits[meshNum].op2=meshNum;
		dTextureUnits[meshNum].colorIndex=matNum;
		dTextureUnits[meshNum].flagsIndex=matNum;
		dTextureUnits[meshNum].texunit=0;
		dTextureUnits[meshNum].textureid=findTexture(m->faceL[0].material,f);
		dTextureUnits[meshNum].texunit2=0;
		dTextureUnits[meshNum].transid=matNum;
		dTextureUnits[meshNum].texanimid=0;
		dTextureUnits[meshNum].d4=1;
		
		meshNum++;

		
		for(i=0;i<m->points;i++)
		{
			dVertices[i+meshV].pos=Vec3D(m->pointL[i].pos[0],m->pointL[i].pos[1],m->pointL[i].pos[2])*0.01*.33*Scale;
			dVertices[i+meshV].texcoords=Vec2D(m->texelL[i][0],m->texelL[i][1]);

			dVertices[i+meshV].texcoords[1]=1-dVertices[i+meshV].texcoords[1];
			for(j=0;j<4;j++)
			{
				dVertices[i+meshV].bones[j]=0;
				dVertices[i+meshV].weights[j]=0;
			}
			dVertices[i+meshV].weights[0]=255;
			dVertices[i+meshV].unk1=0;
			dVertices[i+meshV].unk2=0;
			//Calculate Normal
			Vec3D Normal;
			Normal=Vec3D(0,0,0);
			for(j=0;j<m->faces;j++)
			{
				if((m->faceL[j].points[0]==i)||(m->faceL[j].points[2]==i)||(m->faceL[j].points[2]==i))
					Normal+=Vec3D(m->faceL[j].normal[0],m->faceL[j].normal[1],m->faceL[j].normal[2]);
			}
			Normal.normalize();
			dVertices[i+meshV].normal=Normal;
		}
		for(i=0;i<m->faces;i++)
		{
			if(i!=0)
			{
				if(strcmp(m->faceL[i-1].material,m->faceL[i].material)!=0)
				{
					//This mesh must have something in it
					dSubmeshes[meshNum].id=0;
					dSubmeshes[meshNum].vstart=meshV;
					dSubmeshes[meshNum].vcount=m->points;
					dSubmeshes[meshNum].istart=meshT*3+i*3;
					//Change count numbers
					dSubmeshes[meshNum-1].icount-=m->faces*3-i*3;
					dSubmeshes[meshNum].icount=m->faces*3-i*3;
					dSubmeshes[meshNum].d2=0;
					dSubmeshes[meshNum].d3=1;
					dSubmeshes[meshNum].d4=0;
					dSubmeshes[meshNum].d5=1;
					dSubmeshes[meshNum].d6=0;
					dSubmeshes[meshNum].v.x=0.001168764;
					dSubmeshes[meshNum].v.y=5.960465E-9;
					dSubmeshes[meshNum].v.z=0.6214849;
					//For now we are going to fake the texture unit data
					dTextureUnits[meshNum].flags=0;
					dTextureUnits[meshNum].colorIndex=0;
					dTextureUnits[meshNum].order=0;
					dTextureUnits[meshNum].op=meshNum;
					dTextureUnits[meshNum].op2=meshNum;
					dTextureUnits[meshNum].colorIndex=0;
					dTextureUnits[meshNum].flagsIndex=0;
					dTextureUnits[meshNum].texunit=0;
					dTextureUnits[meshNum].textureid=findTexture(m->faceL[i].material,f);
					dTextureUnits[meshNum].texunit2=0;
					dTextureUnits[meshNum].transid=0;
					dTextureUnits[meshNum].texanimid=0;
					dTextureUnits[meshNum].d4=1;
					
					meshNum++;
				}
			}
			dTriangles[(i+meshT)*3]=(uint16)m->faceL[i].points[0]+meshV;
			dTriangles[(i+meshT)*3+1]=(uint16)m->faceL[i].points[1]+meshV;
			dTriangles[(i+meshT)*3+2]=(uint16)m->faceL[i].points[2]+meshV;
			
		}
		meshV+=m->points;
		meshT+=m->faces;
	}
}
Ejemplo n.º 10
0
Particle SphereParticleEmitter::newParticle(int anim, int time, float w, float l, float spd, float var, float spr, float spr2)
{
	Particle p;
	Vec3D dir;
	float radius;

	radius = misc::randfloat(0, 1);

	// Old method
	//float t = misc::randfloat(0,2*PI);

	// New
	// Spread should never be zero for sphere particles ?
	float t = 0;
	if (spr == 0)
		t = misc::randfloat((float)-PI, (float)PI);
	else
		t = misc::randfloat(-spr, spr);

	//Spread Calculation
	Matrix mrot;

	CalcSpreadMatrix(spr * 2, spr2 * 2, w, l);
	mrot = sys->parent->mrot*SpreadMat;

	// New
	// Length should never technically be zero ?
	//if (l==0)
	//  l = w;

	// New method
	// Vec3D bdir(w*cosf(t), 0.0f, l*sinf(t));
	// --

	//! \todo fix shpere emitters to work properly
	/* // Old Method
	//Vec3D bdir(l*cosf(t), 0, w*sinf(t));
	//Vec3D bdir(0, w*cosf(t), l*sinf(t));


	float theta_range = sys->spread.getValue(anim, time);
	float theta = -0.5f* theta_range + misc::randfloat(0, theta_range);
	Vec3D bdir(0, l*cosf(theta), w*sinf(theta));

	float phi_range = sys->lat.getValue(anim, time);
	float phi = misc::randfloat(0, phi_range);
	rotate(0,0, &bdir.z, &bdir.x, phi);
	*/

	if (sys->flags == 57 || sys->flags == 313) { // Faith Halo
		Vec3D bdir(w*cosf(t)*1.6f, 0.0f, l*sinf(t)*1.6f);

		p.pos = sys->pos + bdir;
		p.pos = sys->parent->mat * p.pos;

		if (bdir.lengthSquared() == 0)
			p.speed = Vec3D(0, 0, 0);
		else {
			dir = sys->parent->mrot * (bdir.normalize());//mrot * Vec3D(0, 1.0f,0);
			p.speed = dir.normalize() * spd * (1.0f + misc::randfloat(-var, var));   // ?
		}

	}
	else {
		Vec3D bdir;
		float temp;

		bdir = mrot * Vec3D(0, 1, 0) * radius;
		temp = bdir.z;
		bdir.z = bdir.y;
		bdir.y = temp;

		p.pos = sys->parent->mat * sys->pos + bdir;


		//p.pos = sys->pos + bdir;
		//p.pos = sys->parent->mat * p.pos;


		if (!bdir.lengthSquared() && !(sys->flags & 0x100))
		{
			p.speed = Vec3D(0, 0, 0);
			dir = sys->parent->mrot * Vec3D(0, 1, 0);
		}
		else
		{
			if (sys->flags & 0x100)
				dir = sys->parent->mrot * Vec3D(0, 1, 0);
			else
				dir = bdir.normalize();

			p.speed = dir.normalize() * spd * (1.0f + misc::randfloat(-var, var));   // ?
		}
	}

	p.dir = dir.normalize();//mrot * Vec3D(0, 1.0f,0);
	p.down = Vec3D(0, -1.0f, 0);

	p.life = 0;
	p.maxlife = sys->lifespan.getValue(anim, time);

	p.origin = p.pos;

	p.tile = misc::randint(0, sys->rows*sys->cols - 1);
	return p;
}
Ejemplo n.º 11
0
Particle PlaneParticleEmitter::newParticle(int anim, int time, float w, float l, float spd, float var, float spr, float /*spr2*/)
{
	// Model Flags - *shrug* gotta write this down somewhere.
	// 0x1 =
	// 0x2 =
	// 0x4 =
	// 0x8 =
	// 0x10 =
	// 19 = 0x13 = blue ball in thunderfury = should be billboarded?

	// Particle Flags
	// 0x0  / 0    = Basilisk has no flags?
	// 0x1  / 1    = Pretty much everything I know of except Basilisks have this flag..  Billboard?
	// 0x2  / 2    =
	// 0x4  / 4    =
	// 0x8  / 8    =
	// 0x10  / 16  = Position Relative to bone pivot?
	// 0x20  / 32  =
	// 0x40  / 64  =
	// 0x80 / 128  =
	// 0x100 / 256  =
	// 0x200 / 512  =
	// 0x400 / 1024 =
	// 0x800 / 2048 =
	// 0x1000/ 4096 =
	// 0x0000/ 1593 = [1,8,16,32,512,1024]"Warp Storm" - aura type particle effect
	// 0x419 / 1049 = [1,8,16,1024] Forest Wind shoulders
	// 0x411 / 1041 = [1,16,1024] Halo
	// 0x000 / 541  = [1,4,8,16,512] Staff glow
	// 0x000 / 537 = "Warp Storm"
	// 0x31 / 49 = [1,16,32] particle moving up?
	// 0x00 / 41 = [1,8,32] Blood elf broom, dust spread out on the ground (X, Z axis)
	// 0x1D / 29 = [1,4,8,16] particle being static
	// 0x19 / 25 = [1,8,16] flame on weapon - move up/along the weapon
	// 17 = 0x11 = [1,16] glow on weapon - static, random direction.  - Aurastone Hammer
	// 1 = 0x1 = perdition blade
	// 4121 = water ele
	// 4097 = water elemental
	// 1041 = Transcendance Halo
	// 1039 = water ele

	Particle p;

	//Spread Calculation
	Matrix mrot;

	CalcSpreadMatrix(spr, spr, 1.0f, 1.0f);
	mrot = sys->parent->mrot*SpreadMat;

	if (sys->flags == 1041) { // Trans Halo
		p.pos = sys->parent->mat * (sys->pos + Vec3D(misc::randfloat(-l, l), 0, misc::randfloat(-w, w)));

		const float t = misc::randfloat(0.0f, 2.0f * (float)PI);

		p.pos = Vec3D(0.0f, sys->pos.y + 0.15f, sys->pos.z) + Vec3D(cos(t) / 8, 0.0f, sin(t) / 8); // Need to manually correct for the halo - why?

		// var isn't being used, which is set to 1.0f,  whats the importance of this?
		// why does this set of values differ from other particles

		Vec3D dir(0.0f, 1.0f, 0.0f);
		p.dir = dir;

		p.speed = dir.normalize() * spd * misc::randfloat(0, var);
	}
	else if (sys->flags == 25 && sys->parent->parent<1) { // Weapon Flame
		p.pos = sys->parent->pivot * (sys->pos + Vec3D(misc::randfloat(-l, l), misc::randfloat(-l, l), misc::randfloat(-w, w)));
		Vec3D dir = mrot * Vec3D(0.0f, 1.0f, 0.0f);
		p.dir = dir.normalize();
		//Vec3D dir = sys->model->bones[sys->parent->parent].mrot * sys->parent->mrot * Vec3D(0.0f, 1.0f, 0.0f);
		//p.speed = dir.normalize() * spd;

	}
	else if (sys->flags == 25 && sys->parent->parent > 0) { // Weapon with built-in Flame (Avenger lightsaber!)
		p.pos = sys->parent->mat * (sys->pos + Vec3D(misc::randfloat(-l, l), misc::randfloat(-l, l), misc::randfloat(-w, w)));
		Vec3D dir = Vec3D(sys->parent->mat.m[1][0], sys->parent->mat.m[1][1], sys->parent->mat.m[1][2]) * Vec3D(0.0f, 1.0f, 0.0f);
		p.speed = dir.normalize() * spd * misc::randfloat(0, var * 2);

	}
	else if (sys->flags == 17 && sys->parent->parent<1) { // Weapon Glow
		p.pos = sys->parent->pivot * (sys->pos + Vec3D(misc::randfloat(-l, l), misc::randfloat(-l, l), misc::randfloat(-w, w)));
		Vec3D dir = mrot * Vec3D(0, 1, 0);
		p.dir = dir.normalize();

	}
	else {
		p.pos = sys->pos + Vec3D(misc::randfloat(-l, l), 0, misc::randfloat(-w, w));
		p.pos = sys->parent->mat * p.pos;

		//Vec3D dir = mrot * Vec3D(0,1,0);
		Vec3D dir = sys->parent->mrot * Vec3D(0, 1, 0);

		p.dir = dir;//.normalize();
		p.down = Vec3D(0, -1.0f, 0); // dir * -1.0f;
		p.speed = dir.normalize() * spd * (1.0f + misc::randfloat(-var, var));
	}

	if (!sys->billboard)  {
		p.corners[0] = mrot * Vec3D(-1, 0, +1);
		p.corners[1] = mrot * Vec3D(+1, 0, +1);
		p.corners[2] = mrot * Vec3D(+1, 0, -1);
		p.corners[3] = mrot * Vec3D(-1, 0, -1);
	}

	p.life = 0;
	p.maxlife = sys->lifespan.getValue(anim, time);

	p.origin = p.pos;

	p.tile = misc::randint(0, sys->rows*sys->cols - 1);
	return p;
}
Ejemplo n.º 12
0
Track::Track(Vec3D pos, Vec3D dir, float en) : position(pos), flightDirection(dir.normalize()), energy(en) {
}