📄 world.java
字号:
/* * J3DME Fast 3D software rendering for small devices * Copyright (C) 2001 Onno Hommes * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package net.jscience.j3dme;/** * Objects of this class represent a virtual world. The virtual world * can hold one or more models. Models are 3D objects that have a defined * geometry and a location in this virtual world. * @see Model */public class World{ public static final int ONE = 256; private Model[] models; private int empty = 0; private int next = 0; /** * Return a virtual world.<p> * Return a virtual world that can hold the number of specified models * The number of models cannot be changed during the life of the world. * * @param numberOfModels The maximum number of models this world can host * @return The virtual world. */ public World(int numberOfModels){ models = new Model[numberOfModels]; } /** * Add a model to the virtual world<p> * The supplied model will be added to the virtual world and a model * index will be returned. If you receive a model index of -1 then the * world cannot host the model because it has reached its maximum capacity. * * @param model The model to add to the world * @return The world index to the model or -1 if full. */ public int addModel(Model model){ if (empty==models.length) return -1; models[empty] = model; empty++; return empty-1; } /** * Remove the model from the world<p> * * @param model The model to remove. */ public void removeModel(Model model){ removeModel(getModelIndex(model)); } /** * Remove a model by index<p> * The supplied index will be used to remove a model from the world. * * @param index The index to the model */ public void removeModel(int index){ if (index >= 0 && index < empty){ while (index < empty){ models[index]=models[index+1]; index++; } empty--; } } /** * Return the model located at the index<p> * This method does not check for incorrect indices. Indices * larger then the worlds capacity minus one or negative indices will * surely give you some expected array Execptions. * * @param index The index to the model to be retrieved * @return The model at the supplied index */ public Model getModel(int index){ return models[index]; } /** * Return the current number of models in the world<p> * * @return the number of models in the world. */ public int getNumberOfModels(){ return empty; } /** * Return the model index for the specified model<p> * Return the index in the world to the supplied model. */ public int getModelIndex(Model model){ int index = -1; for (int i=0;i<models.length;i++){ if (models[i] == model) { index = i; break; } } return index; } public int getMaximumModels(){ return(models.length); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -