Пример #1
0
void ModelGroup::update(Storm &storm, const VC3 &position)
{
	QUAT quat;
	//quat.MakeFromAngles(0, rotation, 0);
	quat = frozenbyte::editor::getRotation(rotationEul);
	MAT tm;
	tm.CreateRotationMatrix(quat);

	for(int i = 0; i < int(models.size()); ++i)
	{
		if(!models[i])
			continue;

		const GroupList::Instance &instance = objectGroup.instances[i];

		VC3 pos = instance.position;
		tm.RotateVector(pos);
		pos += position;
		pos.y = storm.getHeight(VC2(pos.x, pos.z)) + heightOffset;
		pos.y += objectGroup.instances[i].position.y;
		models[i]->SetPosition(pos);

		VC3 angles = getRotation(storm, i);
		quat = frozenbyte::editor::getRotation(angles);

		//QUAT q;
		//q.MakeFromAngles(0, rotation, 0);
		//quat = quat * q;

		models[i]->SetRotation(quat);
	}
}
Пример #2
0
		VC3 getSunDirection() const
		{
			float yAngle = getSliderValue(dialog, IDC_SUN_YANGLE) / 180.f * PI;
			float xAngle = -getSliderValue(dialog, IDC_SUN_XANGLE) / 180.f * PI;
			float strength = getSliderValue(dialog, IDC_SUN_STRENGTH) / 400.f;

			QUAT q;
			q.MakeFromAngles(xAngle, yAngle);
			q.Normalize();
			MAT tm;
			tm.CreateRotationMatrix(q);

			VC3 result(0, 0, strength);
			tm.RotateVector(result);

			return result;
		}
int Storm3D_ParticleSystem::QuadArray::lock(VXFORMAT_PART *pointer, int particleOffset, Storm3D_Scene *scene)
{
	m_partOffset = particleOffset;
	pointer += particleOffset * 4;
	VXFORMAT_PART *vp = pointer;

	float frameWidth = 0.0f;
	float frameHeight = 0.0f;
	if(m_animInfo.numFrames > 1) 
	{
		frameWidth = 1.0f / m_animInfo.textureUSubDivs;
		frameHeight = 1.0f / m_animInfo.textureVSubDivs;
	}
	
	BYTE *verts = (BYTE*)&vp[0].position;
	BYTE *uvs = (BYTE*)&vp[0].texcoords;
	BYTE *colors = (BYTE*)&vp[0].color;
	
	DWORD stride = sizeof(VXFORMAT_PART);
	D3DXMATRIX mv = scene->camera.GetViewMatrix();
	DWORD c0 = 0;

	// Up rotation
	MAT view(scene->camera.GetViewMatrix());
	VC3 worldUp(0, 1.f, 0);
	view.RotateVector(worldUp);
	QUAT q;
	rotateToward(worldUp, VC3(0, 0, 1.f), q);
	MAT g;
	g.CreateRotationMatrix(q);

	for(int i = 0; i < m_numParts; i++) 
	{
		Storm3D_PointParticle& p = m_parts[i];

		float sa = sinf(p.angle);
		float ca = cosf(p.angle);
		float hsize = 0.5f*p.size;
			
		float x1,y1,x2,y2,x3,y3,x4,y4;

		quad_util::rotatePointFast(x1, y1, -hsize, hsize, ca, sa);
		quad_util::rotatePointFast(x2, y2,  hsize, hsize, ca, sa);
		quad_util::rotatePointFast(x3, y3, -hsize, -hsize, ca, sa);
		quad_util::rotatePointFast(x4, y4,  hsize, -hsize, ca, sa);

		VC3 v;
			
		v.x = p.position.x * mv.m[0][0] + 
			p.position.y * mv.m[1][0] + 
			p.position.z * mv.m[2][0] + mv.m[3][0];
		
		v.y = p.position.x * mv.m[0][1] + 
			p.position.y * mv.m[1][1] + 
			p.position.z * mv.m[2][1] + mv.m[3][1];

		v.z = p.position.x * mv.m[0][2] + 
			p.position.y * mv.m[1][2] + 
			p.position.z * mv.m[2][2] + mv.m[3][2];

		VC3 v1(x1, y1, 0);
		VC3 v2(x2, y2, 0);
		VC3 v3(x3, y3, 0);
		VC3 v4(x4, y4, 0);

		if(faceUp)
		{
			g.RotateVector(v1);
			g.RotateVector(v2);
			g.RotateVector(v3);
			g.RotateVector(v4);
		}

		v1 += v;
		v2 += v;
		v3 += v;
		v4 += v;

		/*
		VC3 v1(v.x + x1, v.y + y1, v.z);
		VC3 v2(v.x + x2, v.y + y2, v.z);
		VC3 v3(v.x + x3, v.y + y3, v.z);
		VC3 v4(v.x + x4, v.y + y4, v.z);

		{
			v1 -= v;
			g.RotateVector(v1);
			v1 += v;

			v2 -= v;
			g.RotateVector(v2);
			v2 += v;

			v3 -= v;
			g.RotateVector(v3);
			v3 += v;

			v4 -= v;
			g.RotateVector(v4);
			v4 += v;
		}
		*/

		*((Vector*)verts) = v1; verts += stride;
		*((Vector*)verts) = v2; verts += stride;
		*((Vector*)verts) = v3; verts += stride;
		*((Vector*)verts) = v4; verts += stride;

		// Fill texturecoords
		if(m_animInfo.numFrames > 1) {
			
			int frame = (int)p.frame % m_animInfo.numFrames;
			
			int col = frame % m_animInfo.textureUSubDivs;
			int row = frame / m_animInfo.textureUSubDivs;
			
			float tx = frameWidth * (float)col;
			float ty = frameHeight * (float)row;				
			
			*((float*)uvs) = tx; uvs += 4; *((float*)uvs) = ty; uvs += (stride - 4);
			*((float*)uvs) = tx + frameWidth; uvs += 4; *((float*)uvs) = ty; uvs += (stride - 4);
			*((float*)uvs) = tx; uvs += 4; *((float*)uvs) = ty + frameHeight; uvs += (stride - 4);
			*((float*)uvs) = tx + frameWidth; uvs += 4; *((float*)uvs) = ty + frameHeight; uvs += (stride - 4);

		} else {

			*((float*)uvs) = 0.0f; uvs += 4; *((float*)uvs) = 0.0f; uvs += (stride - 4);
			*((float*)uvs) = 1.0f; uvs += 4; *((float*)uvs) = 0.0f; uvs += (stride - 4);
			*((float*)uvs) = 0.0f; uvs += 4; *((float*)uvs) = 1.0f; uvs += (stride - 4);
			*((float*)uvs) = 1.0f; uvs += 4; *((float*)uvs) = 1.0f; uvs += (stride - 4);
			
		}

		c0 = (((DWORD)(p.alpha * 255.0f) &0xff) << 24) |
			(((DWORD)(factor.r * p.color.r * 255.0f) &0xff) << 16) |
			(((DWORD)(factor.g * p.color.g * 255.0f) &0xff) << 8) |
			(((DWORD)(factor.b * p.color.b * 255.0f) &0xff) );
	
		*((DWORD*)colors) = c0; colors += stride;
		*((DWORD*)colors) = c0; colors += stride;
		*((DWORD*)colors) = c0; colors += stride;
		*((DWORD*)colors) = c0; colors += stride;

	}

	return m_numParts;
}