physics.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  1. /*
  2. Copyright (C) 2005, 2010 - Cryptic Sea
  3. This file is part of Gish.
  4. Gish is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. See the GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. void setupphysics(void)
  17. {
  18. int count;
  19. count=1;
  20. particletype[count].drag=0.995f;
  21. particletype[count].gravity=4.0f/(PHYSICSCYCLE*PHYSICSCYCLE);
  22. particletype[count].elasticity=1.2f;
  23. particletype[count].friction=1.2f;
  24. particletype[count].levelcollision=0;
  25. particletype[count].objectcollision=0;
  26. particletype[count].rendertype=0;
  27. count=2;
  28. particletype[count].drag=0.0f;
  29. particletype[count].gravity=0.0f;
  30. particletype[count].elasticity=1.2f;
  31. particletype[count].friction=1.2f;
  32. particletype[count].levelcollision=0;
  33. particletype[count].objectcollision=0;
  34. particletype[count].rendertype=0;
  35. count=3;
  36. particletype[count].drag=0.999f;
  37. particletype[count].gravity=4.0f/(PHYSICSCYCLE*PHYSICSCYCLE);
  38. particletype[count].elasticity=1.2f;
  39. particletype[count].friction=1.2f;
  40. particletype[count].levelcollision=0;
  41. particletype[count].objectcollision=0;
  42. particletype[count].rendertype=0;
  43. count=4;
  44. particletype[count].drag=0.995f;
  45. particletype[count].gravity=4.0f/(PHYSICSCYCLE*PHYSICSCYCLE);
  46. particletype[count].elasticity=1.2f;
  47. particletype[count].friction=0.2f;
  48. particletype[count].levelcollision=1;
  49. particletype[count].objectcollision=0;
  50. particletype[count].rendertype=0;
  51. count=5;
  52. particletype[count].drag=0.99f;
  53. particletype[count].gravity=4.0f/(PHYSICSCYCLE*PHYSICSCYCLE);
  54. particletype[count].elasticity=1.2f;
  55. particletype[count].friction=0.2f;
  56. particletype[count].levelcollision=1;
  57. particletype[count].objectcollision=0;
  58. particletype[count].rendertype=0;
  59. count=6;
  60. particletype[count].drag=0.999f;
  61. particletype[count].gravity=0.0f;
  62. particletype[count].elasticity=1.2f;
  63. particletype[count].friction=0.3f;
  64. particletype[count].levelcollision=1;
  65. particletype[count].objectcollision=0;
  66. particletype[count].rendertype=0;
  67. count=16;
  68. particletype[count].drag=0.999f;
  69. particletype[count].gravity=0.0f;
  70. particletype[count].elasticity=1.2f;
  71. particletype[count].friction=0.3f;
  72. particletype[count].levelcollision=0;
  73. particletype[count].objectcollision=0;
  74. particletype[count].rendertype=0;
  75. count=1;
  76. bondtype[count].elasticity=0.2f;
  77. bondtype[count].cycles=1;
  78. bondtype[count].compression=0.1f;
  79. bondtype[count].tension=1.9f;
  80. bondtype[count].rendertype=1;
  81. bondtype[count].rendersize=0.4f;
  82. count=2;
  83. bondtype[count].elasticity=0.02f;
  84. bondtype[count].cycles=31;
  85. bondtype[count].compression=0.1f;
  86. bondtype[count].tension=1.9f;
  87. bondtype[count].rendertype=1;
  88. bondtype[count].rendersize=0.4f;
  89. count=3;
  90. bondtype[count].elasticity=0.2f;
  91. bondtype[count].cycles=3;
  92. bondtype[count].compression=0.1f;
  93. bondtype[count].tension=1.9f;
  94. bondtype[count].rendertype=1;
  95. bondtype[count].rendersize=0.4f;
  96. count=4;
  97. bondtype[count].elasticity=0.5f;
  98. bondtype[count].cycles=1;
  99. bondtype[count].compression=0.0f;
  100. bondtype[count].tension=1.15f;
  101. bondtype[count].rendertype=1;
  102. bondtype[count].rendersize=0.4f;
  103. count=5;
  104. bondtype[count].elasticity=0.1f;
  105. bondtype[count].cycles=31;
  106. bondtype[count].compression=0.1f;
  107. bondtype[count].tension=1.9f;
  108. bondtype[count].rendertype=1;
  109. bondtype[count].rendersize=0.4f;
  110. count=6;
  111. bondtype[count].elasticity=0.2f;
  112. bondtype[count].cycles=15;
  113. bondtype[count].compression=0.75f;
  114. bondtype[count].tension=1.25f;
  115. bondtype[count].rendertype=1;
  116. bondtype[count].rendersize=0.4f;
  117. count=7;
  118. bondtype[count].elasticity=0.2f;
  119. bondtype[count].cycles=0;
  120. bondtype[count].compression=0.5f;
  121. bondtype[count].tension=1.5f;
  122. bondtype[count].rendertype=1;
  123. bondtype[count].rendersize=0.4f;
  124. count=8;
  125. bondtype[count].elasticity=0.002f;
  126. bondtype[count].cycles=0;
  127. bondtype[count].compression=0.5f;
  128. bondtype[count].tension=1.5f;
  129. bondtype[count].rendertype=1;
  130. bondtype[count].rendersize=0.4f;
  131. count=9;
  132. bondtype[count].elasticity=0.2f;
  133. bondtype[count].cycles=0;
  134. bondtype[count].compression=0.5f;
  135. bondtype[count].tension=1.5f;
  136. bondtype[count].rendertype=1;
  137. bondtype[count].rendersize=0.4f;
  138. count=16;
  139. bondtype[count].elasticity=0.1f;
  140. bondtype[count].cycles=31;
  141. bondtype[count].compression=0.5f;
  142. bondtype[count].tension=1.5f;
  143. bondtype[count].rendertype=1;
  144. bondtype[count].rendersize=0.4f;
  145. }
  146. void particlecollision(int particlenum)
  147. {
  148. float vec[3],vec2[3],vec3[3];
  149. float intersectpoint[3];
  150. float normal[3];
  151. float scale;
  152. if (pointintersectlevel(intersectpoint,normal,&scale,particle[particlenum].position))
  153. {
  154. subtractvectors(vec2,intersectpoint,particle[particlenum].position);
  155. scaleaddvectors(vec,particle[particlenum].position,normal,dotproduct(vec2,normal));
  156. physicstemp.bond[physicstemp.numofbonds].part1=particlenum;
  157. physicstemp.bond[physicstemp.numofbonds].type=0;
  158. physicstemp.bond[physicstemp.numofbonds].cycles=3;
  159. physicstemp.bond[physicstemp.numofbonds].length=0.0f;
  160. physicstemp.bond[physicstemp.numofbonds].elasticity=0.2f;
  161. physicstemp.bond[physicstemp.numofbonds].friction=particle[particlenum].friction;
  162. if (collision.friction<particle[particlenum].friction)
  163. physicstemp.bond[physicstemp.numofbonds].friction=collision.friction;
  164. physicstemp.bond[physicstemp.numofbonds].objectnum[0]=-1;
  165. physicstemp.bond[physicstemp.numofbonds].blocknum=collision.blocknum;
  166. physicstemp.bond[physicstemp.numofbonds].blockx=collision.blockx;
  167. physicstemp.bond[physicstemp.numofbonds].blocky=collision.blocky;
  168. copyvector(physicstemp.bond[physicstemp.numofbonds].point,vec);
  169. copyvector(physicstemp.bond[physicstemp.numofbonds].normal,normal);
  170. physicstemp.numofbonds++;
  171. }
  172. }
  173. void objectcollision(int objectnum)
  174. {
  175. int count,count2;
  176. int part1,part2;
  177. int blocknum;
  178. int particlenum;
  179. int particlelist[2];
  180. float vec[3],vec2[3],vec3[3];
  181. float intersectpoint[3];
  182. float normal[3];
  183. float force[2];
  184. float scale;
  185. float friction;
  186. copyvector(object[objectnum].prevposition,object[objectnum].position);
  187. if (object[objectnum].numofparticles!=0)
  188. {
  189. zerovector(object[objectnum].position);
  190. for (count=0;count<object[objectnum].numofparticles;count++)
  191. addvectors(object[objectnum].position,object[objectnum].position,particle[object[objectnum].particle[count]].position);
  192. scalevector(object[objectnum].position,object[objectnum].position,1.0f/(float)object[objectnum].numofparticles);
  193. object[objectnum].numoforientations=0;
  194. zerovector(object[objectnum].orientation[1]);
  195. if (object[objectnum].type!=1)
  196. if (object[objectnum].type!=2 || object[objectnum].size[0]>0.5f)
  197. {
  198. getlevellines(objectnum);
  199. for (count=0;count<numoflevellines;count++)
  200. {
  201. if (lineintersectobject(intersectpoint,normal,&scale,levelline[count].line[0],levelline[count].line[1],objectnum,particlelist))
  202. {
  203. part1=particlelist[0];
  204. part2=particlelist[1];
  205. if (dotproduct(normal,levelline[count].normal)<-0.707f)
  206. {
  207. subtractvectors(object[objectnum].orientation[1],object[objectnum].orientation[1],normal);
  208. object[objectnum].numoforientations++;
  209. collision.friction=levelline[count].friction;
  210. collision.blocknum=levelline[count].blocknum;
  211. collision.blockx=levelline[count].blockx;
  212. collision.blocky=levelline[count].blocky;
  213. subtractvectors(vec,intersectpoint,levelline[count].line[1]);
  214. scaleaddvectors(vec2,levelline[count].line[1],normal,dotproduct(vec,normal));
  215. subtractvectors(vec,particle[object[objectnum].particle[part2]].position,particle[object[objectnum].particle[part1]].position);
  216. scale=vectorlength(vec);
  217. subtractvectors(vec,particle[object[objectnum].particle[part1]].position,intersectpoint);
  218. force[0]=vectorlength(vec)/scale;
  219. subtractvectors(vec,particle[object[objectnum].particle[part2]].position,intersectpoint);
  220. force[1]=vectorlength(vec)/scale;
  221. if (force[0]>1.0f)
  222. force[0]=1.0f;
  223. if (force[1]>1.0f)
  224. force[1]=1.0f;
  225. physicstemp.bond[physicstemp.numofbonds].part1=object[objectnum].particle[part1];
  226. physicstemp.bond[physicstemp.numofbonds].part2=object[objectnum].particle[part2];
  227. physicstemp.bond[physicstemp.numofbonds].type=2;
  228. subtractvectors(vec,vec2,intersectpoint);
  229. physicstemp.bond[physicstemp.numofbonds].length=vectorlength(vec);
  230. copyvector(physicstemp.bond[physicstemp.numofbonds].normal,normal);
  231. physicstemp.bond[physicstemp.numofbonds].cycles=0;
  232. physicstemp.bond[physicstemp.numofbonds].elasticity=0.2f;
  233. physicstemp.bond[physicstemp.numofbonds].friction=object[objectnum].friction;
  234. if (collision.friction<object[objectnum].friction)
  235. physicstemp.bond[physicstemp.numofbonds].friction=collision.friction;
  236. physicstemp.bond[physicstemp.numofbonds].force[0]=force[1];
  237. physicstemp.bond[physicstemp.numofbonds].force[1]=force[0];
  238. physicstemp.bond[physicstemp.numofbonds].objectnum[0]=objectnum;
  239. physicstemp.bond[physicstemp.numofbonds].objectnum[1]=objectnum;
  240. physicstemp.bond[physicstemp.numofbonds].blocknum=collision.blocknum;
  241. physicstemp.bond[physicstemp.numofbonds].blockx=collision.blockx;
  242. physicstemp.bond[physicstemp.numofbonds].blocky=collision.blocky;
  243. physicstemp.numofbonds++;
  244. }
  245. }
  246. }
  247. }
  248. for (count=0;count<object[objectnum].numofparticles;count++)
  249. {
  250. if (object[objectnum].particlestick[count])
  251. {
  252. scaleaddvectors(object[objectnum].orientation[1],object[objectnum].orientation[1],object[objectnum].particlesticknormal[count],0.5f);
  253. object[objectnum].numoforientations++;
  254. }
  255. particlenum=object[objectnum].particle[count];
  256. if (pointintersectlevel(intersectpoint,normal,&scale,particle[particlenum].position))
  257. {
  258. addvectors(object[objectnum].orientation[1],object[objectnum].orientation[1],normal);
  259. object[objectnum].numoforientations++;
  260. if (object[objectnum].timetolive==10001)
  261. object[objectnum].timetolive=50;
  262. if (object[objectnum].type==1 || object[objectnum].type==4)
  263. {
  264. blocknum=collision.blocknum;
  265. if (block[blocknum].animation!=0)
  266. if (block[blocknum].animationspeed!=0)
  267. blocknum+=(game.framenum/block[blocknum].animationspeed)%block[blocknum].animation;
  268. if (block[blocknum].middamage!=0)
  269. {
  270. if (object[objectnum].type==1)
  271. object[objectnum].hitpoints-=block[blocknum].middamage;
  272. if (object[objectnum].type==4)
  273. object[objectnum].hitpoints-=block[blocknum].middamage*4;
  274. }
  275. }
  276. subtractvectors(vec2,intersectpoint,particle[particlenum].position);
  277. scaleaddvectors(vec,particle[particlenum].position,normal,dotproduct(vec2,normal));
  278. physicstemp.bond[physicstemp.numofbonds].part1=particlenum;
  279. physicstemp.bond[physicstemp.numofbonds].type=0;
  280. physicstemp.bond[physicstemp.numofbonds].cycles=0;
  281. physicstemp.bond[physicstemp.numofbonds].length=0.0f;
  282. physicstemp.bond[physicstemp.numofbonds].elasticity=0.2f;
  283. physicstemp.bond[physicstemp.numofbonds].friction=object[objectnum].friction;
  284. if (collision.friction<object[objectnum].friction)
  285. physicstemp.bond[physicstemp.numofbonds].friction=collision.friction;
  286. physicstemp.bond[physicstemp.numofbonds].objectnum[0]=objectnum;
  287. physicstemp.bond[physicstemp.numofbonds].blocknum=collision.blocknum;
  288. physicstemp.bond[physicstemp.numofbonds].blockx=collision.blockx;
  289. physicstemp.bond[physicstemp.numofbonds].blocky=collision.blocky;
  290. copyvector(physicstemp.bond[physicstemp.numofbonds].point,vec);
  291. copyvector(physicstemp.bond[physicstemp.numofbonds].normal,normal);
  292. physicstemp.numofbonds++;
  293. if ((object[objectnum].button&1)==1 && object[objectnum].type==1)
  294. if (collision.friction>0.1f)
  295. {
  296. if (!object[objectnum].particlestick[count])
  297. {
  298. object[objectnum].particlestick[count]=1;
  299. copyvector(object[objectnum].particlesticknormal[count],normal);
  300. copyvector(object[objectnum].particlestickposition[count],intersectpoint);
  301. physicstemp.bond[physicstemp.numofbonds].part1=object[objectnum].particle[count];
  302. physicstemp.bond[physicstemp.numofbonds].part4=count;
  303. physicstemp.bond[physicstemp.numofbonds].type=1;
  304. physicstemp.bond[physicstemp.numofbonds].cycles=0;
  305. physicstemp.bond[physicstemp.numofbonds].length=0.0f;
  306. physicstemp.bond[physicstemp.numofbonds].elasticity=0.2f;
  307. physicstemp.bond[physicstemp.numofbonds].breakpoint=0.25f;
  308. if (fabs(normal[1])<0.707f)
  309. physicstemp.bond[physicstemp.numofbonds].breakpoint=0.2f;
  310. physicstemp.bond[physicstemp.numofbonds].objectnum[0]=objectnum;
  311. physicstemp.bond[physicstemp.numofbonds].blocknum=collision.blocknum;
  312. physicstemp.bond[physicstemp.numofbonds].blockx=collision.blockx;
  313. physicstemp.bond[physicstemp.numofbonds].blocky=collision.blocky;
  314. copyvector(physicstemp.bond[physicstemp.numofbonds].point,vec);
  315. copyvector(physicstemp.bond[physicstemp.numofbonds].normal,normal);
  316. physicstemp.numofbonds++;
  317. }
  318. }
  319. }
  320. }
  321. }
  322. }
  323. void objectcollisionobject(int objectnum)
  324. {
  325. int count,count2;
  326. int part1,part2;
  327. int objectcount;
  328. int particlenum;
  329. int particlelist[2];
  330. float vec[3],vec2[3],vec3[3];
  331. float intersectpoint[3];
  332. float normal[3];
  333. float force[2];
  334. float scale;
  335. float friction;
  336. if (object[objectnum].type==3)
  337. for (count=0;count<object[objectnum].numofparticles;count++)
  338. {
  339. particlenum=object[objectnum].particle[count];
  340. for (count2=0;count2<numofropes;count2++)
  341. if (rope[count2].type<=4)
  342. if (lineintersectline(intersectpoint,normal,&scale,object[objectnum].position,particle[object[objectnum].particle[count]].position,particle[rope[count2].part1].position,particle[rope[count2].part2].position))
  343. {
  344. subtractvectors(vec,intersectpoint,particle[particlenum].position);
  345. scaleaddvectors(vec2,particle[particlenum].position,normal,dotproduct(vec,normal));
  346. subtractvectors(vec,particle[rope[count2].part2].position,particle[rope[count2].part1].position);
  347. scale=vectorlength(vec);
  348. subtractvectors(vec,particle[rope[count2].part1].position,intersectpoint);
  349. force[0]=vectorlength(vec)/scale;
  350. subtractvectors(vec,particle[rope[count2].part2].position,intersectpoint);
  351. force[1]=vectorlength(vec)/scale;
  352. if (force[0]>1.0f)
  353. force[0]=1.0f;
  354. if (force[1]>1.0f)
  355. force[1]=1.0f;
  356. physicstemp.bond[physicstemp.numofbonds].part1=rope[count2].part1;
  357. physicstemp.bond[physicstemp.numofbonds].part2=rope[count2].part2;
  358. physicstemp.bond[physicstemp.numofbonds].part3=particlenum;
  359. physicstemp.bond[physicstemp.numofbonds].type=4;
  360. subtractvectors(vec,vec2,intersectpoint);
  361. physicstemp.bond[physicstemp.numofbonds].length=vectorlength(vec);
  362. copyvector(physicstemp.bond[physicstemp.numofbonds].normal,normal);
  363. physicstemp.bond[physicstemp.numofbonds].cycles=0;
  364. physicstemp.bond[physicstemp.numofbonds].elasticity=0.2f;
  365. physicstemp.bond[physicstemp.numofbonds].friction=0.8f;
  366. physicstemp.bond[physicstemp.numofbonds].objectnum[0]=objectnum;
  367. physicstemp.bond[physicstemp.numofbonds].objectnum[1]=objectnum;
  368. physicstemp.bond[physicstemp.numofbonds].force[0]=force[1];
  369. physicstemp.bond[physicstemp.numofbonds].force[1]=force[0];
  370. physicstemp.bond[physicstemp.numofbonds].blocknum=0;
  371. physicstemp.bond[physicstemp.numofbonds].blockx=0;
  372. physicstemp.bond[physicstemp.numofbonds].blocky=0;
  373. physicstemp.numofbonds++;
  374. }
  375. }
  376. updateogg();
  377. for (objectcount=0;objectcount<numofobjects;objectcount++)
  378. if (objectnum!=objectcount)
  379. if (objecttype[object[objectnum].type].collide[object[objectcount].type])
  380. if ((object[objectnum].type!=2 || object[objectnum].timetolive>175) && (object[objectcount].type!=2 || object[objectcount].timetolive>175))
  381. if (object[objectnum].timetolive>40 && object[objectcount].timetolive>40)
  382. {
  383. subtractvectors(vec,object[objectnum].position,object[objectcount].position);
  384. if (vectorlength(vec)<object[objectnum].radius+object[objectcount].radius)
  385. for (count=0;count<object[objectnum].numofparticles;count++)
  386. {
  387. particlenum=object[objectnum].particle[count];
  388. //for (count2=0;count2<object[objectcount].numofcdlines;count2++)
  389. if (pointintersectobject(intersectpoint,normal,&scale,particle[object[objectnum].particle[count]].position,objectcount,objectnum,particlelist))
  390. {
  391. //part1=object[objectcount].cdline[count2][0];
  392. //part2=object[objectcount].cdline[count2][1];
  393. part1=particlelist[0];
  394. part2=particlelist[1];
  395. //if (lineintersectline2(intersectpoint,normal,&scale,object[objectnum].position,particle[object[objectnum].particle[count]].position,particle[object[objectcount].particle[part1]].position,particle[object[objectcount].particle[part2]].position))
  396. {
  397. scaleaddvectors(object[objectnum].orientation[1],object[objectnum].orientation[1],normal,0.5f);
  398. object[objectnum].numoforientations++;
  399. if (object[objectnum].type==1)
  400. if (game.levelnum==29)
  401. if (objectcount==38)
  402. if (game.godmode==0)
  403. {
  404. game.godmode=1;
  405. playsound(10,object[objectnum].position,NULL,0.4f,0,1.0f,-1,0);
  406. }
  407. if (object[objectnum].type==1)
  408. if (object[objectcount].type==4)
  409. if (object[objectcount].beasttype==15)
  410. object[objectnum].hitpoints--;
  411. if (object[objectnum].type==1)
  412. if (object[objectcount].type==6)
  413. if (object[objectcount].timetolive>16)
  414. {
  415. object[objectcount].timetolive=16;
  416. if (level.gametype==12)
  417. {
  418. if (objectnum==0)
  419. game.score[0]++;
  420. if (objectnum==1)
  421. game.score[1]++;
  422. }
  423. }
  424. //subtractvectors(vec,intersectpoint,particle[particlenum].position);
  425. //scaleaddvectors(vec2,particle[particlenum].position,normal,dotproduct(vec,normal));
  426. //copyvector(vec,intersectpoint);
  427. subtractvectors(vec,particle[object[objectcount].particle[part2]].position,particle[object[objectcount].particle[part1]].position);
  428. scale=vectorlength(vec);
  429. subtractvectors(vec,particle[object[objectcount].particle[part1]].position,intersectpoint);
  430. force[0]=vectorlength(vec)/scale;
  431. subtractvectors(vec,particle[object[objectcount].particle[part2]].position,intersectpoint);
  432. force[1]=vectorlength(vec)/scale;
  433. if (force[0]>1.0f)
  434. force[0]=1.0f;
  435. if (force[1]>1.0f)
  436. force[1]=1.0f;
  437. friction=object[objectnum].friction;
  438. if (friction>object[objectcount].friction)
  439. friction=object[objectcount].friction;
  440. physicstemp.bond[physicstemp.numofbonds].part1=object[objectcount].particle[part1];
  441. physicstemp.bond[physicstemp.numofbonds].part2=object[objectcount].particle[part2];
  442. physicstemp.bond[physicstemp.numofbonds].part3=particlenum;
  443. physicstemp.bond[physicstemp.numofbonds].type=4;
  444. subtractvectors(vec,particle[particlenum].position,intersectpoint);
  445. physicstemp.bond[physicstemp.numofbonds].length=vectorlength(vec);
  446. copyvector(physicstemp.bond[physicstemp.numofbonds].normal,normal);
  447. physicstemp.bond[physicstemp.numofbonds].cycles=0;
  448. if (object[objectnum].type==2 && object[objectcount].type==2)
  449. if (object[objectnum].size[0]<=0.5f && object[objectcount].size[0]<=0.5f)
  450. physicstemp.bond[physicstemp.numofbonds].cycles=3;
  451. physicstemp.bond[physicstemp.numofbonds].elasticity=0.2f;
  452. physicstemp.bond[physicstemp.numofbonds].friction=friction;
  453. physicstemp.bond[physicstemp.numofbonds].objectnum[0]=objectnum;
  454. physicstemp.bond[physicstemp.numofbonds].objectnum[1]=objectcount;
  455. physicstemp.bond[physicstemp.numofbonds].force[0]=force[1];
  456. physicstemp.bond[physicstemp.numofbonds].force[1]=force[0];
  457. physicstemp.bond[physicstemp.numofbonds].blocknum=0;
  458. physicstemp.bond[physicstemp.numofbonds].blockx=0;
  459. physicstemp.bond[physicstemp.numofbonds].blocky=0;
  460. physicstemp.numofbonds++;
  461. if ((object[objectnum].button&1)==1 && object[objectnum].type==1)
  462. if (object[objectcount].type!=1 || (object[objectcount].button&4)==0)
  463. {
  464. //if (!object[objectnum].particlestick[count])
  465. {
  466. if (object[objectnum].particlestick[count])
  467. {
  468. for (count2=0;count2<physicstemp.numofbonds;count2++)
  469. if (physicstemp.bond[count2].type==5)
  470. if (physicstemp.bond[count2].objectnum[0]==objectnum)
  471. if (physicstemp.bond[count2].part4==count)
  472. physicstemp.bond[count2].type=-1;
  473. }
  474. object[objectnum].particlestick[count]=1;
  475. physicstemp.bond[physicstemp.numofbonds].part1=object[objectcount].particle[part1];
  476. physicstemp.bond[physicstemp.numofbonds].part2=object[objectcount].particle[part2];
  477. physicstemp.bond[physicstemp.numofbonds].part3=particlenum;
  478. physicstemp.bond[physicstemp.numofbonds].part4=count;
  479. physicstemp.bond[physicstemp.numofbonds].type=5;
  480. physicstemp.bond[physicstemp.numofbonds].length=vectorlength(vec);
  481. copyvector(physicstemp.bond[physicstemp.numofbonds].normal,normal);
  482. physicstemp.bond[physicstemp.numofbonds].cycles=0;
  483. physicstemp.bond[physicstemp.numofbonds].elasticity=0.2f;
  484. physicstemp.bond[physicstemp.numofbonds].breakpoint=0.3f;
  485. if (fabs(normal[1])<0.707f)
  486. physicstemp.bond[physicstemp.numofbonds].breakpoint=0.25f;
  487. if (object[objectcount].type>=3 && object[objectcount].type<=5)
  488. physicstemp.bond[physicstemp.numofbonds].breakpoint*=1.5f;
  489. physicstemp.bond[physicstemp.numofbonds].friction=friction;
  490. physicstemp.bond[physicstemp.numofbonds].objectnum[0]=objectnum;
  491. physicstemp.bond[physicstemp.numofbonds].objectnum[1]=objectcount;
  492. physicstemp.bond[physicstemp.numofbonds].force[0]=force[1];
  493. physicstemp.bond[physicstemp.numofbonds].force[1]=force[0];
  494. physicstemp.bond[physicstemp.numofbonds].blocknum=0;
  495. physicstemp.bond[physicstemp.numofbonds].blockx=0;
  496. physicstemp.bond[physicstemp.numofbonds].blocky=0;
  497. physicstemp.numofbonds++;
  498. if (game.oldschool==2)
  499. if (object[objectcount].type==3)
  500. if (game.framenum-game.oldschoolsound>200)
  501. {
  502. playsound(22,object[objectnum].position,NULL,1.0f,0,1.0f,objectnum,1);
  503. game.oldschoolsound=game.framenum;
  504. }
  505. }
  506. }
  507. }
  508. }
  509. }
  510. }
  511. if (level.gametype>=10)
  512. for (objectcount=0;objectcount<numofobjects;objectcount++)
  513. if (object[objectcount].type==1)
  514. {
  515. for (count=0;count<object[objectcount].numofparticles;count++)
  516. {
  517. particlenum=object[objectcount].particle[count];
  518. part1=object[objectcount].particle[((count+4)&15)];
  519. part2=object[objectcount].particle[((count-4)&15)];
  520. //for (count2=-6;count2<6;count2++)
  521. {
  522. //part1=object[objectcount].particle[((count+8+count2)&15)];
  523. //part2=object[objectcount].particle[((count+8+count2+1)&15)];
  524. normal[0]=particle[part2].position[1]-particle[part1].position[1];
  525. normal[1]=particle[part1].position[0]-particle[part2].position[0];
  526. normal[2]=0.0f;
  527. normalizevector(normal,normal);
  528. scaleaddvectors(vec,particle[particlenum].position,normal,1.0f);
  529. if (lineintersectline2(intersectpoint,normal,&scale,vec,particle[particlenum].position,particle[part1].position,particle[part2].position))
  530. {
  531. subtractvectors(vec,particle[part2].position,particle[part1].position);
  532. scale=vectorlength(vec);
  533. if (scale>0.00000001f)
  534. {
  535. subtractvectors(vec,particle[part1].position,intersectpoint);
  536. force[0]=vectorlength(vec)/scale;
  537. subtractvectors(vec,particle[part2].position,intersectpoint);
  538. force[1]=vectorlength(vec)/scale;
  539. }
  540. else
  541. {
  542. force[0]=0.5f;
  543. force[1]=0.5f;
  544. }
  545. if (force[0]>1.0f)
  546. force[0]=1.0f;
  547. if (force[1]>1.0f)
  548. force[1]=1.0f;
  549. physicstemp.bond[physicstemp.numofbonds].part1=part1;
  550. physicstemp.bond[physicstemp.numofbonds].part2=part2;
  551. physicstemp.bond[physicstemp.numofbonds].part3=particlenum;
  552. physicstemp.bond[physicstemp.numofbonds].type=4;
  553. subtractvectors(vec,particle[particlenum].position,intersectpoint);
  554. physicstemp.bond[physicstemp.numofbonds].length=vectorlength(vec);
  555. copyvector(physicstemp.bond[physicstemp.numofbonds].normal,normal);
  556. physicstemp.bond[physicstemp.numofbonds].cycles=0;
  557. physicstemp.bond[physicstemp.numofbonds].elasticity=0.5f;
  558. physicstemp.bond[physicstemp.numofbonds].friction=1.0f;
  559. physicstemp.bond[physicstemp.numofbonds].objectnum[0]=-1;
  560. physicstemp.bond[physicstemp.numofbonds].objectnum[1]=-1;
  561. physicstemp.bond[physicstemp.numofbonds].force[0]=force[1];
  562. physicstemp.bond[physicstemp.numofbonds].force[1]=force[0];
  563. physicstemp.bond[physicstemp.numofbonds].blocknum=0;
  564. physicstemp.bond[physicstemp.numofbonds].blockx=0;
  565. physicstemp.bond[physicstemp.numofbonds].blocky=0;
  566. physicstemp.numofbonds++;
  567. }
  568. }
  569. }
  570. }
  571. }
  572. void bondsimulation2(void)
  573. {
  574. int count,count2;
  575. int part1,part2,part3;
  576. int blocknum;
  577. unsigned int x;
  578. float vec[3],vec2[3],vec3[3];
  579. float bondnormal[3];
  580. float veclength;
  581. float force[2];
  582. float temp;
  583. float scale;
  584. for (count2=0;count2<physicstemp.numofbonds;count2++)
  585. {
  586. zerovector(physicstemp.bond[count2].forceapplied[0]);
  587. zerovector(physicstemp.bond[count2].forceapplied[1]);
  588. }
  589. for (count2=0;count2<numofbonds;count2++)
  590. {
  591. part1=bond[count2].part1;
  592. part2=bond[count2].part2;
  593. subtractvectors(bond[count2].bondnormal,particle[part2].position,particle[part1].position);
  594. bond[count2].veclength=vectorlength(bond[count2].bondnormal);
  595. normalizevector(bond[count2].bondnormal,bond[count2].bondnormal);
  596. bond[count2].oomass=1.0f/(particle[part1].mass+particle[part2].mass);
  597. }
  598. for (count=0;count<32;count++)
  599. {
  600. //starttimer(0);
  601. updateogg();
  602. for (count2=0;count2<numofparticles;count2++)
  603. copyvector(particle[count2].prevvelocity,particle[count2].velocity);
  604. for (count2=0;count2<numofbonds;count2++)
  605. if ((count&bond[count2].cycles)==0)
  606. {
  607. part1=bond[count2].part1;
  608. part2=bond[count2].part2;
  609. temp=bond[count2].veclength;
  610. veclength=temp-bond[count2].length;
  611. copyvector(bondnormal,bond[count2].bondnormal);
  612. zerovector(vec);
  613. scaleaddvectors2(vec,vec,particle[part2].prevvelocity,1.0f);
  614. scaleaddvectors2(vec,vec,particle[part1].prevvelocity,-1.0f);
  615. veclength+=dotproduct(vec,bondnormal);
  616. if (bondtype[bond[count2].type].compression==0.0f)
  617. if (veclength<0.0f)
  618. veclength=0.0f;
  619. veclength*=bond[count2].elasticity;
  620. //if (bond[count2].type==2 && temp<bond[count2].length*0.35f)
  621. // veclength*=10.0f;
  622. if (bond[count2].type==2 && temp<bond[count2].length*0.25f)
  623. bond[count2].cycles=0;
  624. veclength*=bond[count2].oomass;
  625. force[0]=veclength*particle[part2].mass;
  626. force[1]=veclength*particle[part1].mass;
  627. scaleaddvectors2(particle[part1].velocity,particle[part1].velocity,bondnormal,force[0]);
  628. scaleaddvectors2(particle[part2].velocity,particle[part2].velocity,bondnormal,-force[1]);
  629. }
  630. //stoptimer(0);
  631. //starttimer(1);
  632. for (count2=0;count2<physicstemp.numofbonds;count2++)
  633. if ((count&physicstemp.bond[count2].cycles)==0)
  634. {
  635. if (physicstemp.bond[count2].type==0)
  636. {
  637. part1=physicstemp.bond[count2].part1;
  638. subtractvectors2(bondnormal,physicstemp.bond[count2].point,particle[part1].position);
  639. scalevector2(vec,bondnormal,0.2f);
  640. veclength=(vectorlength(bondnormal)-physicstemp.bond[count2].length);
  641. scaleaddvectors2(vec,vec,particle[part1].prevvelocity,-1.0f);
  642. if (dotproduct(vec,physicstemp.bond[count2].normal)>0.0f)
  643. {
  644. scalevector2(vec,vec,physicstemp.bond[count2].elasticity);
  645. calculatefriction(vec,vec2,physicstemp.bond[count2].normal,physicstemp.bond[count2].friction);
  646. addvectors2(vec,vec,vec2);
  647. addvectors2(particle[part1].velocity,particle[part1].velocity,vec);
  648. if (particle[part1].type!=5)
  649. {
  650. addvectors2(physicstemp.bond[count2].forceapplied[0],physicstemp.bond[count2].forceapplied[0],vec);
  651. if (block[physicstemp.bond[count2].blocknum].breakpoint!=0.0f)
  652. {
  653. level.gridforce[physicstemp.bond[count2].blocky][physicstemp.bond[count2].blockx]+=vectorlength(vec)*particle[part1].mass;
  654. if (level.gridforce[physicstemp.bond[count2].blocky][physicstemp.bond[count2].blockx]>block[physicstemp.bond[count2].blocknum].breakpoint)
  655. physicstemp.bond[count2].type=-1;
  656. }
  657. }
  658. }
  659. }
  660. if (physicstemp.bond[count2].type==1)
  661. {
  662. part1=physicstemp.bond[count2].part1;
  663. subtractvectors2(bondnormal,physicstemp.bond[count2].point,particle[part1].position);
  664. scalevector2(vec,bondnormal,1.0f);
  665. veclength=(vectorlength(bondnormal)-physicstemp.bond[count2].length);
  666. scaleaddvectors2(vec,vec,particle[part1].prevvelocity,-1.0f);
  667. veclength=(vectorlength(bondnormal)-physicstemp.bond[count2].length)-dotproduct(bondnormal,particle[part1].prevvelocity)/vectorlength(bondnormal);
  668. scalevector2(vec,vec,physicstemp.bond[count2].elasticity);
  669. scalevector2(vec,vec,0.04f);
  670. addvectors2(particle[part1].velocity,particle[part1].velocity,vec);
  671. addvectors2(physicstemp.bond[count2].forceapplied[0],physicstemp.bond[count2].forceapplied[0],vec);
  672. if (block[physicstemp.bond[count2].blocknum].breakpoint!=0.0f)
  673. {
  674. level.gridforce[physicstemp.bond[count2].blocky][physicstemp.bond[count2].blockx]+=vectorlength(vec)*particle[part1].mass;
  675. if (level.gridforce[physicstemp.bond[count2].blocky][physicstemp.bond[count2].blockx]>block[physicstemp.bond[count2].blocknum].breakpoint || level.gridmod[physicstemp.bond[count2].blocky][physicstemp.bond[count2].blockx]!=0)
  676. {
  677. physicstemp.bond[count2].type=-1;
  678. object[physicstemp.bond[count2].objectnum[0]].particlestick[physicstemp.bond[count2].part4]=0;
  679. }
  680. }
  681. }
  682. if (physicstemp.bond[count2].type==2)
  683. {
  684. part1=physicstemp.bond[count2].part1;
  685. part2=physicstemp.bond[count2].part2;
  686. scalevector2(bondnormal,physicstemp.bond[count2].normal,-physicstemp.bond[count2].length*0.2f);
  687. scaleaddvectors2(bondnormal,bondnormal,particle[part2].prevvelocity,-physicstemp.bond[count2].force[1]);
  688. scaleaddvectors2(bondnormal,bondnormal,particle[part1].prevvelocity,-physicstemp.bond[count2].force[0]);
  689. copyvector(vec,bondnormal);
  690. if (dotproduct(vec,physicstemp.bond[count2].normal)<0.0f)
  691. {
  692. scalevector2(vec,vec,physicstemp.bond[count2].elasticity);
  693. calculatefriction(vec,vec2,physicstemp.bond[count2].normal,physicstemp.bond[count2].friction);
  694. addvectors2(vec,vec,vec2);
  695. scaleaddvectors2(particle[part1].velocity,particle[part1].velocity,vec,physicstemp.bond[count2].force[0]);
  696. scaleaddvectors2(particle[part2].velocity,particle[part2].velocity,vec,physicstemp.bond[count2].force[1]);
  697. addvectors2(physicstemp.bond[count2].forceapplied[0],physicstemp.bond[count2].forceapplied[0],vec);
  698. if (block[physicstemp.bond[count2].blocknum].breakpoint!=0.0f)
  699. {
  700. level.gridforce[physicstemp.bond[count2].blocky][physicstemp.bond[count2].blockx]+=vectorlength(vec)*particle[part1].mass;
  701. if (level.gridforce[physicstemp.bond[count2].blocky][physicstemp.bond[count2].blockx]>block[physicstemp.bond[count2].blocknum].breakpoint)
  702. physicstemp.bond[count2].type=-1;
  703. }
  704. }
  705. }
  706. if (physicstemp.bond[count2].type==4)
  707. {
  708. part1=physicstemp.bond[count2].part1;
  709. part2=physicstemp.bond[count2].part2;
  710. part3=physicstemp.bond[count2].part3;
  711. scalevector2(bondnormal,physicstemp.bond[count2].normal,-physicstemp.bond[count2].length*0.2f);
  712. scaleaddvectors2(bondnormal,bondnormal,particle[part3].prevvelocity,1.0f);
  713. scaleaddvectors2(bondnormal,bondnormal,particle[part2].prevvelocity,-physicstemp.bond[count2].force[1]);
  714. scaleaddvectors2(bondnormal,bondnormal,particle[part1].prevvelocity,-physicstemp.bond[count2].force[0]);
  715. veclength=physicstemp.bond[count2].elasticity/(particle[part1].mass*physicstemp.bond[count2].force[0]+particle[part2].mass*physicstemp.bond[count2].force[1]+particle[part3].mass);
  716. force[0]=veclength*particle[part3].mass;
  717. force[1]=veclength*(particle[part1].mass*physicstemp.bond[count2].force[0]+particle[part2].mass*physicstemp.bond[count2].force[1]);
  718. if (dotproduct(bondnormal,physicstemp.bond[count2].normal)*force[0]<0.0f)
  719. {
  720. scalevector2(vec,bondnormal,force[0]);
  721. calculatefriction(vec,vec2,physicstemp.bond[count2].normal,physicstemp.bond[count2].friction);
  722. addvectors2(vec,vec,vec2);
  723. scaleaddvectors2(particle[part1].velocity,particle[part1].velocity,vec,physicstemp.bond[count2].force[0]);
  724. scaleaddvectors2(particle[part2].velocity,particle[part2].velocity,vec,physicstemp.bond[count2].force[1]);
  725. addvectors2(physicstemp.bond[count2].forceapplied[0],physicstemp.bond[count2].forceapplied[0],vec);
  726. scalevector2(vec,bondnormal,-force[1]);
  727. calculatefriction(vec,vec2,physicstemp.bond[count2].normal,physicstemp.bond[count2].friction);
  728. addvectors2(vec,vec,vec2);
  729. addvectors2(particle[part3].velocity,particle[part3].velocity,vec);
  730. addvectors2(physicstemp.bond[count2].forceapplied[1],physicstemp.bond[count2].forceapplied[1],vec);
  731. }
  732. }
  733. if (physicstemp.bond[count2].type==5)
  734. {
  735. part1=physicstemp.bond[count2].part1;
  736. part2=physicstemp.bond[count2].part2;
  737. part3=physicstemp.bond[count2].part3;
  738. //scalevector(bondnormal,physicstemp.bond[count2].normal,-physicstemp.bond[count2].length*0.2f);
  739. scalevector2(vec,particle[part1].position,physicstemp.bond[count2].force[0]);
  740. scaleaddvectors2(vec,vec,particle[part2].position,physicstemp.bond[count2].force[1]);
  741. subtractvectors2(bondnormal,particle[part3].position,vec);
  742. scaleaddvectors2(bondnormal,bondnormal,particle[part3].prevvelocity,1.0f);
  743. scaleaddvectors2(bondnormal,bondnormal,particle[part2].prevvelocity,-physicstemp.bond[count2].force[1]*1.0f);
  744. scaleaddvectors2(bondnormal,bondnormal,particle[part1].prevvelocity,-physicstemp.bond[count2].force[0]*1.0f);
  745. veclength=physicstemp.bond[count2].elasticity/(particle[part1].mass*physicstemp.bond[count2].force[0]+particle[part2].mass*physicstemp.bond[count2].force[1]+particle[part3].mass);
  746. veclength*=0.2f;
  747. veclength*=0.2f;
  748. force[0]=veclength*particle[part3].mass;
  749. force[1]=veclength*(particle[part1].mass*physicstemp.bond[count2].force[0]+particle[part2].mass*physicstemp.bond[count2].force[1]);
  750. scalevector2(vec,bondnormal,force[0]);
  751. scaleaddvectors2(particle[part1].velocity,particle[part1].velocity,vec,physicstemp.bond[count2].force[0]);
  752. scaleaddvectors2(particle[part2].velocity,particle[part2].velocity,vec,physicstemp.bond[count2].force[1]);
  753. addvectors2(physicstemp.bond[count2].forceapplied[0],physicstemp.bond[count2].forceapplied[0],vec);
  754. scalevector2(vec,bondnormal,-force[1]);
  755. addvectors2(particle[part3].velocity,particle[part3].velocity,vec);
  756. addvectors2(physicstemp.bond[count2].forceapplied[1],physicstemp.bond[count2].forceapplied[1],vec);
  757. }
  758. }
  759. //stoptimer(1);
  760. }
  761. for (count2=0;count2<physicstemp.numofbonds;count2++)
  762. {
  763. if (physicstemp.bond[count2].type==0)
  764. if (physicstemp.bond[count2].objectnum[0]!=-1)
  765. {
  766. force[0]=dotproduct(physicstemp.bond[count2].forceapplied[0],physicstemp.bond[count2].normal);
  767. force[1]=vectorlength(physicstemp.bond[count2].forceapplied[0]);
  768. scale=sqrt(force[1]*force[1]-force[0]*force[0]);
  769. object[physicstemp.bond[count2].objectnum[0]].frictionapplied+=scale;
  770. }
  771. }
  772. for (count2=0;count2<physicstemp.numofbonds;count2++)
  773. if (particle[physicstemp.bond[count2].part1].type!=5)
  774. {
  775. if (physicstemp.bond[count2].type==1)
  776. {
  777. part1=physicstemp.bond[count2].part1;
  778. subtractvectors(bondnormal,physicstemp.bond[count2].point,particle[part1].position);
  779. scalevector(vec,bondnormal,1.0f);
  780. veclength=(vectorlength(bondnormal)-physicstemp.bond[count2].length);
  781. scaleaddvectors(vec,vec,particle[part1].prevvelocity,-1.0f);
  782. veclength=(vectorlength(bondnormal)-physicstemp.bond[count2].length)-dotproduct(bondnormal,particle[part1].prevvelocity)/vectorlength(bondnormal);
  783. if (fabs(veclength)>physicstemp.bond[count2].breakpoint || (object[physicstemp.bond[count2].objectnum[0]].button&1)==0)
  784. {
  785. physicstemp.bond[count2].type=-1;
  786. object[physicstemp.bond[count2].objectnum[0]].particlestick[physicstemp.bond[count2].part4]=0;
  787. }
  788. }
  789. if (physicstemp.bond[count2].type==5)
  790. {
  791. part1=physicstemp.bond[count2].part1;
  792. part2=physicstemp.bond[count2].part2;
  793. part3=physicstemp.bond[count2].part3;
  794. scalevector(vec,particle[part1].position,physicstemp.bond[count2].force[0]);
  795. scaleaddvectors(vec,vec,particle[part2].position,physicstemp.bond[count2].force[1]);
  796. copyvector(object[physicstemp.bond[count2].objectnum[0]].particlestickposition[physicstemp.bond[count2].part4],vec);
  797. subtractvectors(bondnormal,particle[part3].position,vec);
  798. subtractvectors(vec,particle[part2].position,particle[part1].position);
  799. vec2[0]=-vec[1];
  800. vec2[1]=vec[0];
  801. vec2[2]=0.0f;
  802. normalizevector(object[physicstemp.bond[count2].objectnum[0]].particlesticknormal[physicstemp.bond[count2].part4],vec2);
  803. scaleaddvectors(bondnormal,bondnormal,particle[part3].prevvelocity,1.0f);
  804. scaleaddvectors(bondnormal,bondnormal,particle[part2].prevvelocity,-physicstemp.bond[count2].force[1]*1.0f);
  805. scaleaddvectors(bondnormal,bondnormal,particle[part1].prevvelocity,-physicstemp.bond[count2].force[0]*1.0f);
  806. veclength=vectorlength(bondnormal);
  807. if (fabs(veclength)>physicstemp.bond[count2].breakpoint || (object[physicstemp.bond[count2].objectnum[0]].button&1)==0 || (object[physicstemp.bond[count2].objectnum[0]].button&4)==4 || (object[physicstemp.bond[count2].objectnum[1]].button&4)==4)
  808. {
  809. physicstemp.bond[count2].type=-1;
  810. object[physicstemp.bond[count2].objectnum[0]].particlestick[physicstemp.bond[count2].part4]=0;
  811. }
  812. }
  813. blocknum=physicstemp.bond[count2].blocknum;
  814. if (block[blocknum].breakpoint!=0.0f)
  815. {
  816. if (level.gridforce[physicstemp.bond[count2].blocky][physicstemp.bond[count2].blockx]>block[blocknum].breakpoint)
  817. {
  818. level.gridmod[physicstemp.bond[count2].blocky][physicstemp.bond[count2].blockx]=1;
  819. if (blocknum>=240 && blocknum<248)
  820. level.gridmod[physicstemp.bond[count2].blocky][physicstemp.bond[count2].blockx]=2;
  821. setuplevellines(physicstemp.bond[count2].blockx-1,physicstemp.bond[count2].blocky-1,physicstemp.bond[count2].blockx+1,physicstemp.bond[count2].blocky+1);
  822. vec[0]=(float)physicstemp.bond[count2].blockx+0.5f;
  823. vec[1]=(float)physicstemp.bond[count2].blocky+0.5f;
  824. vec[2]=0.0f;
  825. playsound(0,vec,NULL,0.75f,0,0.5f/block[blocknum].breakpoint,-1,0);
  826. if (level.gametype==0)
  827. {
  828. game.score[0]+=10;
  829. createsprite(10,vec);
  830. }
  831. /*
  832. vec[0]=(float)physicstemp.bond[count2].blockx+0.5f;
  833. vec[1]=(float)physicstemp.bond[count2].blocky+0.5f;
  834. vec[2]=0.0f;
  835. createbox(vec,0.99f,0.99f,block[blocknum].breakpoint*4.0f,block[blocknum].friction);
  836. object[numofobjects-1].timetolive=200+(rand()&63);
  837. object[numofobjects-1].texturenum=blocknum-256;
  838. object[numofobjects-1].texcoord[0][0]=0.0f;
  839. object[numofobjects-1].texcoord[0][1]=0.0f;
  840. object[numofobjects-1].texcoord[1][0]=1.0f;
  841. object[numofobjects-1].texcoord[1][1]=0.0f;
  842. object[numofobjects-1].texcoord[2][0]=1.0f;
  843. object[numofobjects-1].texcoord[2][1]=1.0f;
  844. object[numofobjects-1].texcoord[3][0]=0.0f;
  845. object[numofobjects-1].texcoord[3][1]=1.0f;
  846. */
  847. if (numofobjects<500)
  848. {
  849. vec[0]=(float)physicstemp.bond[count2].blockx+0.25f;
  850. vec[1]=(float)physicstemp.bond[count2].blocky+0.75f;
  851. vec[2]=0.0f;
  852. createbox(vec,0.49f,0.49f,block[blocknum].breakpoint,block[blocknum].friction);
  853. object[numofobjects-1].timetolive=200;
  854. object[numofobjects-1].texturenum=blocknum-256;
  855. object[numofobjects-1].texcoord[0][0]=0.0f;
  856. object[numofobjects-1].texcoord[0][1]=0.0f;
  857. object[numofobjects-1].texcoord[1][0]=0.5f;
  858. object[numofobjects-1].texcoord[1][1]=0.0f;
  859. object[numofobjects-1].texcoord[2][0]=0.5f;
  860. object[numofobjects-1].texcoord[2][1]=0.5f;
  861. object[numofobjects-1].texcoord[3][0]=0.0f;
  862. object[numofobjects-1].texcoord[3][1]=0.5f;
  863. vec[0]=(float)physicstemp.bond[count2].blockx+0.75f;
  864. vec[1]=(float)physicstemp.bond[count2].blocky+0.75f;
  865. vec[2]=0.0f;
  866. createbox(vec,0.49f,0.49f,block[blocknum].breakpoint,block[blocknum].friction);
  867. object[numofobjects-1].timetolive=200;
  868. object[numofobjects-1].texturenum=blocknum-256;
  869. object[numofobjects-1].texcoord[0][0]=0.0f+0.5f;
  870. object[numofobjects-1].texcoord[0][1]=0.0f;
  871. object[numofobjects-1].texcoord[1][0]=0.5f+0.5f;
  872. object[numofobjects-1].texcoord[1][1]=0.0f;
  873. object[numofobjects-1].texcoord[2][0]=0.5f+0.5f;
  874. object[numofobjects-1].texcoord[2][1]=0.5f;
  875. object[numofobjects-1].texcoord[3][0]=0.0f+0.5f;
  876. object[numofobjects-1].texcoord[3][1]=0.5f;
  877. vec[0]=(float)physicstemp.bond[count2].blockx+0.75f;
  878. vec[1]=(float)physicstemp.bond[count2].blocky+0.25f;
  879. vec[2]=0.0f;
  880. createbox(vec,0.49f,0.49f,block[blocknum].breakpoint,block[blocknum].friction);
  881. object[numofobjects-1].timetolive=200;
  882. object[numofobjects-1].texturenum=blocknum-256;
  883. object[numofobjects-1].texcoord[0][0]=0.0f+0.5f;
  884. object[numofobjects-1].texcoord[0][1]=0.0f+0.5f;
  885. object[numofobjects-1].texcoord[1][0]=0.5f+0.5f;
  886. object[numofobjects-1].texcoord[1][1]=0.0f+0.5f;
  887. object[numofobjects-1].texcoord[2][0]=0.5f+0.5f;
  888. object[numofobjects-1].texcoord[2][1]=0.5f+0.5f;
  889. object[numofobjects-1].texcoord[3][0]=0.0f+0.5f;
  890. object[numofobjects-1].texcoord[3][1]=0.5f+0.5f;
  891. vec[0]=(float)physicstemp.bond[count2].blockx+0.25f;
  892. vec[1]=(float)physicstemp.bond[count2].blocky+0.25f;
  893. vec[2]=0.0f;
  894. createbox(vec,0.49f,0.49f,block[blocknum].breakpoint,block[blocknum].friction);
  895. object[numofobjects-1].timetolive=200;
  896. object[numofobjects-1].texturenum=blocknum-256;
  897. object[numofobjects-1].texcoord[0][0]=0.0f;
  898. object[numofobjects-1].texcoord[0][1]=0.0f+0.5f;
  899. object[numofobjects-1].texcoord[1][0]=0.5f;
  900. object[numofobjects-1].texcoord[1][1]=0.0f+0.5f;
  901. object[numofobjects-1].texcoord[2][0]=0.5f;
  902. object[numofobjects-1].texcoord[2][1]=0.5f+0.5f;
  903. object[numofobjects-1].texcoord[3][0]=0.0f;
  904. object[numofobjects-1].texcoord[3][1]=0.5f+0.5f;
  905. }
  906. }
  907. level.gridforce[physicstemp.bond[count2].blocky][physicstemp.bond[count2].blockx]=0.0f;
  908. }
  909. }
  910. count2=0;
  911. while (count2<physicstemp.numofbonds)
  912. {
  913. while (count2<physicstemp.numofbonds && physicstemp.bond[count2].type!=1 && physicstemp.bond[count2].type!=5)
  914. {
  915. physicstemp.numofbonds--;
  916. memcpy(&physicstemp.bond[count2],&physicstemp.bond[physicstemp.numofbonds],sizeof(physicstemp.bond[0]));
  917. }
  918. count2++;
  919. }
  920. }
  921. int lineintersectline2(float *intersectpoint,float *normal,float *scale,float *startpoint,float *endpoint,float *vertex1,float *vertex2)
  922. {
  923. float vec[3],vec2[3];
  924. float dot1,dot2;
  925. normal[0]=vertex1[1]-vertex2[1];
  926. normal[1]=vertex2[0]-vertex1[0];
  927. normal[2]=0.0f;
  928. vec[0]=startpoint[0]-vertex1[0];
  929. vec[1]=startpoint[1]-vertex1[1];
  930. vec[2]=0.0f;
  931. vec2[0]=endpoint[0]-vertex1[0];
  932. vec2[1]=endpoint[1]-vertex1[1];
  933. vec2[2]=0.0f;
  934. dot1=dotproduct(normal,vec);
  935. dot2=dotproduct(normal,vec2);
  936. if (dot1>0.0f)
  937. if (dot2>0.0f)
  938. return(0);
  939. if (dot1<0.0f)
  940. return(0);
  941. normalizevector(normal,normal);
  942. vec[0]=vertex1[0]-startpoint[0];
  943. vec[1]=vertex1[1]-startpoint[1];
  944. vec[2]=0.0f;
  945. *scale=dotproduct(vec,normal);
  946. vec[0]=endpoint[0]-startpoint[0];
  947. vec[1]=endpoint[1]-startpoint[1];
  948. vec[2]=0.0f;
  949. *scale/=dotproduct(vec,normal);
  950. scaleaddvectors(intersectpoint,startpoint,vec,*scale);
  951. vec[0]=intersectpoint[0]-vertex1[0];
  952. vec[1]=intersectpoint[1]-vertex1[1];
  953. vec[2]=0.0f;
  954. vec2[0]=vertex2[0]-vertex1[0];
  955. vec2[1]=vertex2[1]-vertex1[1];
  956. vec2[2]=0.0f;
  957. if (dotproduct(vec,vec2)<0.0f)
  958. return(0);
  959. vec[0]=intersectpoint[0]-vertex2[0];
  960. vec[1]=intersectpoint[1]-vertex2[1];
  961. vec[2]=0.0f;
  962. vec2[0]=vertex1[0]-vertex2[0];
  963. vec2[1]=vertex1[1]-vertex2[1];
  964. vec2[2]=0.0f;
  965. if (dotproduct(vec,vec2)<0.0f)
  966. return(0);
  967. return(1);
  968. }