Example #1
0
BOOL CGauge::OnDragEnd(int nHitTest,CPointF point)
{
	CRectF rc;
	GetBoundsRect(rc);

	REAL dx = m_pWnd->GetStartPos().x;
	REAL dy = m_pWnd->GetStartPos().y;

	switch (nHitTest)
	{
	case TopLeft:
		rc.left = point.x + dx;
		rc.top = point.y + dy;
		break;
	case Top:
		rc.top = point.y + dy;
		break;
	case TopRight:
		rc.right = point.x + dx;
		rc.top = point.y + dy;
		break; 
	case Right:
		rc.right = point.x + dx;
		break;
	case BottomRight:
		rc.right = point.x + dx;
		rc.bottom = point.y + dy;
		break;
	case Bottom:
		rc.bottom = point.y + dy;
		break;
	case BottomLeft:
		rc.left = point.x + dx;
		rc.bottom = point.y + dy;
		break;
	case Left:
		rc.left = point.x + dx;
		break;
	case Body:
		rc.MoveToXY(rc.left+point.x-m_pWnd->GetMarkPos().x,
			rc.top+point.y-m_pWnd->GetMarkPos().y);
		break;
	default:
		m_pts[nHitTest-HtIndex] = point + m_pWnd->GetStartPos();
		PointHelper::CalcPointsBoundsRect(m_pts,m_rcBounds);
		FormatDesc();
		return TRUE;
	}

	SetBoundsRect(rc);
	
	FormatDesc();
	return TRUE;
}
Example #2
0
void CGauge::InitEndDrag(CPointF point)
{ 
	int i = 1;
	while (i<m_pts.GetCount() && m_pts.GetCount()>2)
	{
		if (LineHelper::LEN(m_pts[i],m_pts[i-1]) <= HITTEST_DIST)
			m_pts.RemoveAt(i);
		else
			++i;
	}
	PointHelper::OffsetPoints(m_pts,m_pWnd->GetStartPos().x,m_pWnd->GetStartPos().y);
	PointHelper::CalcPointsBoundsRect(m_pts,m_rcBounds);
	FormatDesc();
}
void Particle_Group::ReloadShaders(){
	
	VS_Main.CompileShaderFromFile("Fireworks_Particle.fx","VSScenemain");

	FormatDesc fd[4] ={
		FormatDesc(),
		FormatDesc(TYPE_NORMAL),
		FormatDesc(TYPE_WEIGHT, FORMAT_FLOAT, 1),// i used a weight here as the type just because I dont need 50 different names for the same purpose
		FormatDesc(TYPE_WEIGHT, FORMAT_FLOAT, 1),// i used a weight here as the type just because I dont need 50 different names for the same purpose
	};
	VS_Main.CreateInputLayout(fd, 4);
	VS_Passthrough.CompileShaderFromFile("Fireworks_Particle.fx", "VSPassThroughmain");
	VS_Passthrough.CreateInputLayout(fd, 4);
	FormatDesc_SO fdso[4] = {
		FormatDesc_SO(0, "POSITION", 0, 0, 3, 0),
		FormatDesc_SO(0, "NORMAL", 0, 0, 3, 0),
		FormatDesc_SO(0, "BLENDWEIGHT", 0, 0, 1, 0),
		FormatDesc_SO(0, "BLENDWEIGHT", 1, 0, 1, 0),
	};
	
	GS_StreamOut.CompileShaderFromFile("Fireworks_Particle.fx", fdso, 4,  "GSAdvanceParticlesMain");
	GS_Main.CompileShaderFromFile("Fireworks_Particle.fx","GSScenemain");
	PS_Main.CompileShaderFromFile("Fireworks_Particle.fx","PSScenemain");
}
bool Trans_Mesh::Init(){
	XAxis_Color=vec3(1, 0, 0);
	YAxis_Color=vec3(0, 1,0);
	ZAxis_Color=vec3(0, 0, 1);
	Hit_Axis_Color = vec3(1, 1, 1);
	HitAxis = vec3(0,0,0);
	Vertices.push_back(vec3(1.0f, 0.0f, 0.0f));
	const float split=16.0f;
	//note: all of these shapes will have to be scaled to correctly in the draw function, but its not something the user will do. that will be done in the draw function below
	// first create the cone pointer
	uint16_t index=1;
	for(float i=0.0f; i<2*Pi; i+=Pi/split){
		vec3 p;
		p.x=-1.0f;
		p.y=sinf(i);
		p.z=cosf(i);
		Vertices.push_back(p);
	}

	index=0;
	for(float i=0.0f; i<2*Pi; i+=Pi/split){
		Indices.push_back(0);
		Indices.push_back(index+2);
		Indices.push_back(index+1);
		index+=1;
	}
	Indices[Indices.size()-2]=Vertices.size()-1;
	Indices.push_back(0);
	Indices.push_back(1);
	Indices.push_back(Vertices.size()-1);

	FormatDesc layers[1] = { FormatDesc(TYPE_VERTEX, FORMAT_FLOAT, 4, 0) };
	Batch* b = new Batch();
	b->GetVS()->CompileShaderFromMemory(Graphics::Shader_Defines::BV_VS);
	b->GetVS()->CreateInputLayout(layers, 1);
	b->GetPS()->CompileShaderFromMemory(Graphics::Shader_Defines::BV_PS);
	b->NumIndices = Indices.size();
	b->StartIndex =0;
	b->NumVerts = Vertices.size();
	Batches.push_back(b);

	index=Vertices.size();

	// now create the rod to connect to it 
	// a long triangle looks the same as a rod
	Vertices.push_back(vec3(1.0f, 1.0f, 0.0f));//0
	Vertices.push_back(vec3(1.0f, -1.0f, 1.0f));//1
	Vertices.push_back(vec3(1.0f, -1.0f, -1.0f));//2

	Vertices.push_back(vec3(-1.0f, 1.0f, 0.0f));//3
	Vertices.push_back(vec3(-1.0f, -1.0f, 1.0f));//4
	Vertices.push_back(vec3(-1.0f, -1.0f, -1.0f));//5

	Vertices.push_back(vec3(-1.0f, -1.0f, -1.0f));//extra vert is needed for alignment reasons.. .  i guess

	Batch* b1 = new Batch();
	b1->GetVS()->CompileShaderFromMemory(Graphics::Shader_Defines::BV_VS);
	b1->GetVS()->CreateInputLayout(layers, 1);
	b1->GetPS()->CompileShaderFromMemory(Graphics::Shader_Defines::BV_PS);
	b1->StartIndex =Indices.size();
	b1->NumVerts = 6;
	Batches.push_back(b1);

	Indices.push_back(index+0);
	Indices.push_back(index+4);
	Indices.push_back(index+3);

	Indices.push_back(index+1);
	Indices.push_back(index+4);
	Indices.push_back(index+0);

	Indices.push_back(index+1);
	Indices.push_back(index+4);
	Indices.push_back(index+2);

	Indices.push_back(index+2);
	Indices.push_back(index+4);
	Indices.push_back(index+5);

	Indices.push_back(index+5);
	Indices.push_back(index+2);
	Indices.push_back(index+3);

	Indices.push_back(index+3);
	Indices.push_back(index+2);
	Indices.push_back(index+0);

	b1->NumIndices = Indices.size()-b->NumIndices;


	CBuffer0.Create(1, sizeof(mat4) + sizeof(vec4), CONSTANT_BUFFER);
	VB[0].Create(Vertices.size(), sizeof(vec3), BufferType::VERTEX_BUFFER, DEFAULT, CPU_NONE, &Vertices[0]);
	IB.Create(Indices.size(), sizeof(uint16_t), BufferType::INDEX_BUFFER, DEFAULT, CPU_NONE, &Indices[0]);

	return true;
}
bool Animated_Mesh::Load_Assimp(const std::string& file){
	const aiScene* load =aiImportFile(file.c_str(), aiProcessPreset_TargetRealtime_MaxQuality | aiProcess_ConvertToLeftHanded );
	if(load==NULL) {
		OUTPUT_DEBUG_MSG("Could not load the Model in Animated_Mesh::Load_MyFormat file: '" + file+"'");
		return false;
	}
	size_t numverts(0), currentvertex(0), currentindex(0), numindices(0);
	bool hasbones=false;
	// go through the mesh counting all the verts and indices that I will need
	for (unsigned int i = 0; i < load->mNumMeshes;++i) {
		numverts+=load->mMeshes[i]->mNumVertices;
		numindices+=load->mMeshes[i]->mNumFaces*3;
		if(load->mMeshes[i]->HasBones()) hasbones=true;
	}
	if(!hasbones) {
		aiReleaseImport(load);// free the resrouces
		OUTPUT_DEBUG_MSG("Could not load the Model in Animated_Mesh::Load_MyFormat file: '" + file+"', there were no bones deteected.");
		return false;
	}
	IB.Stride=2;
	if(numverts >= 65536) IB.Stride=4;

	Vertices.resize(numverts);
	Indices.resize((IB.Stride/2)*numindices);
	std::vector<Vertex_Types::Pos_Tex_Norm_Tang_Bone_Weight> tempverts(numverts);
	std::vector<std::string> bonenames;

	for (unsigned int i = 0; i < load->mNumMeshes;++i){
		Graphics::Texture diffuse, normal;
		const aiMesh* mesh = load->mMeshes[i];
		if(mesh->mPrimitiveTypes != aiPrimitiveType_TRIANGLE) {
			OUTPUT_DEBUG_MSG("There are errors with this submesh, named: "<<mesh->mName.data<<"   Please, fix it");
			if(mesh->mPrimitiveTypes == aiPrimitiveType_LINE){
				OUTPUT_DEBUG_MSG("Problem: The mesh containes lines when it should only contain triangles");
			}else {
				OUTPUT_DEBUG_MSG("Problem: The mesh containes points when it should only contain triangles");
			}
			continue;
		}

		if (!mesh->HasTextureCoords(0))	{
			OUTPUT_DEBUG_MSG("There are errors with this submesh, named: "<<mesh->mName.data<<"   Please, fix it");
			OUTPUT_DEBUG_MSG("Problem: The mesh containes no texcoords, which means there will just be color displayed. This engine does not support color mesh displays, only textured mesh!");
			continue;
		} 
		if(!mesh->HasTangentsAndBitangents()) {
			OUTPUT_DEBUG_MSG("There are errors with this submesh, named: "<<mesh->mName.data<<"   Please, fix it");
			OUTPUT_DEBUG_MSG("Problem: Tangents were not created. No known fix");
			continue;
		}
		OUTPUT_DEBUG_MSG("Loading "<<mesh->mNumBones<<" bones . . .");
		for( unsigned int a = 0; a < mesh->mNumBones; a++)	{
			const aiBone* bone = mesh->mBones[a];
			size_t bonein(-1);
			for(size_t ib(0); ib< bonenames.size(); ib++){
				std::string tname = bone->mName.data;
				if(tname == bonenames[ib]){// found the bone.. break
					bonein=ib;
					break;
				}
			}
			if(bonein ==-1){//  did not find the bone, this is a new one push back
				bonein = bonenames.size();// get the index before insertion
				bonenames.push_back(bone->mName.data);
			}
			// there should only be 4 per vertex here because assimp guaranteees it, but if there are more, we are ok
			for( unsigned int b = 0; b < bone->mNumWeights; b++){
				if(			tempverts[bone->mWeights[b].mVertexId+ currentvertex].Weights.x <= 0.f) {
							tempverts[bone->mWeights[b].mVertexId+ currentvertex].Bones[0] = static_cast<float>(bonein);
							tempverts[bone->mWeights[b].mVertexId+ currentvertex].Weights.x = bone->mWeights[b].mWeight;
				} else if(	tempverts[bone->mWeights[b].mVertexId+ currentvertex].Weights.y <= 0.f){
							tempverts[bone->mWeights[b].mVertexId+ currentvertex].Bones[1] = static_cast<float>(bonein);
							tempverts[bone->mWeights[b].mVertexId+ currentvertex].Weights.y = bone->mWeights[b].mWeight;
				} else if(	tempverts[bone->mWeights[b].mVertexId+ currentvertex].Weights.z <= 0.f){
							tempverts[bone->mWeights[b].mVertexId+ currentvertex].Bones[2] = static_cast<float>(bonein);
							tempverts[bone->mWeights[b].mVertexId+ currentvertex].Weights.z = bone->mWeights[b].mWeight;
				} else if(	tempverts[bone->mWeights[b].mVertexId+ currentvertex].Weights.w <= 0.f){
							tempverts[bone->mWeights[b].mVertexId+ currentvertex].Bones[3] = static_cast<float>(bonein);
							tempverts[bone->mWeights[b].mVertexId+ currentvertex].Weights.w = bone->mWeights[b].mWeight;
				}
			}
			
		}
		for (unsigned int x = 0; x < mesh->mNumVertices;++x){
			Vertices[x + currentvertex] = tempverts[x + currentvertex].Pos = *reinterpret_cast<vec3*>(&mesh->mVertices[x]);
			tempverts[x + currentvertex].Tex =  *reinterpret_cast<vec2*>(&mesh->mTextureCoords[0][x]);
			tempverts[x + currentvertex].Norm = *reinterpret_cast<vec3*>(&mesh->mNormals[x]);
			tempverts[x + currentvertex].Tang = *reinterpret_cast<vec3*>(&mesh->mTangents[x]);
		}
		// check whether we can use 16 bit indices for our format... the ASSIMPOBLARBLA uses 32 bit indices for all theirs..
		if (IB.Stride == 4){
			uint32_t* pbData = reinterpret_cast<uint32_t*>(&Indices[currentindex]);
			for (unsigned int x = 0; x < mesh->mNumFaces;++x){
				for (unsigned int a = 0; a < 3 ;++a) {
					*pbData++ = static_cast<uint32_t>(mesh->mFaces[x].mIndices[a]+ currentvertex);
				}
			}
		} else {
			uint16_t* pbData = reinterpret_cast<uint16_t*>(&Indices[currentindex]);
			for (unsigned int x = 0; x < mesh->mNumFaces;++x){
				for (unsigned int a = 0; a < 3 ;++a) {
					*pbData++ = static_cast<uint16_t>(mesh->mFaces[x].mIndices[a]+ currentvertex);
				}
			}
		}
		//load the textures
		std::string pathtomodel(GetPath(file));
		Batch *batch = new Batch();

		LoadMaterials(mesh, load->mMaterials, batch, pathtomodel, Asset_Dir);
		batch->NumIndices=mesh->mNumFaces*3;
		batch->StartIndex = static_cast<uint32_t>(currentindex);
		batch->NumVerts= mesh->mNumVertices;
		// make sure to increment the ref count for thesse so they are properly destroyed

		currentvertex+=mesh->mNumVertices;
		currentindex+=mesh->mNumFaces*3;

		//For now, there will be a new shader for each material. I will create a shader cache where the graphics lib will cache the shaders and issue out already created shaders like it does with textures.
		Graphics::Shader_Macro macro1[] = {
			{"NORMALMAP", "1" }, 
			{"MATRIX_PALETTE_SIZE_DEFAULT", "60" }, 
			{NULL, NULL}
		};
		Graphics::Shader_Macro macro0[] = {
			{"NORMALMAP", "0" }, 
			{"MATRIX_PALETTE_SIZE_DEFAULT", "60" }, 
			{NULL, NULL}
		};

		Graphics::Shader_Macro* ptr = nullptr;
		if(batch->Has_NormalMap()) ptr = macro1;
		else ptr = macro0;

		batch->GetVS()->CompileShaderFromFile("Animated_Mesh.fx", "VS", "vs_4_0", ptr);

		FormatDesc lay[] = {
			FormatDesc(),
			FormatDesc(TYPE_TEXCOORD, FORMAT_FLOAT, 2),
			FormatDesc(TYPE_NORMAL, FORMAT_FLOAT, 3),
			FormatDesc(TYPE_TANGENT, FORMAT_FLOAT, 3),
			FormatDesc(TYPE_BONE, FORMAT_FLOAT, 4),
			FormatDesc(TYPE_WEIGHT, FORMAT_FLOAT, 4)
		};
		batch->GetVS()->CreateInputLayout(lay, sizeof(lay)/sizeof(FormatDesc));
		batch->GetPS()->CompileShaderFromFile("Animated_Mesh.fx", "PS", "ps_4_0", ptr);

		Batches.push_back(batch);
	}
	Animatior.Init(load);
	aiReleaseImport(load);// free the resrouces
	if(currentvertex==0) {// this could happen, if so GET OUTOF HERE
		OUTPUT_DEBUG_MSG("Problem loading the mesh, there were no vertices loaded. Failed to load the mesh");
		return false;
	}
	VB[0].Create(currentvertex, sizeof(Vertex_Types::Pos_Tex_Norm_Tang_Bone_Weight), VERTEX_BUFFER, IMMUTABLE, CPU_NONE, &tempverts[0] );
	IB.Create(currentindex, IB.Stride, INDEX_BUFFER, IMMUTABLE, CPU_NONE, &Indices[0]); // create index buffer!
	OUTPUT_DEBUG_MSG("Finished Loading the Mesh");
	Name=FileName =file;
	return true;
}