int do_take(string arg) { object me=this_player(), ob; string weapon, destination, type; if (!arg) return notify_fail("你要拿什么?\n"); if (me->is_busy()) return notify_fail("你上一个动作还没有完成!\n"); if (sscanf(arg, "%s from %s", weapon, destination)!=2) return notify_fail("用 take <weapon> from <wall|四壁> 来拿想用的兵器。\n"); if (destination != "wall" && destination != "四壁") return notify_fail("从哪里拿?\n"); if (weapon == "chang jian" || weapon == "changjian" || weapon == "长剑" || weapon == "duan jian" || weapon == "duanjian" || weapon == "短剑" || weapon == "zhu jian" || weapon == "zhujian" || weapon == "竹剑") { if (present("sword", me)) return notify_fail("别这么自私,身上不是有一柄剑了吗?\n"); if(present("sword", environment(me))) return notify_fail("地上不是有吗?\n"); type = "sword"; } if (weapon == "dan dao" || weapon == "dandao" || weapon == "单刀" || weapon == "mu dao" || weapon == "mudao" || weapon == "木刀") { if (present("blade", me)) return notify_fail("别这么自私,身上不是有一柄刀了吗?\n"); if(present("blade", environment(me))) return notify_fail("地上不是有吗?\n"); type = "blade"; } if (weapon == "chang jian" || weapon == "changjian" || weapon == "长剑") { weapon = "changjian"; } if (weapon == "duan jian" || weapon == "duanjian" || weapon == "短剑") { weapon ="duanjian"; } if (weapon == "zhu jian" || weapon == "zhujian" || weapon == "竹剑") { weapon ="zhujian"; } if (weapon == "dan dao" || weapon == "dandao" || weapon == "单刀") { weapon ="dandao"; } if (weapon == "mu dao" || weapon == "mudao" || weapon == "木刀") { weapon ="mudao"; } if(amount[weapon]==0) return notify_fail("墙上已经没有你要的兵器了。\n"); ob=new("/d/obj/weapon/"+type+"/"+weapon); amount[weapon]-=1; if (amount[weapon] == 0) msg[weapon]=""; else msg[weapon]="\t"+chinese_number(amount[weapon])+ob->query("unit")+ ob->query("name")+ "("+ob->query("id")+")\n"; message_vision("$N从墙上取下一"+ob->query("unit")+ob->query("name")+"。\n", me); update_wall(); ob->move(me); return 1; }
void OnTimer(int value) { glutTimerFunc(20, &OnTimer, value); old_t = t; t = (GLfloat)glutGet(GLUT_ELAPSED_TIME)/1000.0; delta_t = (t - old_t); //printf("%f\n", delta_t); GLfloat tmpppp[3] = {cow.pos.x, cow.pos.y, cow.pos.z}; glUniform3fv(glGetUniformLocation(g_shader, "cow_pos"), 1, tmpppp); turn_cow(&cow, -m_angle); update_cow(&cow, delta_t); update_fence(&ff, &cow, delta_t); move_cow(&cow, m_angle); update_floor(&f, &cow); update_wall(&wall, &cow, delta_t); update_ball(&ball, &cow, delta_t); update_farmer(&farmer); if(keyIsDown('k')) update_ragdoll(&ragdoll, delta_t); if(check_collision_2(&cow.bb, &wall.bb)) { //printf("yey\n"); glUniform1i(glGetUniformLocation(g_shader, "collision"), 1); //cow.momentum = SetVector(-cow.momentum.x, cow.momentum.y, -cow.momentum.z); //wall_collision(wall, cow); } else glUniform1i(glGetUniformLocation(g_shader, "collision"), 0); //printf("%f, %f\n", delta_t, old_t); glUniform1f(glGetUniformLocation(g_shader, "time"), t); mat4 proj_matrix = frustum(-1, 1, -1, 1, 1, 750.0); mat4 cam_matrix = lookAt(cam_dist*cos(m_angle)+cow.pos.x, 9+cow.pos.y, cam_dist*sin(m_angle)+cow.pos.z, cow.pos.x, 8.5+cow.pos.y, cow.pos.z, 0.0, 1.0, 0.0); //mat4 cam_matrix = lookAt(200+200*cos(cam_angle), 0, 200, 0, 8, 0, 0.0, 1.0, 0.0); //g_shader = loadShaders("shader.vert" , "shader.frag"); //glUseProgram(g_shader); glUniformMatrix4fv(glGetUniformLocation(g_shader, "proj_matrix"), 1, GL_TRUE, proj_matrix.m); glUniformMatrix4fv(glGetUniformLocation(g_shader, "cam_matrix"), 1, GL_TRUE, cam_matrix.m); //glutDisplayFunc(DisplayWindow); //draw_cow(&cow, g_shader); //draw_bone(&bone, g_shader); mat4 tmp, testjoint, testjoint2; testjoint = IdentityMatrix(); joint_s * j = &head_joint[0]; joint_s * jc = j->child[0]; joint_s * jcc = jc->child[0]; //joint_s * jp = j->parent; //joint_s * jpp = jp->parent; float Ms[8][4*4]; float legMs[8][4*4]; float currpos[8*3] = {0}; float bonepos[8*3] = {0}; float legcurrpos[8*3] = {0}; float legbonepos[8*3] = {0}; //GLfloat * Mtmp = Ms; int i=0, ii=0; //jc->R = ArbRotate(SetVector(0,0,1), cos(4*t/(i+1))/2.5); //j->R = ArbRotate(SetVector(0,0,1), 0); j->R = ArbRotate(SetVector(0,0,1), sin(4*t/(3+1))/1.2); //jcc->R = ArbRotate(SetVector(0,0,1), cos(8*t/(2+1))/4); mat4 Mpacc, Minvacc, tmptrans, tmppp, invtrans; tmppp = IdentityMatrix(); float freq = 7;//Norm(cow.speed)/4; if(Norm(cow.momentum) < .5) freq = 0; else if(Norm(cow.momentum) > 5) freq = 20; //printf("%f\n", freq); j = &thigh_joint[0]; jc = j->child[0]; j->R = ArbRotate(SetVector(0,0,1), sin(freq*t)/1.5); jc->R = ArbRotate(SetVector(0,0,1), cos(freq*t)/2.5); j = &thigh_joint[1]; jc = j->child[0]; j->R = ArbRotate(SetVector(0,0,1), -cos(freq*t)/2.5); jc->R = ArbRotate(SetVector(0,0,1), sin(freq*t)/2.5); j = &thigh_joint[2]; jc = j->child[0]; j->R = ArbRotate(SetVector(0,0,1), sin(freq*t)/1.5); jc->R = ArbRotate(SetVector(0,0,1), cos(freq*t)/2.5); j = &thigh_joint[3]; jc = j->child[0]; j->R = ArbRotate(SetVector(0,0,1), -cos(freq*t)/2.5); jc->R = ArbRotate(SetVector(0,0,1), sin(freq*t)/2.5); j = &legbase_joint[0]; //j->R = ArbRotate(SetVector(1,0,0), -cos(7*t/(i+1))); //j->R = ArbRotate(SetVector(1,0,0), -M_PI/6); j = &thigh_joint[0]; //j->R = Mult(ArbRotate(SetVector(1,0,0), cos(7*t/(i+1))), j->R); //j->R = Mult(ArbRotate(SetVector(1,0,0), M_PI/6), j->R); i = 0; tmppp = IdentityMatrix(); //legbase_joint[0].R = ArbRotate(SetVector(0,0,1), cos(3*t)/2); //legs calc_bone_transform(&legbase_joint[0], 0); calc_bone_transform(&legbase_joint[1], 0); calc_bone_transform(&legbase_joint[2], 0); calc_bone_transform(&legbase_joint[3], 0); j = &tail_joint[0]; j->R = ArbRotate(SetVector(0,0,1), -M_PI/2.5); j = &tail_joint[1]; j->R = ArbRotate(SetVector(0,0,1), -M_PI/8.5); //j = &tail_joint[1]; //j->R = ArbRotate(SetVector(0,0,1), 0); j = &tail_joint[2]; //j->R = ArbRotate(SetVector(0,0,1), 0); j = &tail_joint[3]; j->R = ArbRotate(SetVector(0,0,1), 0); //body j = &body_joint[1]; //j->R = ArbRotate(SetVector(0,0,1), cos(t*7)/9.5); j->R = ArbRotate(SetVector(0,1,0), m_angle + cow.angle); j->R = Mult(j->R, ArbRotate(SetVector(0,0,1), cos(freq*t)/9)); calc_bone_transform(&body_joint[0],0); //tail //j = &tail_joint[1]; //j->R = ArbRotate(SetVector(0,0,1), -M_PI/2.5); //j = &tail_joint[1]; //j->R = ArbRotate(SetVector(0,0,1), 0); //j = &tail_joint[2]; //j->R = ArbRotate(SetVector(0,0,1), 0); //j = &tail_joint[3]; //j->R = ArbRotate(SetVector(0,0,1), 0); //calc_bone_transform(&tail_joint[0],0); //head j = &head_joint[0]; j->R = ArbRotate(SetVector(0,0,1), sin(7*t)/9.5); calc_bone_transform(&head_joint[0],0); j = &farmer.skeleton.joints[2]; //j->R = Rx(cos(4*t)); j->R = Mult(Rx(M_PI/2.2 + sin(5*t)/11), Ry(cos(-5*t)/2)); j = &farmer.skeleton.joints[3]; //j->R = Rx(cos(4*t)); j->R = Mult(Rx(-M_PI/2.2 + sin(5*t)/11), Ry(cos(5*t)/2)); //left shoulder (her right) //jc = &farmer.skeleton.joints[3]; //jc->R = Rx(-sin(3*t)); jc = &farmer.skeleton.joints[4]; jc->R = Ry(M_PI/3 + cos(5*t)/8); jc = &farmer.skeleton.joints[5]; jc->R = Ry(-M_PI/3 + cos(5*t)/8); jc = &farmer.skeleton.joints[10]; //jc->R = Rz(M_PI/3); jc->R = Rz(.5-cos(5*t)); jc = &farmer.skeleton.joints[12]; jc->R = Rz((-1-cos(5*t))/2); jc = &farmer.skeleton.joints[11]; //jc->R = Rz(M_PI/3); jc->R = Rz(.5+cos(5*t)); jc = &farmer.skeleton.joints[13]; jc->R = Rz((-1-cos(5*t))/2); calc_bone_transform(&farmer.skeleton.joints[0], 0); calc_bone_transform(&farmer.skeleton.joints[2], 0); calc_bone_transform(&farmer.skeleton.joints[3], 0); //calc_bone_transform(&farmer.skeleton.joints[4], 0); calc_bone_transform(&farmer.skeleton.joints[1], 0); calc_bone_transform(&farmer.skeleton.joints[10], 0); calc_bone_transform(&farmer.skeleton.joints[11], 0); // calc_bone_transform(&farmer.skeleton.joints[8], 0); // calc_bone_transform(&farmer.skeleton.joints[9], 0); glutPostRedisplay(); }
void Cconfig::fread(Cin_out where_to_read) { where_to_read.set_file_name(); where_to_read.check_file(); P.clear(); C.clear(); ifstream file; file.open(where_to_read.save_file[0].c_str()); // read particles while(1<2) { Cparticle part; file>>part; if(!file.eof()) P.push_back(part); else break; } file.close(); file.open(where_to_read.save_file[1].c_str()); // read contact while(1<2) { Ccontact cont; file>> cont; if(!file.eof()) C.push_back(cont); else break; } file.close(); file.open(where_to_read.save_file[2].c_str());//save parameter file>>t; file>>parameter; file.close(); file.open(where_to_read.save_file[3].c_str()); //save cell file>>cell; file.close(); //bluild the pointers for(int ip=0;ip<P.size();ip++)//cell knows which particle is a plan { if(P[ip].AM_I_BOUNDARY==-2 ) cell.plan_bottom=&P[ip]; if(P[ip].AM_I_BOUNDARY==2 ) cell.plan_top=&P[ip]; P[ip].id=ip; } // if (BOUNDARY == "XXX") update_wall(); // update wall class for(int ic=0;ic<C.size();ic++) { C[ic].pA = &P[C[ic].A]; if(C[ic].B >=0) C[ic].pB = &P[C[ic].B]; else C[ic].pB = &Wall[-C[ic].B]; C[ic].cell = &cell; C[ic].parameter = ¶meter; P[C[ic].A].contact.push_back(&C[ic]); if(INIT_BOND != 0) C[ic].deltaNB = INIT_BOND; } parameter.RHO = 1.0; // NOTE, this is a default vaule, can be changed later. parameter.VOL_polymer = 0.0; update_particle(); parameter.dimensionless_number(cell,P); iterate(0.0);//use here to recover all the data that haven't been saved, but which derive from saved data }