view resources/human.js @ 0:0b8d8ce99f46 default tip

commit
author Daiki KINJYO <e085722@ie.u-ryukyu.ac.jp>
date Mon, 14 Feb 2011 17:06:56 +0900
parents
children
line wrap: on
line source

createHuman = function(sgroot, w, h){
	var walk_man = new sgroot.createSceneGraph3();
	walk_man.xyz[0] = 100;
	walk_man.xyz[1] = -5;
	walk_man.xyz[2] = 100;
	position_xyz[0] = walk_man.xyz[0];
	position_xyz[1] = walk_man.xyz[1] - 10;
	position_xyz[2] = walk_man.xyz[2] - 50;
	aim_xyz[0] = position_xyz[0];
	aim_xyz[1] = position_xyz[1];
	aim_xyz[2] = position_xyz[2] + 1;
	walk_man.scale = 0.01;
	//walk_man.set_move_collision(body_move, body_collision)
	walk_man.set_move_collision(body_move, no_collision_idle);


	var head = new sgroot.createSceneGraph1("head");
	head.angle[0] = 90;
	head.angle[1] = 90;
	head.xyz[0] = -sgroot.sg_src["head"].model_x * 100;
	head.xyz[1] = -sgroot.sg_src["head"].model_y * 100;
	head.xyz[2] = -sgroot.sg_src["head"].model_z * 100;
	head.set_move_collision(head_move, no_collision_idle);


	var body = new sgroot.createSceneGraph1("body");
	body.xyz[0] = -sgroot.sg_src["body"].model_x * 100;
	body.xyz[1] = -sgroot.sg_src["body"].model_y * 100;
	body.xyz[2] = -sgroot.sg_src["body"].model_z * 100 + 200;
	body.set_move_collision(no_move_idle, no_collision_idle);


	var joint_rh = new sgroot.createSceneGraph1("Kata");
	/*joint_rh.xyz[0] = -sgroot.sg_src["green"].model_x * 7
	  joint_rh.xyz[1] =- sgroot.sg_src["green"].model_y * 7
	  joint_rh.xyz[2] = -sgroot.sg_src["green"].model_z * 7
	  */

	joint_rh.scale = 7;
	joint_rh.set_move_collision(joint_rh_move, no_collision_idle);


	var right_hand = new sgroot.createSceneGraph1("right_hand");
	right_hand.xyz[0] = -sgroot.sg_src["right_hand"].model_x * (100/7);
	right_hand.xyz[1] = -sgroot.sg_src["right_hand"].model_y * (100/7);
	right_hand.xyz[2] = -sgroot.sg_src["right_hand"].model_z * (100/7) - (sgroot.sg_src["right_hand"].w / 2);
	right_hand.scale = 1/7;
	right_hand.set_move_collision(right_hand_move, no_collision_idle);


	var joint_lh = new sgroot.createSceneGraph1("Kata");
	joint_lh.scale = 7;
	joint_lh.set_move_collision(joint_lh_move, no_collision_idle);


	var left_hand = new sgroot.createSceneGraph1("left_hand");
	left_hand.xyz[0] = -sgroot.sg_src["left_hand"].model_x * (100/7);
	left_hand.xyz[1] = -sgroot.sg_src["left_hand"].model_y * (100/7);
	left_hand.xyz[2] = -sgroot.sg_src["left_hand"].model_z * (100/7) - (sgroot.sg_src["left_hand"].w / 2);
	left_hand.scale = 1/7;
	left_hand.set_move_collision(left_hand_move, no_collision_idle);


	var joint_rl = new sgroot.createSceneGraph1("Kata");
	joint_rl.scale = 7;
	joint_rl.set_move_collision(joint_rl_move, no_collision_idle);

	var right_leg = new sgroot.createSceneGraph1("left_leg");
	right_leg.xyz[0] = -sgroot.sg_src["left_leg"].model_x * (100/7);
	right_leg.xyz[1] = -sgroot.sg_src["left_leg"].model_y * (100/7);
	right_leg.xyz[2] = -sgroot.sg_src["left_leg"].model_z * (100/7) - (sgroot.sg_src["left_leg"].w / 10);
	right_leg.scale = 1/7;
	right_leg.set_move_collision(right_leg_move, no_collision_idle);


	var joint_ll = new sgroot.createSceneGraph1("Kata");
	joint_ll.scale = 7;
	joint_ll.set_move_collision(joint_ll_move, no_collision_idle);


	var left_leg = new sgroot.createSceneGraph1("left_leg");
	left_leg.xyz[0] = -sgroot.sg_src["left_leg"].model_x * (100/7);
	left_leg.xyz[1] = -sgroot.sg_src["left_leg"].model_y * (100/7);
	left_leg.xyz[2] = -sgroot.sg_src["left_leg"].model_z * (100/7) - (sgroot.sg_src["left_leg"].w / 10);
	left_leg.scale = 1/7;
	left_leg.set_move_collision(left_leg_move, no_collision_idle);



	walk_man.addChild(head);
	head.addChild(body);

	body.addChild(joint_rh);
	joint_rh.addChild(right_hand);

	body.addChild(joint_lh);
	joint_lh.addChild(left_hand);

	body.addChild(joint_rl);
	joint_rl.addChild(right_leg);

	body.addChild(joint_ll);
	joint_ll.addChild(left_leg);



	return walk_man;

}


