temp=joints[jointlabels[leftknee]].position-(joints[jointlabels[lefthip]].position+joints[jointlabels[leftankle]].position)/2;
}
}
- /*
- if(terrain.patchobjectnum[whichpatchx][whichpatchz])
- for(m=0;m<terrain.patchobjectnum[whichpatchx][whichpatchz];m++){
- k=terrain.patchobjects[whichpatchx][whichpatchz][m];
- if(k<objects.numobjects&&k>=0)
- if(objects.possible[k]){
- temp=joints[jointlabels[head]].position*(*scale)+*coords;
- if(objects.model[k].SphereCheck(&temp, 0.06, &start, &objects.position[k], &objects.rotation[k])!=-1){
- //temp=(joints[jointlabels[head]].position*(*scale)+*coords)-start;
- //Normalise(&temp);
- //joints[jointlabels[head]].position=((temp*.2+start)-*coords)/(*scale);
- joints[jointlabels[head]].position=(temp-*coords)/(*scale);
- }
- }
- } */
-
-
- //Ears check
- /*XYZ startheadpos;
- startheadpos=joints[jointlabels[head]].position;
- XYZ headpos;
- headpos=joints[jointlabels[head]].position+(joints[jointlabels[head]].position-joints[jointlabels[neck]].position);
- if(terrain.patchobjectnum[whichpatchx][whichpatchz])
- for(m=0;m<terrain.patchobjectnum[whichpatchx][whichpatchz];m++){
- k=terrain.patchobjects[whichpatchx][whichpatchz][m];
- if(k<objects.numobjects&&k>=0)
- if(objects.possible[k]){
- friction=objects.friction[k];
- start=joints[jointlabels[head]].position*(*scale)+*coords;
- end=(headpos)*(*scale)+*coords;
- whichhit=objects.model[k].LineCheckPossible(&start,&end,&temp,&objects.position[k],&objects.rotation[k]);
- if(whichhit!=-1){
- if(joints[jointlabels[head]].label==groin&&!joints[jointlabels[head]].locked&&joints[jointlabels[head]].delay<=0){
- joints[jointlabels[head]].locked=1;
- joints[jointlabels[head]].delay=1;
- static float gLoc[3];
- static float vel[3];
- gLoc[0]=headpos.x*(*scale)+coords->x;
- gLoc[1]=headpos.y*(*scale)+coords->y;
- gLoc[2]=headpos.z*(*scale)+coords->z;
- vel[0]=joints[jointlabels[head]].velocity.x;
- vel[1]=joints[jointlabels[head]].velocity.y;
- vel[2]=joints[jointlabels[head]].velocity.z;
- PlaySoundEx( landsound1, samp[landsound1], NULL, true);
- OPENAL_3D_SetAttributes(channels[landsound1], gLoc, vel);
- OPENAL_SetVolume(channels[landsound1], 128);
- OPENAL_SetPaused(channels[landsound1], false);
-
- breaking=1;
- }
-
- if(joints[jointlabels[head]].label==head&&!joints[jointlabels[head]].locked&&joints[jointlabels[head]].delay<=0){
- joints[jointlabels[head]].locked=1;
- joints[jointlabels[head]].delay=1;
- static float gLoc[3];
- static float vel[3];
- gLoc[0]=headpos.x*(*scale)+coords->x;
- gLoc[1]=headpos.y*(*scale)+coords->y;
- gLoc[2]=headpos.z*(*scale)+coords->z;
- vel[0]=joints[jointlabels[head]].velocity.x;
- vel[1]=joints[jointlabels[head]].velocity.y;
- vel[2]=joints[jointlabels[head]].velocity.z;
- PlaySoundEx( landsound2, samp[landsound2], NULL, true);
- OPENAL_3D_SetAttributes(channels[landsound2], gLoc, vel);
- OPENAL_SetVolume(channels[landsound2], 128);
- OPENAL_SetPaused(channels[landsound2], false);
- }
-
- terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
- if(terrainnormal.y>.8)freefall=0;
- bounceness=terrainnormal*findLength(&joints[jointlabels[head]].velocity)*(abs(normaldotproduct(joints[jointlabels[head]].velocity,terrainnormal)));
- if(findLengthfast(&joints[jointlabels[head]].velocity)>findLengthfast(&joints[jointlabels[head]].oldvelocity)){
- bounceness=0;
- joints[jointlabels[head]].velocity=joints[jointlabels[head]].oldvelocity;
- }
- if(findLengthfast(&bounceness)>4000&&breaking){
- objects.model[k].MakeDecal(breakdecal,DoRotation(temp-objects.position[k],0,-objects.rotation[k],0),.4,.5,Random()%360);
- Sprite::MakeSprite(cloudsprite, headpos*(*scale)+*coords,joints[jointlabels[head]].velocity*.06, 1,1,1, 4, .2);
- breaking=0;
- camerashake+=.6;
-
- static float gLoc[3];
- static float vel[3];
- gLoc[0]=headpos.x*(*scale)+coords->x;
- gLoc[1]=headpos.y*(*scale)+coords->y;
- gLoc[2]=headpos.z*(*scale)+coords->z;
- vel[0]=joints[jointlabels[head]].velocity.x;
- vel[1]=joints[jointlabels[head]].velocity.y;
- vel[2]=joints[jointlabels[head]].velocity.z;
- PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
- OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
- OPENAL_SetVolume(channels[breaksound2], 300);
- OPENAL_SetPaused(channels[breaksound2], false);
-
- envsound[numenvsounds]=*coords;
- envsoundvol[numenvsounds]=64;
- envsoundlife[numenvsounds]=.4;
- numenvsounds++;
- }
- if(objects.type[k]==treetrunktype){
- objects.rotx[k]+=joints[jointlabels[head]].velocity.x*multiplier*.4;
- objects.roty[k]+=joints[jointlabels[head]].velocity.z*multiplier*.4;
- objects.rotx[k+1]+=joints[jointlabels[head]].velocity.x*multiplier*.4;
- objects.roty[k+1]+=joints[jointlabels[head]].velocity.z*multiplier*.4;
- }
- if(!joints[jointlabels[head]].locked)damage+=findLengthfast(&bounceness)/2500;
- ReflectVector(&joints[jointlabels[head]].velocity,&terrainnormal);
- frictionness=abs(normaldotproduct(joints[jointlabels[head]].velocity,terrainnormal));//findLength(&bounceness)/findLength(&joints[jointlabels[head]].velocity);
- joints[jointlabels[head]].velocity-=bounceness;
- if(1-friction*frictionness>0)joints[jointlabels[head]].velocity*=1-friction*frictionness;
- else joints[jointlabels[head]].velocity=0;
- if(findLengthfast(&bounceness)>2500){
- Normalise(&bounceness);
- bounceness=bounceness*50;
- }
- joints[jointlabels[head]].velocity+=bounceness*elasticity;
-
-
- if(!joints[jointlabels[head]].locked)
- if(findLengthfast(&joints[jointlabels[head]].velocity)<1){
- joints[jointlabels[head]].locked=1;
- //joints[jointlabels[head]].velocity*=3;
- }
- if(findLengthfast(&bounceness)>500)Sprite::MakeSprite(cloudsprite, headpos*(*scale)+*coords,joints[jointlabels[head]].velocity*.06, 1,1,1, .5, .2);
- joints[jointlabels[head]].position=(temp-*coords)/(*scale)+(startheadpos-headpos)+terrainnormal*.005;
- if(longdead>100)broken=1;
- }
- }
- }
- */
for(i=0; i<num_joints; i++){
//joints[i].delay-=multiplier/1.5;
}
tippoint[i]+=(mid-oldmid)*20;
}
- /*XYZ mid;
- mid=position[i]+tippoint[i];
- mid/=2;
- if(position[i].y<terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z)){
- hitsomething[i]=1;
- position[i].y=terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z);
-
- terrainnormal=terrain.getNormal(mid.x,mid.z);
- ReflectVector(&velocity[i],&terrainnormal);
- position[i]+=terrainnormal*.002;
- bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
- if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
- frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
- velocity[i]-=bounceness;
- if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
- else velocity[i]=0;
- if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
- else velocity[i]+=bounceness*elasticity;
-
- if(findLengthfast(&bounceness)>1){
- float gLoc[3];
- float vel[3];
- int whichsound;
- if(terrain.getOpacity(mid.x,mid.z)>.2){
- if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
- if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
- }
- else whichsound=footstepsound+abs(Random()%2);
- gLoc[0]=position[i].x;
- gLoc[1]=position[i].y;
- gLoc[2]=position[i].z;
- vel[0]=0;
- vel[1]=0;
- vel[2]=0;
- PlaySoundEx( whichsound, samp[whichsound], NULL, true);
- OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
- if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
- else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
- OPENAL_SetPaused(channels[whichsound], false);
- }
- }
-
- if(tippoint[i].y<terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z)){
- hitsomething[i]=1;
- tippoint[i].y=terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z);
-
- terrainnormal=terrain.getNormal(mid.x,mid.z);
- ReflectVector(&tipvelocity[i],&terrainnormal);
- tippoint[i]+=terrainnormal*.002;
- bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
- if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
- frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
- tipvelocity[i]-=bounceness;
- if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
- else tipvelocity[i]=0;
- if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
- else tipvelocity[i]+=bounceness*elasticity;
-
- if(findLengthfast(&bounceness)>1){
- float gLoc[3];
- float vel[3];
- int whichsound;
- if(terrain.getOpacity(mid.x,mid.z)>.2){
- if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
- if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
- }
- else whichsound=footstepsound+abs(Random()%2);
- gLoc[0]=tippoint[i].x;
- gLoc[1]=tippoint[i].y;
- gLoc[2]=tippoint[i].z;
- vel[0]=0;
- vel[1]=0;
- vel[2]=0;
- PlaySoundEx( whichsound, samp[whichsound], NULL, true);
- OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
- if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
- else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
- OPENAL_SetPaused(channels[whichsound], false);
- }
- }*/
-
- //Fix terrain edge collision
- /*start=position[i];
- end=tippoint[i];
- whichhit=terrain.lineTerrain(start,end,&colpoint);
- if(whichhit!=-1){
- XYZ tippoi,posit;
- tippoi=tippoint[i];
- posit=position[i];
-
-
- while(whichhit!=-1){
- position[i].y+=.1;
- tippoint[i].y+=.1;
- velocity[i].y+=.1;
- tipvelocity[i].y+=.1;
- start=position[i];
- end=tippoint[i];
- whichhit=terrain.lineTerrain(start,end,&colpoint);
- if(whichhit!=-1)
- closestpoint=colpoint*terrain.scale;
- }
- position[i].y-=.1;
- tippoint[i].y-=.1;
- velocity[i].y-=.1;
- tipvelocity[i].y-=.1;
- start=position[i];
- end=tippoint[i];
- whichhit=terrain.lineTerrain(start,end,&colpoint);
- while(whichhit!=-1){
- position[i].y+=.01;
- tippoint[i].y+=.01;
- velocity[i].y+=.01;
- tipvelocity[i].y+=.01;
- start=position[i];
- end=tippoint[i];
- whichhit=terrain.lineTerrain(start,end,&colpoint);
- if(whichhit!=-1)
- closestpoint=colpoint*terrain.scale;
- }
- }*/
- /*if(whichhit!=-1){
- whichhit=terrain.lineTerrain(end,start,&closestswordpoint);
- if(whichhit!=-1){
- colpoint=(closestswordpoint*terrain.scale+colpoint*terrain.scale)/2;
- proportion=findDistance(&tippoint[i],&colpoint)/findDistance(&position[i],&tippoint[i]);
- if(proportion<=1){
- while(whichhit!=-1){
- position[i].y+=.1*proportion;
- tippoint[i].y+=.1*(1-proportion);
- velocity[i].y+=.1*proportion;
- tipvelocity[i].y+=.1*(1-proportion);
- start=position[i];
- end=tippoint[i];
- whichhit=terrain.lineTerrain(start,end,&colpoint);
- }
- position[i].y-=.1*proportion;
- tippoint[i].y-=.1*(1-proportion);
- velocity[i].y-=.1*proportion;
- tipvelocity[i].y-=.1*(1-proportion);
- start=position[i];
- end=tippoint[i];
- whichhit=terrain.lineTerrain(start,end,&colpoint);
- while(whichhit!=-1){
- position[i].y+=.01*proportion;
- tippoint[i].y+=.01*(1-proportion);
- velocity[i].y+=.01*proportion;
- tipvelocity[i].y+=.01*(1-proportion);
- start=position[i];
- end=tippoint[i];
- whichhit=terrain.lineTerrain(start,end,&colpoint);
- }
- }
- }
- }
- */
//Gravity
velocity[i].y+=gravity*multiplier;
tipvelocity[i].y+=gravity*multiplier;