1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
2 | // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. |
---|
3 | // See LICENSE.txt for details. |
---|
4 | |
---|
5 | #include <stdlib.h> |
---|
6 | #include <math.h> |
---|
7 | #include <stdio.h> |
---|
8 | #include <string.h> |
---|
9 | #include <ctype.h> |
---|
10 | #include <time.h> |
---|
11 | #include <errno.h> |
---|
12 | |
---|
13 | /////////////////////////////// MODELPARTS.CPP /////////////// |
---|
14 | |
---|
15 | #include "modelparts.h" |
---|
16 | #include "model.h" |
---|
17 | |
---|
18 | #include <common/nonstd.h> |
---|
19 | #include <frams/param/param.h> |
---|
20 | #include <frams/neuro/neurolibrary.h> |
---|
21 | #include <frams/util/multirange.h> |
---|
22 | #include <frams/util/extvalue.h> |
---|
23 | #include <frams/param/paramobj.h> |
---|
24 | #include <frams/neuro/neuroimpl.h> |
---|
25 | |
---|
26 | #include F0_DEFASSIGN_FILE |
---|
27 | |
---|
28 | #ifndef SDK_WITHOUT_FRAMS |
---|
29 | #include <frams/neuro/neuroclsobject.h> |
---|
30 | #endif |
---|
31 | |
---|
32 | ///////////////////////// |
---|
33 | |
---|
34 | PartBase::~PartBase() |
---|
35 | { |
---|
36 | if (mapped) delete mapped; |
---|
37 | } |
---|
38 | |
---|
39 | void PartBase::notifyMappingChange() |
---|
40 | { |
---|
41 | if (owner) owner->partmappingchanged = 1; |
---|
42 | } |
---|
43 | |
---|
44 | void PartBase::setMapping(const IRange &r) |
---|
45 | { |
---|
46 | if (mapped) (*mapped) = r; |
---|
47 | else mapped = new MultiRange(r); |
---|
48 | notifyMappingChange(); |
---|
49 | } |
---|
50 | |
---|
51 | void PartBase::clearMapping() |
---|
52 | { |
---|
53 | if (mapped) { delete mapped; mapped = 0; } |
---|
54 | } |
---|
55 | |
---|
56 | void PartBase::addMapping(const IRange &r) |
---|
57 | { |
---|
58 | if (mapped) mapped->add(r); |
---|
59 | else mapped = new MultiRange(r); |
---|
60 | notifyMappingChange(); |
---|
61 | } |
---|
62 | |
---|
63 | void PartBase::setMapping(const MultiRange &mr) |
---|
64 | { |
---|
65 | if (mapped) (*mapped) = mr; |
---|
66 | else mapped = new MultiRange(mr); |
---|
67 | notifyMappingChange(); |
---|
68 | } |
---|
69 | |
---|
70 | void PartBase::addMapping(const MultiRange &mr) |
---|
71 | { |
---|
72 | if (mapped) mapped->add(mr); |
---|
73 | else mapped = new MultiRange(mr); |
---|
74 | notifyMappingChange(); |
---|
75 | } |
---|
76 | |
---|
77 | void PartBase::setInfo(const SString &name, const SString &value) |
---|
78 | { |
---|
79 | strSetField(info, name, value); |
---|
80 | } |
---|
81 | |
---|
82 | void PartBase::setInfo(const SString &name, int value) |
---|
83 | { |
---|
84 | setInfo(name, SString::valueOf(value)); |
---|
85 | } |
---|
86 | |
---|
87 | void PartBase::setInfo(const SString &name, double value) |
---|
88 | { |
---|
89 | setInfo(name, SString::valueOf(value)); |
---|
90 | } |
---|
91 | |
---|
92 | SString PartBase::getInfo(const SString &name) |
---|
93 | { |
---|
94 | return strGetField(info, name); |
---|
95 | } |
---|
96 | |
---|
97 | ///////////////////////// |
---|
98 | |
---|
99 | NeuroClass::NeuroClass(ParamEntry *_props, SString _description, |
---|
100 | int _prefinputs, int _prefoutput, int _preflocation, |
---|
101 | int *_vectordata, bool own_vd, int vhints, int sup_shapes, int sup_joints) |
---|
102 | :ownedvectordata(own_vd), |
---|
103 | name(_props->name), longname(_props->id), description(_description), |
---|
104 | props(_props), ownedprops(false), |
---|
105 | prefinputs(_prefinputs), |
---|
106 | prefoutput(_prefoutput), |
---|
107 | preflocation(_preflocation), |
---|
108 | supported_shape_types(sup_shapes), |
---|
109 | supported_joint_shapes(sup_joints), |
---|
110 | vectordata(_vectordata), |
---|
111 | visualhints(vhints), impl_count(0),/*impl(0),*/active(1), genactive(0) |
---|
112 | {} |
---|
113 | |
---|
114 | NeuroClass::~NeuroClass() |
---|
115 | { |
---|
116 | setSymbolGlyph(0, 0); |
---|
117 | if (props && ownedprops) |
---|
118 | ParamObject::freeParamTab(props); |
---|
119 | } |
---|
120 | |
---|
121 | NeuroClass::NeuroClass() |
---|
122 | :ownedvectordata(0), |
---|
123 | name("Invalid"), |
---|
124 | props(empty_paramtab), ownedprops(false), |
---|
125 | prefinputs(0), prefoutput(0), |
---|
126 | preflocation(0), vectordata(0), |
---|
127 | visualhints(0), impl_count(0), /*impl(0),*/ active(1), genactive(0) |
---|
128 | {} |
---|
129 | |
---|
130 | void NeuroClass::resetActive() |
---|
131 | { |
---|
132 | for (int i = 0; i < Neuro::getClassCount(); i++) |
---|
133 | { |
---|
134 | Neuro::getClass(i)->genactive = 0; |
---|
135 | Neuro::getClass(i)->active = 1; |
---|
136 | } |
---|
137 | } |
---|
138 | |
---|
139 | void NeuroClass::setGenActive(const char *genactive_classes[]) |
---|
140 | { |
---|
141 | for (const char **n = genactive_classes; *n; n++) |
---|
142 | { |
---|
143 | NeuroClass *cls = Neuro::getClass(*n); |
---|
144 | if (cls) cls->genactive = 1; |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | SString NeuroClass::getSummary() |
---|
149 | { |
---|
150 | SString t; |
---|
151 | t = getDescription(); |
---|
152 | if (t.length()) t += "\n\n"; |
---|
153 | t += "Characteristics:\n"; |
---|
154 | if (getPreferredInputs()) |
---|
155 | { |
---|
156 | if (getPreferredInputs() < 0) t += " supports any number of inputs\n"; |
---|
157 | else if (getPreferredInputs() == 1) t += " uses single input\n"; |
---|
158 | else t += SString::sprintf(" uses %d inputs\n", getPreferredInputs()); |
---|
159 | } |
---|
160 | else t += " does not use inputs\n"; |
---|
161 | if (getPreferredOutput()) |
---|
162 | t += " provides output value\n"; |
---|
163 | else |
---|
164 | t += " does not provide output value\n"; |
---|
165 | switch (getPreferredLocation()) |
---|
166 | { |
---|
167 | case 0: t += " does not require location in body\n"; break; |
---|
168 | case 1: t += " should be located on a Part\n"; break; |
---|
169 | case 2: t += " should be located on a Joint\n"; break; |
---|
170 | } |
---|
171 | Param p = getProperties(); |
---|
172 | if (p.getPropCount()) |
---|
173 | { |
---|
174 | if (t.length()) t += "\n\n"; |
---|
175 | t += "Properties:\n"; |
---|
176 | const char *h; |
---|
177 | int i; |
---|
178 | for (i = 0; i < p.getPropCount(); i++) |
---|
179 | { |
---|
180 | if (i) t += "\n"; |
---|
181 | t += " "; t += p.name(i); t += " ("; t += p.id(i); t += ") "; |
---|
182 | t += p.friendlyTypeDescr(i); |
---|
183 | if (h = p.help(i)) if (*h) { t += " - "; t += h; } |
---|
184 | } |
---|
185 | } |
---|
186 | return t; |
---|
187 | } |
---|
188 | |
---|
189 | ///////////////////////// |
---|
190 | |
---|
191 | ///////////////////////////////////// |
---|
192 | |
---|
193 | Neuro::Neuro(double _state, double _inertia, double _force, double _sigmo) |
---|
194 | :PartBase(getDefaultStyle()), state(_state) |
---|
195 | { |
---|
196 | flags = 0; |
---|
197 | myclass = 0; |
---|
198 | knownclass = 1; |
---|
199 | part_refno = -1; joint_refno = -1; |
---|
200 | } |
---|
201 | |
---|
202 | Neuro::Neuro(void) :PartBase(getDefaultStyle()) |
---|
203 | { |
---|
204 | defassign(); |
---|
205 | state = 0.0; |
---|
206 | myclass = NULL; |
---|
207 | myclassname = "N";//default d="N" but f0.def is unable to set this (d is GETSET, not a regular FIELD) |
---|
208 | knownclass = 0; |
---|
209 | refno = 0; |
---|
210 | pos = Pt3D_0; rot = Pt3D_0; |
---|
211 | parent = 0; part = 0; joint = 0; |
---|
212 | parentcount = 0; |
---|
213 | flags = 0; |
---|
214 | part_refno = -1; joint_refno = -1; |
---|
215 | } |
---|
216 | |
---|
217 | |
---|
218 | Neuro::~Neuro() |
---|
219 | { |
---|
220 | int i; |
---|
221 | for (i = 0; i < inputs.size(); i++) |
---|
222 | { |
---|
223 | NInput &ni = inputs(i); |
---|
224 | if (ni.info) delete ni.info; |
---|
225 | } |
---|
226 | } |
---|
227 | |
---|
228 | SString **Neuro::inputInfo(int i) |
---|
229 | { |
---|
230 | if (i >= getInputCount()) return 0; |
---|
231 | return &inputs(i).info; |
---|
232 | } |
---|
233 | |
---|
234 | void Neuro::setInputInfo(int i, const SString &name, const SString &value) |
---|
235 | { |
---|
236 | SString **s = inputInfo(i); |
---|
237 | if (!s) return; |
---|
238 | if (!*s) *s = new SString(); |
---|
239 | strSetField(**s, name, value); |
---|
240 | } |
---|
241 | |
---|
242 | void Neuro::setInputInfo(int i, const SString &name, int value) |
---|
243 | { |
---|
244 | setInputInfo(i, name, SString::valueOf(value)); |
---|
245 | } |
---|
246 | |
---|
247 | void Neuro::setInputInfo(int i, const SString &name, double value) |
---|
248 | { |
---|
249 | setInputInfo(i, name, SString::valueOf(value)); |
---|
250 | } |
---|
251 | |
---|
252 | SString Neuro::getInputInfo(int i) |
---|
253 | { |
---|
254 | SString **s = inputInfo(i); |
---|
255 | if (!s) return SString(); |
---|
256 | if (!*s) return SString(); |
---|
257 | return **s; |
---|
258 | } |
---|
259 | |
---|
260 | SString Neuro::getInputInfo(int i, const SString &name) |
---|
261 | { |
---|
262 | SString **s = inputInfo(i); |
---|
263 | if (!s) return SString(); |
---|
264 | if (!*s) return SString(); |
---|
265 | return strGetField(**s, name); |
---|
266 | } |
---|
267 | |
---|
268 | void Neuro::operator=(const Neuro &src) |
---|
269 | { |
---|
270 | refno = src.refno; |
---|
271 | state = src.state; |
---|
272 | part_refno = -1; |
---|
273 | joint_refno = -1; |
---|
274 | pos = src.pos; rot = src.rot; |
---|
275 | parent = 0; part = 0; joint = 0; |
---|
276 | parentcount = 0; |
---|
277 | flags = 0; |
---|
278 | myclass = src.myclass; |
---|
279 | knownclass = src.knownclass; |
---|
280 | myclassname = src.myclassname; |
---|
281 | myclassparams = src.myclassparams; |
---|
282 | } |
---|
283 | |
---|
284 | void Neuro::attachToPart(int i) |
---|
285 | { |
---|
286 | attachToPart((i >= 0) ? owner->getPart(i) : 0); |
---|
287 | } |
---|
288 | |
---|
289 | void Neuro::attachToJoint(int i) |
---|
290 | { |
---|
291 | attachToJoint((i >= 0) ? owner->getJoint(i) : 0); |
---|
292 | } |
---|
293 | |
---|
294 | int Neuro::getClassCount() |
---|
295 | { |
---|
296 | return NeuroLibrary::staticlibrary.getClassCount(); |
---|
297 | } |
---|
298 | |
---|
299 | NeuroClass *Neuro::getClass(int classindex) |
---|
300 | { |
---|
301 | return NeuroLibrary::staticlibrary.getClass(classindex); |
---|
302 | } |
---|
303 | |
---|
304 | NeuroClass *Neuro::getClass(const SString &classname) |
---|
305 | { |
---|
306 | return NeuroLibrary::staticlibrary.findClass(classname); |
---|
307 | } |
---|
308 | |
---|
309 | int Neuro::getClassIndex(const NeuroClass *nc) |
---|
310 | { |
---|
311 | return NeuroLibrary::staticlibrary.classes.find((void *)nc); |
---|
312 | } |
---|
313 | |
---|
314 | NeuroClass *Neuro::getClass() |
---|
315 | { |
---|
316 | checkClass(); |
---|
317 | return myclass; |
---|
318 | } |
---|
319 | |
---|
320 | void Neuro::setClass(NeuroClass *cl) |
---|
321 | { |
---|
322 | myclass = cl; |
---|
323 | myclassname = cl->getName(); |
---|
324 | knownclass = 1; |
---|
325 | } |
---|
326 | |
---|
327 | SString Neuro::getClassName(int classindex) |
---|
328 | { |
---|
329 | NeuroClass *cl = NeuroLibrary::staticlibrary.getClass(classindex); |
---|
330 | return cl ? cl->getName() : SString(); |
---|
331 | } |
---|
332 | |
---|
333 | void Neuro::setDetails(const SString &details) |
---|
334 | { |
---|
335 | int colon = details.indexOf(':'); |
---|
336 | if (colon >= 0) { myclassname = details.substr(0, colon); myclassparams = details.substr(colon + 1); } |
---|
337 | else { myclassname = details; myclassparams = 0; } |
---|
338 | knownclass = 0; |
---|
339 | } |
---|
340 | |
---|
341 | SString Neuro::getDetails() |
---|
342 | { |
---|
343 | SString ret = getClassName(); |
---|
344 | if (myclassparams.length()) { if (!ret.length()) ret = "N"; ret += ":"; ret += myclassparams; } |
---|
345 | return ret; |
---|
346 | } |
---|
347 | |
---|
348 | void Neuro::checkClass() |
---|
349 | { |
---|
350 | if (knownclass) return; |
---|
351 | myclass = getClass(myclassname); |
---|
352 | knownclass = 1; |
---|
353 | } |
---|
354 | |
---|
355 | SyntParam Neuro::classProperties(bool handle_defaults_when_saving) |
---|
356 | { |
---|
357 | NeuroClass *cl = getClass(); |
---|
358 | ParamEntry *pe = cl ? cl->getParamTab() : emptyParamTab; |
---|
359 | return SyntParam(pe, &myclassparams, handle_defaults_when_saving); |
---|
360 | } |
---|
361 | |
---|
362 | SString Neuro::getClassName() |
---|
363 | { |
---|
364 | return myclassname; |
---|
365 | } |
---|
366 | |
---|
367 | void Neuro::setClassName(const SString &clazz) |
---|
368 | { |
---|
369 | myclassname = clazz; |
---|
370 | knownclass = 0; |
---|
371 | } |
---|
372 | |
---|
373 | int Neuro::addInput(Neuro *child, double weight, const SString *info) |
---|
374 | { |
---|
375 | inputs += NInput(child, weight, (info && (info->length())) ? new SString(*info) : 0); |
---|
376 | child->parentcount++; |
---|
377 | if (child->parentcount == 1) { child->parent = this; } |
---|
378 | return inputs.size() - 1; |
---|
379 | } |
---|
380 | |
---|
381 | int Neuro::findInput(Neuro *child) const |
---|
382 | { |
---|
383 | for (int i = 0; i < inputs.size(); i++) |
---|
384 | if (inputs(i).n == child) return i; |
---|
385 | return -1; |
---|
386 | } |
---|
387 | |
---|
388 | Neuro *Neuro::getInput(int i, double &weight) const |
---|
389 | { |
---|
390 | if (i >= getInputCount()) return 0; |
---|
391 | NInput &inp = inputs(i); |
---|
392 | weight = inp.weight; |
---|
393 | return inp.n; |
---|
394 | } |
---|
395 | |
---|
396 | double Neuro::getInputWeight(int i) const |
---|
397 | { |
---|
398 | return inputs(i).weight; |
---|
399 | } |
---|
400 | |
---|
401 | void Neuro::setInputWeight(int i, double w) |
---|
402 | { |
---|
403 | inputs(i).weight = w; |
---|
404 | } |
---|
405 | |
---|
406 | void Neuro::setInput(int i, Neuro *n) |
---|
407 | { |
---|
408 | NInput &inp = inputs(i); |
---|
409 | inp.n = n; |
---|
410 | } |
---|
411 | |
---|
412 | void Neuro::setInput(int i, Neuro *n, double w) |
---|
413 | { |
---|
414 | NInput &inp = inputs(i); |
---|
415 | inp.n = n; |
---|
416 | inp.weight = w; |
---|
417 | } |
---|
418 | |
---|
419 | void Neuro::removeInput(int refno) |
---|
420 | { |
---|
421 | Neuro *child = getInput(refno); |
---|
422 | child->parentcount--; |
---|
423 | if (child->parent == this) child->parent = 0; |
---|
424 | SString *s = inputs(refno).info; |
---|
425 | if (s) delete s; |
---|
426 | inputs.remove(refno); |
---|
427 | } |
---|
428 | |
---|
429 | int Neuro::removeInput(Neuro *child) |
---|
430 | { |
---|
431 | int i = findInput(child); |
---|
432 | if (i >= 0) removeInput(i); |
---|
433 | return i; |
---|
434 | } |
---|
435 | |
---|
436 | int Neuro::getOutputsCount() const |
---|
437 | { |
---|
438 | int c = 0; |
---|
439 | for (int i = 0; i < owner->getNeuroCount(); i++) |
---|
440 | for (int j = 0; j < owner->getNeuro(i)->getInputCount(); j++) c += owner->getNeuro(i)->getInput(j) == this; |
---|
441 | return c; |
---|
442 | } |
---|
443 | |
---|
444 | int Neuro::isOldEffector() |
---|
445 | { |
---|
446 | static SString bend("|"), rot("@"); |
---|
447 | return ((getClassName() == bend) || (getClassName() == rot)); |
---|
448 | } |
---|
449 | |
---|
450 | int Neuro::isOldReceptor() |
---|
451 | { |
---|
452 | static SString g("G"), t("T"), s("S"); |
---|
453 | return ((getClassName() == g) || (getClassName() == t) || (getClassName() == s)); |
---|
454 | } |
---|
455 | |
---|
456 | int Neuro::isOldNeuron() |
---|
457 | { |
---|
458 | static SString n("N"); |
---|
459 | return (getClassName() == n); |
---|
460 | } |
---|
461 | |
---|
462 | int Neuro::isNNConnection() |
---|
463 | { |
---|
464 | static SString conn("-"); |
---|
465 | return (getClassName() == conn); |
---|
466 | } |
---|
467 | |
---|
468 | int Neuro::findInputs(SList &result, const char *classname, const Part *part, const Joint *joint) const |
---|
469 | { |
---|
470 | Neuro *nu; |
---|
471 | SString cn(classname); |
---|
472 | int n0 = result.size(); |
---|
473 | for (int i = 0; nu = getInput(i); i++) |
---|
474 | { |
---|
475 | if (part) |
---|
476 | if (nu->part != part) continue; |
---|
477 | if (joint) |
---|
478 | if (nu->joint != joint) continue; |
---|
479 | if (classname) |
---|
480 | if (nu->getClassName() != cn) continue; |
---|
481 | result += (void *)nu; |
---|
482 | } |
---|
483 | return result.size() - n0; |
---|
484 | } |
---|
485 | |
---|
486 | int Neuro::findOutputs(SList &result, const char *classname, const Part *part, const Joint *joint) const |
---|
487 | { // not very efficient... |
---|
488 | Neuro *nu, *inp; |
---|
489 | SString cn(classname); |
---|
490 | SList found; |
---|
491 | int n0 = result.size(); |
---|
492 | for (int i = 0; nu = getModel().getNeuro(i); i++) |
---|
493 | { |
---|
494 | if (part) |
---|
495 | if (nu->part != part) continue; |
---|
496 | if (joint) |
---|
497 | if (nu->joint != joint) continue; |
---|
498 | if (classname) |
---|
499 | if (inp->getClassName() != cn) continue; |
---|
500 | for (int j = 0; inp = nu->getInput(j); j++) |
---|
501 | if (inp == this) |
---|
502 | { |
---|
503 | result += (void *)nu; |
---|
504 | break; |
---|
505 | } |
---|
506 | } |
---|
507 | return result.size() - n0; |
---|
508 | } |
---|
509 | |
---|
510 | void Neuro::get_inputCount(PARAMGETARGS) |
---|
511 | { |
---|
512 | ret->setInt(inputs.size()); |
---|
513 | } |
---|
514 | |
---|
515 | void Neuro::p_getInputNeuroDef(ExtValue *args, ExtValue *ret) |
---|
516 | { |
---|
517 | int i = args->getInt(); |
---|
518 | if ((i < 0) || (i >= inputs.size())) |
---|
519 | ret->setEmpty(); |
---|
520 | else |
---|
521 | ret->setObject(ExtObject(&Neuro::getStaticParam(), inputs(i).n)); |
---|
522 | } |
---|
523 | |
---|
524 | void Neuro::p_getInputWeight(ExtValue *args, ExtValue *ret) |
---|
525 | { |
---|
526 | int i = args->getInt(); |
---|
527 | if ((i < 0) || (i >= inputs.size())) |
---|
528 | ret->setEmpty(); |
---|
529 | else |
---|
530 | ret->setDouble(inputs(i).weight); |
---|
531 | } |
---|
532 | |
---|
533 | void Neuro::p_getInputNeuroIndex(ExtValue *args, ExtValue *ret) |
---|
534 | { |
---|
535 | int i = args->getInt(); |
---|
536 | if ((i < 0) || (i >= inputs.size())) |
---|
537 | ret->setInt(-1); |
---|
538 | else |
---|
539 | ret->setInt(inputs(i).n->refno); |
---|
540 | } |
---|
541 | |
---|
542 | void Neuro::get_classObject(PARAMGETARGS) |
---|
543 | { |
---|
544 | #ifndef SDK_WITHOUT_FRAMS |
---|
545 | NeuroClassExt::makeStaticObject(ret, getClass()); |
---|
546 | #endif |
---|
547 | } |
---|
548 | |
---|
549 | /////////////////////////////////////// |
---|
550 | |
---|
551 | SString Part::getDefaultStyle() |
---|
552 | { |
---|
553 | return SString("part"); |
---|
554 | } |
---|
555 | SString Joint::getDefaultStyle() |
---|
556 | { |
---|
557 | return SString("joint"); |
---|
558 | } |
---|
559 | /* |
---|
560 | const SString& Neuro::getDefaultStyle() |
---|
561 | {static SString s("neuro"); return s;} |
---|
562 | const SString& NeuroItem::getDefaultStyle() |
---|
563 | {static SString s("neuroitem"); return s;} |
---|
564 | */ |
---|
565 | SString Neuro::getDefaultStyle() |
---|
566 | { |
---|
567 | return SString("neuro"); |
---|
568 | } |
---|
569 | |
---|
570 | Part::Part(enum Shape s) :PartBase(getDefaultStyle()) |
---|
571 | { |
---|
572 | o = Orient_1; |
---|
573 | p = Pt3D_0; |
---|
574 | rot = Pt3D_0; |
---|
575 | flags = 0; |
---|
576 | defassign(); |
---|
577 | shape = s; |
---|
578 | mass = 1; |
---|
579 | } |
---|
580 | |
---|
581 | void Part::operator=(const Part &src) |
---|
582 | { |
---|
583 | p = src.p; o = src.o; |
---|
584 | flags = src.flags; |
---|
585 | mass = src.mass; density = src.density; |
---|
586 | friction = src.friction; |
---|
587 | ingest = src.ingest; |
---|
588 | assim = src.assim; |
---|
589 | size = src.size; |
---|
590 | rot = src.rot; |
---|
591 | refno = src.refno; |
---|
592 | vcolor = src.vcolor; |
---|
593 | vsize = src.vsize; |
---|
594 | vis_style = src.vis_style; |
---|
595 | shape = src.shape; |
---|
596 | scale = src.scale; |
---|
597 | hollow = src.hollow; |
---|
598 | } |
---|
599 | |
---|
600 | void Part::setOrient(const Orient &_o) |
---|
601 | { |
---|
602 | o = _o; |
---|
603 | rot.getAngles(o.x, o.z); |
---|
604 | } |
---|
605 | |
---|
606 | void Part::setRot(const Pt3D &r) |
---|
607 | { |
---|
608 | rot = r; |
---|
609 | o = Orient_1; |
---|
610 | o.rotate(rot); |
---|
611 | } |
---|
612 | |
---|
613 | void Part::setPositionAndRotationFromAxis(const Pt3D &p1, const Pt3D &p2) |
---|
614 | { |
---|
615 | Pt3D x = p2 - p1; |
---|
616 | Pt3D dir(x.y, x.z, x.x); |
---|
617 | p = p1 + x * 0.5; |
---|
618 | rot.getAngles(x, dir); |
---|
619 | } |
---|
620 | |
---|
621 | Param &Part::getStaticParam() |
---|
622 | { |
---|
623 | static Param p(f0_part_paramtab, 0, "Part"); |
---|
624 | return p; |
---|
625 | } |
---|
626 | |
---|
627 | const char* Part::getShapeName(Shape sh) |
---|
628 | { |
---|
629 | switch (sh) |
---|
630 | { |
---|
631 | case SHAPE_BALL_AND_STICK: return "ball-and-stick"; |
---|
632 | case SHAPE_ELLIPSOID: return "ellipsoid"; |
---|
633 | case SHAPE_CUBOID: return "cuboid"; |
---|
634 | case SHAPE_CYLINDER: return "cylinder"; |
---|
635 | |
---|
636 | default: |
---|
637 | return "unknown shape"; |
---|
638 | } |
---|
639 | } |
---|
640 | |
---|
641 | /////////////////////////// |
---|
642 | |
---|
643 | Joint::Joint() :PartBase(getDefaultStyle()) |
---|
644 | { |
---|
645 | rot = Pt3D_0; |
---|
646 | defassign(); |
---|
647 | d.x = JOINT_DELTA_MARKER; |
---|
648 | d.y = JOINT_DELTA_MARKER; |
---|
649 | d.z = JOINT_DELTA_MARKER; |
---|
650 | part1 = 0; part2 = 0; |
---|
651 | flags = 0; |
---|
652 | usedelta = 0; |
---|
653 | } |
---|
654 | |
---|
655 | void Joint::operator=(const Joint &src) |
---|
656 | { |
---|
657 | rot = src.rot; |
---|
658 | d = src.d; |
---|
659 | shape = src.shape; |
---|
660 | hinge_pos = src.hinge_pos; |
---|
661 | hinge_rot = src.hinge_rot; |
---|
662 | hinge_limit_x[0] = src.hinge_limit_x[0]; |
---|
663 | hinge_limit_x[1] = src.hinge_limit_x[1]; |
---|
664 | hinge_limit_y[0] = src.hinge_limit_y[0]; |
---|
665 | hinge_limit_y[1] = src.hinge_limit_y[1]; |
---|
666 | stamina = src.stamina; |
---|
667 | stif = src.stif; rotstif = src.rotstif; |
---|
668 | vis_style = src.vis_style; |
---|
669 | vcolor = src.vcolor; |
---|
670 | part1 = 0; part2 = 0; |
---|
671 | flags = src.flags; |
---|
672 | usedelta = src.usedelta; |
---|
673 | refno = src.refno; |
---|
674 | } |
---|
675 | |
---|
676 | void Joint::attachToParts(Part *p1, Part *p2) |
---|
677 | { |
---|
678 | part1 = p1; |
---|
679 | part2 = p2; |
---|
680 | if (p1 && p2) |
---|
681 | { |
---|
682 | o = rot; |
---|
683 | if (usedelta) |
---|
684 | { |
---|
685 | p1->o.transform(p2->o, o); |
---|
686 | // p2->o.x=p1->o/o.x; p2->o.y=p1->o/o.y; p2->o.z=p1->o/o.z; |
---|
687 | p2->p = p2->o.transform(d) + p1->p; |
---|
688 | } |
---|
689 | } |
---|
690 | } |
---|
691 | |
---|
692 | void Joint::attachToParts(int p1, int p2) |
---|
693 | { |
---|
694 | attachToParts((p1 >= 0) ? owner->getPart(p1) : 0, (p2 >= 0) ? owner->getPart(p2) : 0); |
---|
695 | } |
---|
696 | |
---|
697 | void Joint::resetDelta() |
---|
698 | { |
---|
699 | d = Pt3D(JOINT_DELTA_MARKER, JOINT_DELTA_MARKER, JOINT_DELTA_MARKER); |
---|
700 | } |
---|
701 | |
---|
702 | void Joint::resetDeltaMarkers() |
---|
703 | { |
---|
704 | if (d.x == JOINT_DELTA_MARKER) d.x = 0; |
---|
705 | if (d.y == JOINT_DELTA_MARKER) d.y = 0; |
---|
706 | if (d.z == JOINT_DELTA_MARKER) d.z = 0; |
---|
707 | } |
---|
708 | |
---|
709 | void Joint::useDelta(bool use) |
---|
710 | { |
---|
711 | usedelta = use; |
---|
712 | } |
---|
713 | |
---|
714 | bool Joint::isDelta() |
---|
715 | { |
---|
716 | return usedelta; |
---|
717 | } |
---|
718 | |
---|
719 | Param &Joint::getStaticParam() |
---|
720 | { |
---|
721 | static Param p(f0_joint_paramtab, 0, "Joint"); |
---|
722 | return p; |
---|
723 | } |
---|
724 | |
---|
725 | const char* Joint::getShapeName(Shape sh) |
---|
726 | { |
---|
727 | switch (sh) |
---|
728 | { |
---|
729 | case SHAPE_BALL_AND_STICK: return "ball-and-stick"; |
---|
730 | case SHAPE_FIXED: return "fixed"; |
---|
731 | case SHAPE_HINGE_X: return "hinge x"; |
---|
732 | case SHAPE_HINGE_XY: return "hinge xy"; |
---|
733 | |
---|
734 | default: |
---|
735 | return "unknown shape"; |
---|
736 | } |
---|
737 | } |
---|
738 | |
---|
739 | |
---|
740 | ///////////////////////////////////////////////////////////////// |
---|
741 | |
---|
742 | #include F0_CLASSES_FILE |
---|
743 | |
---|
744 | //////////////////////////////////////// |
---|
745 | |
---|
746 | ParamEntry Neuro::emptyParamTab[] = |
---|
747 | { |
---|
748 | { "Undefined Neuro", 1, 0, "?", }, |
---|
749 | { 0, 0, 0, }, |
---|
750 | }; |
---|
751 | |
---|
752 | Param Part::extraProperties() |
---|
753 | { |
---|
754 | return Param(f0_part_xtra_paramtab, this); |
---|
755 | } |
---|
756 | |
---|
757 | Param Joint::extraProperties() |
---|
758 | { |
---|
759 | return Param(f0_joint_xtra_paramtab, this); |
---|
760 | } |
---|
761 | |
---|
762 | Param Neuro::extraProperties() |
---|
763 | { |
---|
764 | return Param(f0_neuro_xtra_paramtab, this); |
---|
765 | } |
---|
766 | |
---|
767 | Param Part::properties() |
---|
768 | { |
---|
769 | return Param(f0_part_paramtab, this); |
---|
770 | } |
---|
771 | |
---|
772 | Param Joint::properties() |
---|
773 | { |
---|
774 | return Param(usedelta ? f0_joint_paramtab : f0_nodeltajoint_paramtab, this); |
---|
775 | } |
---|
776 | |
---|
777 | Param Neuro::properties() |
---|
778 | { |
---|
779 | return Param(f0_neuro_paramtab, this); |
---|
780 | } |
---|
781 | |
---|
782 | class NeuroExtParamTab : public ParamTab |
---|
783 | { |
---|
784 | public: |
---|
785 | NeuroExtParamTab() :ParamTab(f0_neuro_paramtab) |
---|
786 | { |
---|
787 | #define FIELDSTRUCT NeuroExt |
---|
788 | ParamEntry entries[] = { |
---|
789 | { "class", 2, 0, "neuro class", "s", GETSET(neuroclass) }, |
---|
790 | { "liveNeuro", 2, 1, "live Neuro object", "oNeuro", GETONLY(liveNeuro) } }; |
---|
791 | #undef FIELDSTRUCT |
---|
792 | for (auto& e : entries) add(&e); |
---|
793 | |
---|
794 | #define FIELDSTRUCT Neuro |
---|
795 | ParamEntry entry2 = { "state", 2, 0, "state", "f", FIELD(state) }; |
---|
796 | #undef FIELDSTRUCT |
---|
797 | add(&entry2); |
---|
798 | } |
---|
799 | }; |
---|
800 | |
---|
801 | Param &Neuro::getStaticParam() |
---|
802 | { |
---|
803 | static Param p(f0_neuro_paramtab, 0, "NeuroDef"); |
---|
804 | return p; |
---|
805 | } |
---|
806 | |
---|
807 | //////////////////////// |
---|
808 | |
---|
809 | NeuroConn::NeuroConn() |
---|
810 | { |
---|
811 | defassign(); |
---|
812 | } |
---|
813 | |
---|
814 | ////////////////////////////////////// |
---|
815 | |
---|
816 | ParamEntry *NeuroExt::getParamTab() |
---|
817 | { |
---|
818 | static NeuroExtParamTab tab; |
---|
819 | return tab.getParamTab(); |
---|
820 | } |
---|
821 | |
---|
822 | void NeuroExt::get_neuroclass(PARAMGETARGS) |
---|
823 | { |
---|
824 | ret->setString(getClassName()); |
---|
825 | } |
---|
826 | |
---|
827 | int NeuroExt::set_neuroclass(PARAMSETARGS) |
---|
828 | { |
---|
829 | setClassName(arg->getString()); return PSET_CHANGED; |
---|
830 | } |
---|
831 | |
---|
832 | void NeuroExt::get_liveNeuro(PARAMGETARGS) |
---|
833 | { |
---|
834 | #ifndef SDK_WITHOUT_FRAMS |
---|
835 | NeuroNetImpl::getLiveNeuroObject(this, ret); |
---|
836 | #endif |
---|
837 | } |
---|