Author Topic: is result of setboundingbox permanent?  (Read 5707 times)

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: is result of setboundingbox permanent?
« Reply #15 on: June 13, 2017, 07:22:34 am »
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.

Code: [Select]
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(); } }

}


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: is result of setboundingbox permanent?
« Reply #16 on: June 13, 2017, 07:56:58 am »
Thanks, I'll look into it.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: is result of setboundingbox permanent?
« Reply #17 on: June 13, 2017, 09:29:03 pm »
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

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: is result of setboundingbox permanent?
« Reply #18 on: June 14, 2017, 05:22:50 am »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: is result of setboundingbox permanent?
« Reply #19 on: June 14, 2017, 08:57:13 pm »
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.