is result of setboundingbox permanent?

Started by MichaelJPCT, June 05, 2017, 07:31:54 AM

Previous topic - Next topic

MichaelJPCT

see below. in the sample, you can see a triangle suddenly disappears when fov changes, while it shouldn't.
i found if the shape is created by Primitives.getBox, setBoundingBox works correctly.


import com.threed.jpct.*;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.app.Activity;

public class Sim extends Activity {
static GLSurfaceView GLview;
static MyRenderer rend;
static FrameBuffer frmBuf;
static World world=new World();
static Camera cam=world.getCamera();
static float fov=1f;
static Object3D shape;
static String glslV="uniform mat4 modelViewProjectionMatrix;"+
"attribute vec4 position; void main(){ vec4 p=position;"+
"p.y*=2.0; gl_Position=modelViewProjectionMatrix*p; }";
static String glslF="void main(){gl_FragColor=vec4(1,1,1,1);}";
static GLSLShader glsl=new GLSLShader(glslV,glslF);

protected void onCreate(Bundle a) {
super.onCreate(a);
rend=new MyRenderer();
GLview=new GLSurfaceView(getApplication());
GLview.setEGLContextClientVersion(2);
GLview.setRenderer(rend);
setContentView(GLview); }

class MyRenderer implements GLSurfaceView.Renderer {
public void onSurfaceCreated(GL10 g,EGLConfig c) {
shape=new Object3D(new float[]{5,0,0,0,-5,0,-5,0,0},null,new int[]{0,1,2},-1);
shape.build();
shape.setBoundingBox(-100,100,-100,100,-100,100);
world.addObject(shape);
shape.translate(0,15,50);
world.setGlobalShader(glsl);
cam.setFOVLimits(0.001f,1); }
public void onSurfaceChanged(GL10 g,int w,int h) {
if (frmBuf!=null) frmBuf.dispose(); frmBuf=new FrameBuffer(w,h); }
public void onDrawFrame(GL10 g) {
frmBuf.clear();
fov-=0.002;
if (fov<0.1) fov=1f;
cam.setFOV(fov);
world.renderScene(frmBuf);
world.draw(frmBuf);
frmBuf.display(); } }

}



EgonOlsen


EgonOlsen

Now that was a funny one...For single polygon objects, the engine applied an optimization for the bounding box culling, so that it actually used the polygon for culling, not the box (less work to do that way). That has been added to speed up particle effects on slower devices, but it obviously couldn't handle your special case. This version should fix the problem: http://jpct.de/download/beta/jpct_ae.jar

MichaelJPCT

in my actual app, the shape is a quad -- 2 triangles, same problem.
do you mean the new version would slow down particle rendering? if so , i would prefer the old version. there is other way to solve the culling problem - make the shape larger and modify the shader.
since you don't keep branches of the engine, i like the one with faster performance. you just need to tell (in javadoc) people why setBoundingBox doesn't work in some case.

EgonOlsen

The optimization applies to quads as well. It's still in there, just not used anymore in all cases. I don't think it will impact performance in any way noticable.