bool EditPointsMeshOP::OnMouseDrag(int x, int y)
{
	if (!m_dragable) {
		return false;
	}

	if (m_select_center)
	{
		sm::vec2 pos = m_stage->TransPosScrToProj(x, y);
		m_center = pos;
		ee::SetCanvasDirtySJ::Instance()->SetDirty();
		return true;
	}

	if (SelectPointsMeshOP::OnMouseDrag(x, y))
		return true;

	Mesh* mesh = static_cast<StagePanel*>(m_wnd)->GetMesh();
	if (!mesh) return false;

	if (!m_selection.empty())
	{
		sm::vec2 pos = m_stage->TransPosScrToProj(x, y);
		if (m_right_press)
			RotateNode(pos);
		else
			TranslasteNode(pos - m_last_pos);
		m_last_pos = pos;
		ee::SetCanvasDirtySJ::Instance()->SetDirty();
		ee::SetWndDirtySJ::Instance()->SetDirty();
	}

	return false;
}
void CCharShape::AdjustJoints (ETR_DOUBLE turnFact, bool isBraking,
                               ETR_DOUBLE paddling_factor, ETR_DOUBLE speed,
                               const TVector3d& net_force, ETR_DOUBLE flap_factor) {
	ETR_DOUBLE turning_angle[2];
	ETR_DOUBLE paddling_angle = 0;
	ETR_DOUBLE ext_paddling_angle = 0;
	ETR_DOUBLE kick_paddling_angle = 0;
	ETR_DOUBLE braking_angle = 0;
	ETR_DOUBLE force_angle = 0;
	ETR_DOUBLE turn_leg_angle = 0;
	ETR_DOUBLE flap_angle = 0;

	if (isBraking) braking_angle = MAX_ARM_ANGLE2;

	paddling_angle = MAX_PADDLING_ANGLE2 * sin(paddling_factor * M_PI);
	ext_paddling_angle = MAX_EXT_PADDLING_ANGLE2 * sin(paddling_factor * M_PI);
	kick_paddling_angle = MAX_KICK_PADDLING_ANGLE2 * sin(paddling_factor * M_PI * 2.0);

	turning_angle[0] = max(-turnFact,0.0) * MAX_ARM_ANGLE2;
	turning_angle[1] = max(turnFact,0.0) * MAX_ARM_ANGLE2;
	flap_angle = MAX_ARM_ANGLE2 * (0.5 + 0.5 * sin (M_PI * flap_factor * 6 - M_PI / 2));
	force_angle = clamp (-20.0, -net_force.z / 300.0, 20.0);
	turn_leg_angle = turnFact * 10;

	ResetJoints ();

	RotateNode ("left_shldr", 3,
	            min (braking_angle + paddling_angle + turning_angle[0], MAX_ARM_ANGLE2) + flap_angle);
	RotateNode ("right_shldr", 3,
	            min (braking_angle + paddling_angle + turning_angle[1], MAX_ARM_ANGLE2) + flap_angle);

	RotateNode ("left_shldr", 2, -ext_paddling_angle);
	RotateNode ("right_shldr", 2, ext_paddling_angle);
	RotateNode ("left_hip", 3, -20 + turn_leg_angle + force_angle);
	RotateNode ("right_hip", 3, -20 - turn_leg_angle + force_angle);

	RotateNode ("left_knee", 3,
	            -10 + turn_leg_angle - min (35.0f, speed) + kick_paddling_angle + force_angle);
	RotateNode ("right_knee", 3,
	            -10 - turn_leg_angle - min (35.0f, speed) - kick_paddling_angle + force_angle);

	RotateNode ("left_ankle", 3, -20 + min (50.0f, speed));
	RotateNode ("right_ankle", 3, -20 + min (50.0f, speed));
	RotateNode ("tail", 3, turnFact * 20);
	RotateNode ("neck", 3, -50);
	RotateNode ("head", 3, -30);
	RotateNode ("head", 2, -turnFact * 70);
}
bool CCharShape::Load (const string& dir, const string& filename, bool with_actions) {
	CSPList list (500);

	useActions = with_actions;
	CreateRootNode ();
	newActions = true;

	if (!list.Load (dir, filename)) {
		Message ("could not load character", filename);
		return false;
	}

	for (size_t i=0; i<list.Count(); i++) {
		const string& line = list.Line(i);
		int node_name = SPIntN (line, "node", -1);
		int parent_name = SPIntN (line, "par", -1);
		string mat_name = SPStrN (line, "mat");
		string name = SPStrN (line, "joint");
		string fullname = SPStrN (line, "name");

		if (SPIntN (line, "material", 0) > 0) {
			CreateMaterial (line);
		} else {
			float visible = SPFloatN (line, "vis", -1.0);
			bool shadow = SPBoolN (line, "shad", false);
			string order = SPStrN (line, "order");
			CreateCharNode (parent_name, node_name, name, fullname, order, shadow);
			TVector3d rot = SPVector3d(line, "rot");
			MaterialNode (node_name, mat_name);
			for (size_t ii = 0; ii < order.size(); ii++) {
				int act = order[ii]-48;
				switch (act) {
					case 0: {
						TVector3d trans = SPVector3d(line, "trans");
						TranslateNode (node_name, trans);
						break;
					}
					case 1:
						RotateNode (node_name, 1, rot.x);
						break;
					case 2:
						RotateNode (node_name, 2, rot.y);
						break;
					case 3:
						RotateNode (node_name, 3, rot.z);
						break;
					case 4: {
						TVector3d scale = SPVector3(line, "scale", TVector3d(1, 1, 1));
						ScaleNode (node_name, scale);
						break;
					}
					case 5:
						VisibleNode (node_name, visible);
						break;
					case 9:
						RotateNode (node_name, 2, rot.z);
						break;
					default:
						break;
				}
			}
		}
	}
	newActions = false;
	return true;
}
bool CCharShape::RotateNode (const string& node_trivialname, int axis, ETR_DOUBLE angle) {
	map<string, size_t>::const_iterator i = NodeIndex.find(node_trivialname);
	if (i == NodeIndex.end()) return false;
	return RotateNode (i->second, axis, angle);
}
Exemple #5
0
void CCharShape::AdjustJoints (double turnFact, bool isBraking, 
			double paddling_factor, double speed,
			TVector3 net_force, double flap_factor) {
    double turning_angle[2] = {0, 0};
    double paddling_angle = 0;
    double ext_paddling_angle = 0; 
    double kick_paddling_angle = 0;
    double braking_angle = 0;
    double force_angle = 0;
    double turn_leg_angle = 0;
    double flap_angle = 0;

    if (isBraking) braking_angle = MAX_ARM_ANGLE2;

    paddling_angle = MAX_PADDLING_ANGLE2 * sin(paddling_factor * M_PI);
    ext_paddling_angle = MAX_EXT_PADDLING_ANGLE2 * sin(paddling_factor * M_PI);
    kick_paddling_angle = MAX_KICK_PADDLING_ANGLE2 * sin(paddling_factor * M_PI * 2.0);

    turning_angle[0] = MAX(-turnFact,0.0) * MAX_ARM_ANGLE2;
    turning_angle[1] = MAX(turnFact,0.0) * MAX_ARM_ANGLE2;
    flap_angle = MAX_ARM_ANGLE2 * (0.5 + 0.5 * sin (M_PI * flap_factor * 6 - M_PI / 2));
    force_angle = max (-20.0, min (20.0, -net_force.z / 300.0));
    turn_leg_angle = turnFact * 10;
    
	ResetJoints ();

    RotateNode ("left_shldr", 3, 
		    MIN (braking_angle + paddling_angle + turning_angle[0], MAX_ARM_ANGLE2) + flap_angle);
    RotateNode ("right_shldr", 3,
		    MIN (braking_angle + paddling_angle + turning_angle[1], MAX_ARM_ANGLE2) + flap_angle);

    RotateNode ("left_shldr", 2, -ext_paddling_angle);
    RotateNode ("right_shldr", 2, ext_paddling_angle);
    RotateNode ("left_hip", 3, -20 + turn_leg_angle + force_angle);
    RotateNode ("right_hip", 3, -20 - turn_leg_angle + force_angle);
	
    RotateNode ("left_knee", 3, 
		-10 + turn_leg_angle - MIN (35, speed) + kick_paddling_angle + force_angle);
    RotateNode ("right_knee", 3, 
		-10 - turn_leg_angle - MIN (35, speed) - kick_paddling_angle + force_angle);

    RotateNode ("left_ankle", 3, -20 + MIN (50, speed));
    RotateNode ("right_ankle", 3, -20 + MIN (50, speed));
    RotateNode ("tail", 3, turnFact * 20);
    RotateNode ("neck", 3, -50);
    RotateNode ("head", 3, -30);
    RotateNode ("head", 2, -turnFact * 70);
}
Exemple #6
0
bool CCharShape::Load (string dir, string filename, bool with_actions) {
	CSPList list (500);
	int i, ii, act;
	string line, order, name, mat_name, fullname;
	TVector3 scale, trans, rot;
	double visible;
	bool shadow;
	int node_name, parent_name;

	useActions = with_actions;
	CreateRootNode ();
	newActions = true;

	file_name = filename;
 	if (!list.Load (dir, filename)) {
		Message ("could not load character", filename.c_str());
		return false;
	}

	for (i=0; i<list.Count(); i++) {
		line = list.Line (i);
		node_name = SPIntN (line, "node", -1); 
		parent_name = SPIntN (line, "par", -1);		
		mat_name = SPStrN (line, "mat", "");
		name = SPStrN (line, "joint", "");	
		fullname = SPStrN (line, "name", "");

		if (SPIntN (line, "material", 0) > 0) {
			CreateMaterial (line.c_str());
			if (useActions) {
				Matlines[numMatlines] = line;
				numMatlines++;
			}
		} else {
			visible = SPFloatN (line, "vis", -1.0);	
			shadow = SPBoolN (line, "shad", false);
			order = SPStrN (line, "order", "");
 			CreateCharNode (parent_name, node_name, name, fullname, order, shadow);					
			rot = SPVector3N (line, "rot", NullVec);
			MaterialNode (node_name, mat_name);
			for (ii=0; ii<(int)order.size(); ii++) {
				act = order.at(ii)-48;	
				switch (act) {
					case 0:
						trans = SPVector3N (line, "trans", MakeVector (0,0,0));
						TranslateNode (node_name, trans);
						break;
					case 1: RotateNode (node_name, 1, rot.x); break;
					case 2: RotateNode (node_name, 2, rot.y); break;
					case 3: RotateNode (node_name, 3, rot.z); break;
					case 4:
						scale = SPVector3N (line, "scale", MakeVector (1,1,1));
						ScaleNode (node_name, scale);
						break;
					case 5: VisibleNode (node_name, visible); break;
					case 9: RotateNode (node_name, 2, rot.z); break;
					default: break;
				}
			}
		}
	}
	newActions = false;
	return true;
}
Exemple #7
0
bool CCharShape::RotateNode (string node_trivialname, int axis, double angle) {
	int node_name = SPIntN (NodeIndex, node_trivialname, -1);
	if (node_name < 0) return false;
	return RotateNode (node_name, axis, angle);
}