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