roteta_body = function(node, sgroot, w, h){
	node.angle[2] += 1;
}

head_move = function(node, sgroot, w, h){
	var move_eye = 1.0;
	var PI = 3.14;
	var pad = new sgroot.getController();
	var dx = node.parents.xyz[0] - position_xyz[0];
	var dz = node.parents.xyz[2] - position_xyz[2];
	var d = Math.sqrt(Math.pow(dx,2) + Math.pow(dz,2));


	if(pad.left_isHold()){
		cameraAngle_xyz[0] -= move_eye;
		theta += move_eye;
		var radian = ((theta%360) / 360) * 2 * PI;
		var x_rate = Math.sin(radian);
		var z_rate = Math.cos(radian);
		var mv_x = d * Math.cos(radian);
		var mv_z = d * Math.sin(radian);

		position_xyz[0] = node.parents.xyz[0] - mv_x;
		position_xyz[2] = node.parents.xyz[2] - mv_z;
		aim_xyz[0] = position_xyz[0] ;
		aim_xyz[2] = position_xyz[2] + 1;
		node.angle[0] -= move_eye;
		angleRate_xyz[0] = x_rate;
		angleRate_xyz[2] = z_rate;
	}


	if(pad.right_isHold()){
		cameraAngle_xyz[0] += move_eye;
		theta -= move_eye;
		var radian = ((theta%360) / 360) * 2 * PI;
		var x_rate = Math.sin(radian);
		var z_rate = Math.cos(radian);
		var mv_x = d * Math.cos(radian)		
        var mv_z = d * Math.sin(radian);

		position_xyz[0] = node.parents.xyz[0] - mv_x;
		position_xyz[2] = node.parents.xyz[2] - mv_z;
		aim_xyz[0] = position_xyz[0];
		aim_xyz[2] = position_xyz[2] + 1;
		node.angle[0] += move_eye;
		angleRate_xyz[0] = x_rate;
		angleRate_xyz[2] = z_rate;
	}


	if(pad.up_isHold() && cameraAngle_xyz[1] > -90){
		//node.angle[2] -= move_eye
		cameraAngle_xyz[1] -= move_eye;
	}

	if(pad.down_isHold() && cameraAngle_xyz[1] < 90){
		//node.angle[2] += move_eye
		cameraAngle_xyz[1] += move_eye;
	}

}



