source: java/main/src/main/java/com/framsticks/model/F0Model.java @ 78

Last change on this file since 78 was 78, checked in by psniegowski, 11 years ago

Add f0 parsing and f0->Model transformation.

File size: 1.8 KB
Line 
1package com.framsticks.model;
2
3import com.framsticks.params.FramsClass;
4import com.framsticks.util.Orientation;
5
6import java.util.ArrayList;
7import java.util.List;
8
9/**
10 * Author: Piotr Śniegowski
11 */
12public class F0Model {
13
14        public final List<MechPart> mechparts = new ArrayList<MechPart>();
15        public final List<MechJoint> mechjoints = new ArrayList<MechJoint>();
16        public final List<Neuro> neurons = new ArrayList<Neuro>();
17
18        public final List<MechPart> getMechParts() { return mechparts; }
19        public final List<MechJoint> getMechJoints() { return mechjoints; }
20        public final List<Neuro> getNeurons() { return neurons; }
21
22        public static void constructFramsClass(FramsClass.Constructor constructor) {
23                constructor.field("mechparts");
24                constructor.field("mechjoints");
25                constructor.field("neurons");
26        }
27
28        public static F0Model build(F0Genotype f0Genotype) {
29                F0Model model = new F0Model();
30
31                for (Part p : f0Genotype.getParts()) {
32                        /** based on c++ Model::build*/
33                        MechPart mp = new MechPart();
34                        mp.setPosition(p.getPosition());
35                        mp.setOrientation(new Orientation().rotate(p.getRotation()));
36                        mp.copyFrom(p);
37                        model.mechparts.add(mp);
38                }
39                for (Joint j : f0Genotype.getJoints()) {
40                        /** based on c++ Joint::attachToParts*/
41                        MechPart mp1 = model.mechparts.get(j.getP1());
42                        MechPart mp2 = model.mechparts.get(j.getP2());
43                        assert mp1 != null && mp2 != null;
44                        MechJoint mj = new MechJoint();
45                        mj.copyFrom(j);
46                        Orientation o = new Orientation().rotate(j.getRotation());
47                        mp2.setOrientation(mp1.getOrientation().transform(o));
48                        mp2.setPosition(mp2.getOrientation().transform(j.getDelta()).add(mp1.getPosition()));
49                        model.mechjoints.add(mj);
50                }
51                for (NeuroDef nd : f0Genotype.getNeuroDefs()) {
52                        Neuro n = new Neuro();
53                        n.copyFrom(nd);
54                        model.neurons.add(n);
55                }
56
57                return model;
58        }
59}
Note: See TracBrowser for help on using the repository browser.