Beispiel #1
0
void 	CIKLimb::BonesCallback1				(CBoneInstance* B)
{
	SCalculateData* D=(SCalculateData*)B->Callback_Param;
	CIKLimb*		L=D->m_limb							;

	float	const	*x=D->m_angles						;
	
	
	Fmatrix 	bm;//B->mTransform					;
	bm.rotateY(x[3])								;
	CKinematics	*K=D->m_K;
	CBoneData& BD=K->LL_GetData(L->m_bones[1]);

	Fmatrix cmp_save;cmp_save.set(B->mTransform)	;
	B->mTransform.mul_43(K->LL_GetTransform(BD.GetParentID()),BD.bind_transform);

	Fmatrix dd;dd.mul_43(Fmatrix().invert(B->mTransform),cmp_save);
	Fvector a;dd.getXYZ(a);
	B->mTransform.mulB_43(bm)		;

	Fmatrix cmp_savei;cmp_savei.invert(cmp_save);
	Fmatrix dif;dif.mul_43(cmp_savei,B->mTransform);

	
}
Beispiel #2
0
void 	CIKLimb::BonesCallback2				(CBoneInstance* B)
{
	SCalculateData* D=(SCalculateData*)B->Callback_Param;
	CIKLimb*		L=D->m_limb							;
	float	const	*x=D->m_angles						;
	{
		Fmatrix 	bm;//=B->mTransform					;
		//tmp_pos		.set(bm.c)						;
	//	Fvector		ra;B->mTransform.getXYZ(ra)			;
	//	bm			.setXYZ(-x[4],-x[5],-x[6])				;
		Matrix tbm;
		float t[3];
		
		 t[0] = x[6]; t[1] = x[5]; t[2] = x[4]			;
		EulerEval(ZXY,t,tbm)							;
		IM2XM(tbm,bm)									;
		CKinematics	*K=D->m_K;
		CBoneData& BD=K->LL_GetData(L->m_bones[2])		;
		Fmatrix start;start.mul_43(K->LL_GetTransform(BD.GetParentID()),BD.bind_transform);
		Fmatrix inv_start;inv_start.invert(start);
		Fmatrix dif;dif.mul_43(inv_start,B->mTransform);
		Fmatrix ikdif;
		Fvector a;
		dif.getXYZ(a);
		XM2IM(dif,ikdif);

		//B->mTransform.mul_43(K->LL_GetTransform(BD.GetParentID()),BD.bind_transform);
		//B->mTransform.mulB_43(bm)						;
		
		B->mTransform.mul_43(start,bm);
#ifdef DEBUG

		if(ph_dbg_draw_mask.test(phDbgDrawIKGoal))
		{
			Fmatrix DBGG;
			DBGG.mul_43(*D->m_obj,B->mTransform);
			DBG_DrawMatrix(DBGG,0.3f);
			
			
			DBGG.mul_43(*D->m_obj,start);
			DBG_DrawMatrix(DBGG,0.3f);

		}
#endif
		//bm.c		.set(tmp_pos)						;
	}
}
bool ESceneObjectTool::ExportClimableObjects(SExportStreams* F)
{
	bool bResult                    = true;
    CGeomPartExtractor* extractor   = 0;

    Fbox 		bb;
    if (!GetBox(bb))
        return  false;

    extractor	                    = xr_new<CGeomPartExtractor>();
    extractor->Initialize           (bb,EPS_L,int_max);

    UI->SetStatus	("Export climable objects...");
	// collect verts&&faces
    {
	    SPBItem* pb                 = UI->ProgressStart(m_Objects.size(), "Prepare geometry...");
        for (ObjectIt it=m_Objects.begin(); it!=m_Objects.end(); it++)
        {
	        pb->Inc();
            CSceneObject* obj 		= dynamic_cast<CSceneObject*>(*it);
            VERIFY                  (obj);
            if (obj->IsStatic())
            {
                CEditableObject *O 	= obj->GetReference();
                const Fmatrix& T 	= obj->_Transform();
                
                for(EditMeshIt M =O->FirstMesh(); M!=O->LastMesh(); M++)
                    if (!build_mesh	(T, *M, extractor, SGameMtl::flClimable, TRUE))
                    {
                      bResult       = false;
                      break;
                    }
            }
        }
	    UI->ProgressEnd(pb);
    }
    if (!extractor->Process())
        bResult                     = false;

    // export parts
    if (bResult)
    {
    	SBPartVec& parts			= extractor->GetParts();
	    SPBItem* pb                 = UI->ProgressStart(parts.size(),"Export Parts...");
        for (SBPartVecIt p_it=parts.begin(); p_it!=parts.end(); p_it++)
        {
	        pb->Inc                 ();
            SBPart*	P				= *p_it;
        	if (P->Valid())
            {
                // export visual
                AnsiString sn		            = AnsiString().sprintf("clmbl#%d",(p_it-parts.begin()));

				Fvector local_normal	        = {0,0,0};

                LPCSTR mat_name = NULL;
                for (SBFaceVecIt it=P->m_Faces.begin(); it!=P->m_Faces.end(); it++)
                {
                	for (u32 k=0; k<3; k++)
                        local_normal.add	        ((*it)->n[k]);

                    mat_name     = (*it)->surf->_GameMtlName();
                }

                local_normal.normalize_safe		();
                
                // export spawn object
                {
                    AnsiString entity_ref		= "climable_object";
                    ISE_Abstract*	m_Data		= create_entity(entity_ref.c_str()); 	VERIFY(m_Data);
                    ISE_Shape* m_Shape			= m_Data->shape();                      VERIFY(m_Shape);
//					CSE_Visual* m_Visual		= m_Data->visual();	VERIFY(m_Visual);
                    // set params
                    m_Data->set_name			(entity_ref.c_str());
                    m_Data->set_name_replace	(sn.c_str());
                    // set shape
                    CShapeData::shape_def		shape;
                    shape.type					= CShapeData::cfBox;
                    shape.data.box.scale		((P->m_BBox.max.x-P->m_BBox.min.x)*0.5f,
                    							(P->m_BBox.max.y-P->m_BBox.min.y)*0.5f,
                                                (P->m_BBox.max.z-P->m_BBox.min.z)*0.5f);
                    m_Shape->assign_shapes		(&shape,1);
					// orientate object
	          		if (!OrientToNorm(local_normal,P->m_OBB.m_rotate,P->m_OBB.m_halfsize))
                    {
                    	ELog.Msg(mtError,"Invalid climable object found. [%3.2f, %3.2f, %3.2f]",VPUSH(P->m_RefOffset));
					}
                    else
                    {
                        Fmatrix M; M.set			(P->m_OBB.m_rotate.i,P->m_OBB.m_rotate.j,P->m_OBB.m_rotate.k,P->m_OBB.m_translate);
                        M.getXYZ					(P->m_RefRotate); // не i потому что в движке так
                        m_Data->position().set		(P->m_RefOffset); 
                        m_Data->angle().set			(P->m_RefRotate);

                        m_Data->set_additional_info((void*)mat_name);
                        NET_Packet					Packet;
                        m_Data->Spawn_Write			(Packet,TRUE);

                        F->spawn.stream.open_chunk	(F->spawn.chunk++);
                        F->spawn.stream.w			(Packet.B.data,Packet.B.count);
                        F->spawn.stream.close_chunk	();

						if (s_draw_dbg)
                        {
                            Tools->m_DebugDraw.AppendOBB(P->m_OBB);
                            M.transform_dir				(local_normal);
                            Tools->m_DebugDraw.AppendLine(P->m_RefOffset,Fvector().mad(P->m_RefOffset,local_normal,1.f));
                        }
                    }
                    destroy_entity				(m_Data);
                }
            }else
            {
            	ELog.Msg(mtError,"Can't export invalid part #%d",p_it-parts.begin());
            }
        }
	    UI->ProgressEnd     (pb);
    }
    // clean up
    xr_delete               (extractor);

    return                  bResult;
}