body_move = function(node, sgroot, w, h){
	var move_eye = 1.0;
	var move_walk = 1.0;
	var PI = 3.14;
	var pad = new sgroot.getController();
	var dx = position_xyz[0] - aim_xyz[0];
	var dz = position_xyz[2] - aim_xyz[2];
	var d = Math.sqrt(Math.pow(dx,2) + Math.pow(dz,2));

	//if(node.xyz[0] >= 0 && node.xyz[2] >= 0){
	if(pad.left_move_isHold()){
		var radian = (((theta+90)%360) / 360) * 2 * PI;

		if(!pad.zoom_in_isHold()){
			node.xyz[0] += move_walk * Math.cos(radian);
			node.xyz[2] += move_walk * Math.sin(radian);
		}

		aim_xyz[0] += move_walk * Math.cos(radian);
		aim_xyz[2] += move_walk * Math.sin(radian);
		position_xyz[0] += move_walk * Math.cos(radian);
		position_xyz[2] += move_walk * Math.sin(radian);
	}

	if(pad.right_move_isHold()){
		var radian = (((theta+90)%360) / 360) * 2 * PI;

		if(!pad.zoom_in_isHold()){
			node.xyz[0] -= move_walk * Math.cos(radian);
			node.xyz[2] -= move_walk * Math.sin(radian);
		}

		aim_xyz[0] -= move_walk * Math.cos(radian);
		aim_xyz[2] -= move_walk * Math.sin(radian);
		position_xyz[0] -= move_walk * Math.cos(radian);
		position_xyz[2] -= move_walk * Math.sin(radian);
	}

	if(pad.front_move_isHold()){
		var radian = ((theta%360) / 360) * 2 * PI;

		if(!pad.zoom_in_isHold()){
			node.xyz[0] += move_walk * Math.cos(radian);
			node.xyz[2] += move_walk * Math.sin(radian);
		}

		position_xyz[0] += move_walk * Math.cos(radian);
		position_xyz[2] += move_walk * Math.sin(radian);
		aim_xyz[0] += move_walk * Math.cos(radian);
		aim_xyz[2] += move_walk * Math.sin(radian);

		move_length++;
	}

	if(pad.back_move_isHold()){
		var radian = ((theta%360) / 360) * 2 * PI;

		if(!pad.zoom_in_isHold()){
			node.xyz[0] -= move_walk * Math.cos(radian);
			node.xyz[2] -= move_walk * Math.sin(radian);
		}

		position_xyz[0] -= move_walk * Math.cos(radian);
		position_xyz[2] -= move_walk * Math.sin(radian);
		aim_xyz[0] -= move_walk * Math.cos(radian);
		aim_xyz[2] -= move_walk * Math.sin(radian);

		move_length--;
	}
	//}

	if(pad.start_isHold()){
		var bullet_speed = 2;
		var radian_xz  = ((theta%360)/360) * 2 * PI;
		var radian_yz  = ((cameraAngle_xyz[1]%90)/90) * (PI / 2);
		var bullet = new sgroot.createSceneGraph1("yellow");
		bullet.xyz[0] = position_xyz[0] + Math.cos(radian_xz) * 200;
		bullet.xyz[1] = position_xyz[1] + Math.sin(radian_yz) * 200;
		bullet.xyz[2] = position_xyz[2] + Math.sin(radian_xz) * 200;
		bullet.dx = Math.cos(radian_xz) * bullet_speed;
		bullet.dy = Math.sin(radian_yz) * bullet_speed;
		bullet.dz = Math.sin(radian_xz) * bullet_speed;
		bullet.scale = 0.3;
		bullet.set_move_collision(bullet_move, no_collision_idle);
	}


	if(pad.space_isHold()){
		node.xyz[1] -= 0.8;
		position_xyz[1] -= 0.8;
		aim_xyz[1] -= 0.8;
	}else if(pad.space_isRelease() && node.xyz[1] < -5){
		node.xyz[1] += 0.4;
		position_xyz[1] += 0.4;
		aim_xyz[1] += 0.4;
	}
}



body_collision = function(node, sgroot, w, h){
	var dx = node.xyz[0] - position_xyz[0];
	var dz = node.xyz[2] - position_xyz[2];
	var d = Math.sqrt(Math.pow(dx,2) + Math.pow(dz,2));
	var PI = 3.14;
	var radian = ((theta%360) / 360) * 2 * PI;
	if(node.xyz[0] < 0){
		node.xyz[0] = 0;
		position_xyz[0] = -d * Math.cos(radian);
		aim_xyz[0] = position_xyz[0];
	}

	if(node.xyz[0] > 350){
		node.xyz[0] = 350;
		position_xyz[0] = 350 + (-d * Math.cos(radian));
		aim_xyz[0] = position_xyz[0];
	}


	if(node.xyz[2] < 0){
		node.xyz[2] = 0;
		position_xyz[2] = -d * Math.sin(radian);
		aim_xyz[2] = position_xyz[2] + 1;
	}

	if(node.xyz[2] > 350){
		node.xyz[2] = 350;
		position_xyz[2] = 350 + (-d * Math.sin(radian));
		aim_xyz[2] = position_xyz[2] + 1;
	}
}


right_hand_move = function(node, sgroot, w, h){
	var PI = 3.14;
	var radian = (((move_length*5)%360) / 360) * 2 * PI;
	var range = 90;
	node.angle[0] = Math.sin(radian) * range;
}


left_hand_move = function(node, sgroot, w, h){
	var PI = 3.14;
	var radian = (((move_length*5)%360) / 360) * 2 * PI;
	var range = 90;

	node.angle[0] = Math.sin(-radian) * range;
}


right_leg_move = function(node, sgroot, w, h){
	var PI = 3.14;
	var radian = (((move_length*5)%360) / 360) * 2 * PI;
	var range = 90;

	node.angle[0] = Math.sin(-radian) * range;
}


left_leg_move = function(node, sgroot, w, h){
	var PI = 3.14;
	var radian = (((move_length*5)%360) / 360) * 2 * PI;
	var range = 90;

	node.angle[0] = Math.sin(radian) * range;
}


joint_rh_move = function(node, sgroot, w, h){
	node.angle[1] = 45;
	node.xyz[0] =   0;
	node.xyz[1] = 300;
	node.xyz[2] = 100;
}

joint_lh_move = function(node, sgroot, w, h){
	node.angle[1] = -45;
	node.xyz[0] =     0;
	node.xyz[1] =  -300;
	node.xyz[2] =   100;
}


joint_rl_move = function(node, sgroot, w, h){	
	node.xyz[0] = 0;
	node.xyz[1] = -60;
	node.xyz[2] = 0;
}




joint_ll_move = function(node, sgroot, w, h){
	node.xyz[0] = 0;
	node.xyz[1] = 60;
	node.xyz[2] = 0;
}