1. Orthogonal projection coordinate system 만들기 ¶
public void onSurfaceChanged(GL10 gl, int width, int height) { this.m_width = width; this.m_height = height; if(buffer == null) { Util.LOGD("make framebuffer"); world = new World(); m_cam = world.getCamera(); // light mass world.setAmbientLight(0xff, 0xff, 0xff); // making background plane float[] coordinates = { // position of vertices 0.0f, 0.0f, 0.0f, m_width, 0.0f, 0.0f, 0.0f, m_height, 0.0f, m_width, m_height, 0.0f }; float[] uvs = { // how uv mapped? 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f }; int[] indices = { // index of each coordinate 0, 2, 1, 1, 2, 3 }; // make plane Object3D plane = new Object3D(coordinates, uvs, indices, RMObject2D.getTextureIDByColor(Color.white)); plane.build(); Util.LOGD("center: " + plane.getTransformedCenter()); world.addObject(plane); // FOV settings m_cam.setFOVLimits(0.1f, 2.0f); m_cam.setFOV(0.1f); // set up camera // z = (width/2) / tan(fov/2) m_cam.setPosition(m_width/2, m_height/2, (float) -(m_width/2/Math.tan(m_cam.getFOV()/2.0f))); m_cam.lookAt(plane.getTransformedCenter()); fixCubePosition(); // configuration to view far object Config.farPlane = Math.abs(m_cam.getPosition().z) + 1000f; } // make framebuffer if(buffer != null) buffer.dispose(); buffer = new FrameBuffer(m_width, m_height, FrameBuffer.SAMPLINGMODE_NORMAL); }
2. FillBox class ¶
package cau.rpg.maker.object; import java.awt.Color; import javax.vecmath.Vector2f; import com.threed.jpct.Object3D; public class RMFillBox extends RMObject2D { public RMFillBox(float x1, float y1, float x2, float y2, Color color) { init(x1, y1, x2, y2, color); } public RMFillBox(Vector2f vStart, Vector2f vEnd, Color color) { init(vStart.x, vStart.y, vEnd.x, vEnd.y, color); } private void init(float x1, float y1, float x2, float y2, Color color) { if(x1 >= x2 || y1 >= y2) return; float z = -10f; float[] coords = { x1, y1, z, // up left x1, y2, z, // bottom left x2, y1, z, // up right x2, y2, z // bottom right corner }; float[] uvs = { 0f, 0f, 0f, 1f, 1f, 0f, 1f, 1f }; int[] indices = { 0, 1, 2, 2, 1, 3 }; m_polygon = new Object3D(coords, uvs, indices, getTextureIDByColor(color)); } }
3. 2D line class ¶
package cau.rpg.maker.object; import java.awt.Color; import javax.vecmath.Vector2f; import javax.vecmath.Vector3f; import com.threed.jpct.Object3D; public class RMLine extends RMObject2D { private static final Vector3f vectorZ = new Vector3f(0, 0, -1); public RMLine(Vector2f vStart, Vector2f vEnd, float width, Color color) { float z = -10f; Vector3f v3Start = new Vector3f(vStart.x, vStart.y, z); Vector3f v3End = new Vector3f(vEnd.x, vEnd.y, z); // line vector Vector3f lineVector = new Vector3f(); lineVector.sub(v3End, v3Start); // calc normal vector of line Vector3f normal = new Vector3f(); normal.cross(lineVector, vectorZ); normal.normalize(); normal.scale(width/2.0f); float[] coords = { (vStart.x + normal.x), (vStart.y + normal.y), z, (vStart.x - normal.x), (vStart.y - normal.y), z, (vEnd.x + normal.x), (vEnd.y + normal.y), z, (vEnd.x - normal.x), (vEnd.y - normal.y), z }; float[] uvs = { 0f, 0f, 0f, 1f, 1f, 0f, 1f, 1f }; int[] indices = { 0, 2, 1, 1, 2, 3 }; m_polygon = new Object3D(coords, uvs, indices, getTextureIDByColor(color)); } }
4. Interpolation ¶
public void setDepth(float depth) { float delta = depth - this.depth; // move object SimpleVector curPosition = m_polygon.getTransformedCenter(); SimpleVector toCam = MainRenderer.getCamera().getPosition().calcSub(curPosition); float a = MainRenderer.getCamera().getPosition().z - this.depth; toCam.scalarMul(delta/a); m_polygon.translate(toCam); Util.LOGD("translate to " + toCam); // scale m_polygon.scale((a-delta)/a); this.depth = depth; }
6. Actors.rvdata Parser: advanced(위 parser 코드와 이어짐) ¶
public void parse2(InputStream is) throws IOException
{
is.skip(3);
int numChar = is.read()-6;
Util.LOGD("캐릭터 수: " + numChar);
int data;
byte[] buf;
while((data = is.read()) != -1) {
// RPG::Actor(시그니쳐) 찾은 경우
if(finder_actor[0].addChar((byte) data)) {
// 입력받을 클래스 변수 수
int numArgs = get_int(is.read());
// 변수 순서가 저장될 행렬
String result = null;
List<String> argList = new ArrayList<String>();
// 첫번째 캐릭터
for(int i=0; i<numArgs; i++) {
for(;is.read() != 0x3a;); // 다음 구분자까지 읽는다
// 이름 길이
int elementNameLen = get_int(is.read());
buf = new byte[elementNameLen];
// 변수 이름 입력
is.read(buf);
result = new String(buf);
// 변수에 들일 값 읽기
String value = getValue(is);
Util.LOGD("발견!" + result + " value: " + value);
argList.add(result);
// 테이블은 있으면 개수에 포함하지 않는다
if(value.equals("u"))
i--;
}
// 그 이후 캐릭터들
for(int i=0; i<numChar-1; i++) {
Util.LOGD((i+2) + "번째 캐릭터 시작");
for(;is.read() != 0x3b;); // 시작 시그니쳐 건너뜀
for(int j=0; j<numArgs; j++) {
for(;is.read() != 0x3b;); // 다음 구분자까지
// 변수 순서
int index = get_int(is.read());
String value = getValue(is);
// 변수값 읽기
Util.LOGD("발견!" + argList.get(index-1) + " value: " + value);
// 테이블은 있으면 개수에 포함하지 않는다
if(value.equals("u"))
j--;
}
}
}
}
}
private String getValue(InputStream is) throws IOException
{
byte type = (byte) is.read();
String result = null;
switch(type) {
case 0x02: // table
result = "table start";
read_table(is);
break;
case '"': //str
int len = get_int(is.read());
if(len < 0)
len = readShort(is);
byte[] str = new byte[len];
is.read(str);
result = new String(str);
break;
case 'i': // int
int value = get_int(is.read());
result = String.valueOf(value);
break;
case 'T':
case 'F':
result = String.valueOf(type == 'T');
break;
case 'u':
result = "u";
}
return result;
}










