⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objectgridportrayal3d.java

📁 MASON代表多主体邻里或网络仿真(Multi-Agent Simulator of Neighborhoods or Networks)。它是乔治梅森大学用Java开发的离散事件多主体仿真核心库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        Bag b = (Bag)(models.get(o));                        if (b!=null && b.numObjs > 0)                            {                            // yay, we can reuse an existing model                            BranchGroup replacementBranchGroup = (BranchGroup)(b.remove(0));                            originalTransformGroup = (TransformGroup)(replacementBranchGroup.getChild(0));                            newTransformGroup = p3d.getModel(o,originalTransformGroup);                            if (newTransformGroup == originalTransformGroup)  // we can stick the BranchGroup in                                global.setChild(replacementBranchGroup,count-1);                            }                        else                             // shoot, we have to create a new model.  Rebuild.                            newTransformGroup = p3d.getModel(o, null);                        }                                                                    // is the new transformGroup different?                    if (newTransformGroup != originalTransformGroup)                        {                        // dang!                        newTransformGroup.setCapability(TransformGroup.ALLOW_CHILDREN_READ);                        newTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);                        newTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);                        // this is set so he'll be in the scenegraph path                        newTransformGroup.setCapability(TransformGroup.ENABLE_PICK_REPORTING);                                                                        BranchGroup bg2 = new BranchGroup();                        bg2.setCapability(BranchGroup.ALLOW_CHILDREN_READ);                        bg2.setCapability(BranchGroup.ALLOW_DETACH);                        // this is set so he'll be in the scenegraph path                        bg2.setCapability(BranchGroup.ENABLE_PICK_REPORTING);                        tmpLocalT.setTranslation(new Vector3d(x,y,0));                        newTransformGroup.setTransform(tmpLocalT);                        newTransformGroup.setUserData(new Int2D(x,y));                        bg2.addChild(newTransformGroup);                        bg2.setUserData(o);                        global.setChild(bg2,count-1);                        // add old BranchGroup to the hashmap                        Bag b = (Bag)(models.get(originalData));                        if (b==null) { b = new Bag(); models.put(originalData,b); }                        b.add(bg);                        }                    }                }            }        else // field instanceof ObjectGrid3D            {            Object[][][] grid = ((ObjectGrid3D)field).field;            for(int x=0;x<grid.length;x++)                {                Object[][] gridx = grid[x];                for(int y=0;y<gridx.length;y++)                    {                    Object[] gridy = gridx[y];                    for(int z=0;z<gridy.length;z++)                        {                        Object o = gridy[z];                        // get the child model -- it doesn't exist yet                        Portrayal p = getPortrayalForObject(o);                        if(! (p instanceof SimplePortrayal3D))                            throw new RuntimeException("Unexpected Portrayal " + p + " for object " +                                                        o + " -- expecting a SimplePortrayal3D");                        SimplePortrayal3D p3d = (SimplePortrayal3D)p;                        p3d.setParentPortrayal(this);                        BranchGroup bg = (BranchGroup)(global.getChild(count++));                        TransformGroup originalTransformGroup = null;                        if (bg.numChildren() > 0) originalTransformGroup = (TransformGroup)(bg.getChild(0));  // could be null if we've stubbed                        TransformGroup newTransformGroup = null;                        Object originalData = bg.getUserData();                        if (originalData == o)                            newTransformGroup = p3d.getModel(o, originalTransformGroup);                        else                            {                            Bag b = (Bag)(models.get(o));                            if (b!=null && b.numObjs > 0)                                {                                // yay, we can reuse an existing model                                BranchGroup replacementBranchGroup = (BranchGroup)(b.remove(0));                                originalTransformGroup = (TransformGroup)(replacementBranchGroup.getChild(0));                                newTransformGroup = p3d.getModel(o,originalTransformGroup);                                if (newTransformGroup == originalTransformGroup)  // we can stick the BranchGroup in                                    global.setChild(replacementBranchGroup,count-1);                                }                            else                                // shoot, we have to create a new model.  Rebuild.                                newTransformGroup = p3d.getModel(o, null);                            }                                                                        // is the new transformGroup different?                        if (newTransformGroup != originalTransformGroup)                            {                            // dang!                            newTransformGroup.setCapability(TransformGroup.ALLOW_CHILDREN_READ);                            newTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);                            newTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);                            // this is set so he'll be in the scenegraph path                            newTransformGroup.setCapability(TransformGroup.ENABLE_PICK_REPORTING);                                                                                    BranchGroup bg2 = new BranchGroup();                            bg2.setCapability(BranchGroup.ALLOW_CHILDREN_READ);                            bg2.setCapability(BranchGroup.ALLOW_DETACH);                            // this is set so he'll be in the scenegraph path                            bg2.setCapability(BranchGroup.ENABLE_PICK_REPORTING);                            tmpLocalT.setTranslation(new Vector3d(x,y,z));                            newTransformGroup.setTransform(tmpLocalT);                            newTransformGroup.setUserData(new Int3D(x,y,z));                            bg2.addChild(newTransformGroup);                            bg2.setUserData(o);                            global.setChild(bg2,count-1);                            // add old BranchGroup to the hashmap                            Bag b = (Bag)(models.get(originalData));                            if (b==null) { b = new Bag(); models.put(originalData,b); }                            b.add(bg);                            }                        }                    }                }            }        }    public void setField(Object field)        {        dirtyField = true;        if (field instanceof ObjectGrid3D || field instanceof ObjectGrid2D) this.field = field;        else throw new RuntimeException("Invalid field for ObjectGridPortrayal3D: " + field);        }                            public LocationWrapper completedWrapper(LocationWrapper w, PickIntersection pi, PickResult pr)             {        // find the global transform group.        SceneGraphPath path = pr.getSceneGraphPath();        int len = path.nodeCount();        boolean found = false;        int i=0;        for(i=0;i<len;i++)            {            Node node = path.getNode(i);            Object userdata = path.getNode(i).getUserData();            if (userdata == this && node instanceof Group)                {                found = true; break;                  }            }        if (!found) throw new RuntimeException(            "Internal error: ObjectGridPortrayal3D.completedWrapper() couldn't find the root transform group.  This shouldn't happen.");                Object location = path.getNode(i+2).getUserData();  // back off to the TransformGroup                return new LocationWrapper(null, location, this)            {            public Object getObject()                {                 if (this.location instanceof Int3D)                    {                    Int3D loc = (Int3D)this.location;                    return ((ObjectGrid3D)field).field[loc.x][loc.y][loc.z];                    }                else                    {                    Int2D loc = (Int2D)this.location;                    return ((ObjectGrid2D)field).field[loc.x][loc.y];                    }                }                        public String getLocationName()                {                if (this.location instanceof Int3D)                    return ((Int3D)this.location).toCoordinates();                else return ((Int2D)this.location).toCoordinates();                }            };        }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -