Author Topic: dummy  (Read 4102 times)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
dummy
« on: August 05, 2011, 07:25:03 pm »
Hi Egon, I have problem with dummy. I need add dummy to another dummy, but when I do this, object (from code) is not visible. Any idea?

Code: [Select]
for (int i = 0; i < moveMergeIds.size(); i += 2) { // sjednoceni pohybu definovanych objektu (f -> s)
int idf = moveMergeIds.get(i);
int ids = moveMergeIds.get(i + 1);
Object3D object = objectManager.getObject(idf).getDummy();
Object3D dummy = objectManager.getObject(ids).getDummy();
dummy.addChild(object);
}

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: dummy
« Reply #1 on: August 05, 2011, 08:32:54 pm »
dummy -> dummy...object from code...i don't get it...what's the actual problem?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: dummy
« Reply #2 on: August 05, 2011, 08:42:33 pm »
all children of dummy (in code it is variable "object") are not visible, when I use this part of code

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: dummy
« Reply #3 on: August 05, 2011, 09:11:53 pm »
So...you have (non-dummy) objects that are children of dummy and if you add another dummy as child of dummy, those objects suddenly disappear?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: dummy
« Reply #4 on: August 05, 2011, 09:24:41 pm »
both Object3D are dummy objects created by static method createDummyObj()...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: dummy
« Reply #5 on: August 05, 2011, 09:26:01 pm »
Yes, i know...but that doesn't answer my question...

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: dummy
« Reply #6 on: August 05, 2011, 09:30:03 pm »
answer is exactly :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: dummy
« Reply #7 on: August 05, 2011, 09:34:17 pm »
Maybe you are getting an error because Config.maxParentObjects is exceeded?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: dummy
« Reply #8 on: August 05, 2011, 09:44:28 pm »
I set a higher number, but it is still same

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: dummy
« Reply #9 on: August 05, 2011, 09:46:40 pm »
Makes no sense to me. Test case?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: dummy
« Reply #10 on: August 05, 2011, 10:36:14 pm »
Now I have found that objects are on another positions that I want.

Code: [Select]
package cz.test.point_light;

import java.lang.reflect.Field;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.res.Resources;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;

import com.threed.jpct.Camera;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.GLSLShader;
import com.threed.jpct.Light;
import com.threed.jpct.Loader;
import com.threed.jpct.Logger;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.RGBColor;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;
import com.threed.jpct.util.AAConfigChooser;
import com.threed.jpct.util.BitmapHelper;
import com.threed.jpct.util.MemoryHelper;

/**
 * @author EgonOlsen
 *
 */
public class Point_light_testActivity extends Activity {

private static Point_light_testActivity master = null;

private GLSurfaceView mGLView;
private MyRenderer renderer = null;
private FrameBuffer fb = null;
private World world = null;
private RGBColor back = new RGBColor(50, 50, 100);

private float touchTurn = 0;
private float touchTurnUp = 0;

private float xpos = -1;
private float ypos = -1;

private Object3D cube0 = null;
private Object3D cube1 = null;
private Object3D cube2 = null;
private Object3D cube3 = null;
private Object3D dummy = null;

private int fps = 0;

private Light light;

protected void onCreate(Bundle savedInstanceState) {

Logger.log("onCreate");

if (master != null) {
copy(master);
}

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
mGLView = new GLSurfaceView(getApplication());

super.onCreate(savedInstanceState);
mGLView = new GLSurfaceView(getApplication());

mGLView.setEGLContextClientVersion(2);
mGLView.setEGLConfigChooser(new AAConfigChooser(mGLView));

renderer = new MyRenderer();
mGLView.setRenderer(renderer);
setContentView(mGLView);
}

@Override
protected void onPause() {
super.onPause();
mGLView.onPause();
}

@Override
protected void onResume() {
super.onResume();
mGLView.onResume();
}

protected void onStop() {
super.onStop();
}

private void copy(Object src) {
try {
Logger.log("Copying data from master Activity!");
Field[] fs = src.getClass().getDeclaredFields();
for (Field f : fs) {
f.setAccessible(true);
f.set(this, f.get(src));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public boolean onTouchEvent(MotionEvent me) {

if (me.getAction() == MotionEvent.ACTION_DOWN) {
xpos = me.getX();
ypos = me.getY();
return true;
}

if (me.getAction() == MotionEvent.ACTION_UP) {
xpos = -1;
ypos = -1;
touchTurn = 0;
touchTurnUp = 0;
return true;
}

if (me.getAction() == MotionEvent.ACTION_MOVE) {
float xd = me.getX() - xpos;
float yd = me.getY() - ypos;

xpos = me.getX();
ypos = me.getY();

touchTurn = xd / -100f;
touchTurnUp = yd / -100f;
return true;
}

try {
Thread.sleep(15);
} catch (Exception e) {
// No need for this...
}

return super.onTouchEvent(me);
}

protected boolean isFullscreenOpaque() {
return true;
}

class MyRenderer implements GLSurfaceView.Renderer {

private long time = System.currentTimeMillis();
private boolean stop = false;

public MyRenderer() {
}

public void stop() {
stop = true;
}

public void onSurfaceChanged(GL10 gl, int w, int h) {
if (fb != null) {
fb.dispose();
}
fb = new FrameBuffer(w, h);

if (master == null) {

world = new World();
world.setAmbientLight(0, 0, 0);

Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.icon)), 64,
64));
TextureManager.getInstance().addTexture("texture", texture);

dummy = Object3D.createDummyObj();

cube0 = Primitives.getCube(10);
cube0.rotateY(-(float) Math.PI / 4f);
cube0.rotateMesh();
cube0.clearRotation();
cube0.calcTextureWrapSpherical();
cube0.setTexture("texture");
cube0.strip();
cube0.build();

cube1 = cube0.cloneObject();
cube2 = cube0.cloneObject();
cube3 = cube0.cloneObject();

world.addObject(cube0);
world.addObject(cube1);
/*world.addObject(cube2);
world.addObject(cube3);*/

/*cube0.translate(-20, -20, 0);
cube1.translate(20, -20, 0);
cube2.translate(-20, 20, 0);
cube3.translate(20, 20, 0);*/

Object3D dummy2 = Object3D.createDummyObj();
cube0.addParent(dummy2);
dummy2.translate(-30, 0, 0);
cube1.addParent(dummy);
dummy.translate(30, 0, 0);
dummy.addChild(dummy2);

// is it same?
//cube0.translate(-30, 0, 0);
//cube1.translate(30, 0, 0);

Object3D plane = Primitives.getPlane(40, 3);
plane.translate(0, 0, 10);
plane.build();
world.addObject(plane);

Resources res = getResources();

light = new Light(world);
light.setPosition(new SimpleVector(20, 0, -20));

light.setIntensity(255, 255, 255);

Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 100);

MemoryHelper.compact();

if (master == null) {
Logger.log("Saving master Activity!");
master = Point_light_testActivity.this;
}

// Logger.setLogLevel(Logger.DEBUG);
}
}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
}

public void onDrawFrame(GL10 gl) {

try {
if (!stop) {
if (touchTurn != 0) {
dummy.rotateY(touchTurn);
touchTurn = 0;
}

if (touchTurnUp != 0) {
dummy.rotateX(touchTurnUp);
touchTurnUp = 0;
}

light.rotate(new SimpleVector(0, 0, 0.01), new SimpleVector());

fb.clear(back);
world.renderScene(fb);
world.draw(fb);
fb.display();

if (System.currentTimeMillis() - time >= 1000) {
Logger.log(fps + "fps");
fps = 0;
time = System.currentTimeMillis();
}
fps++;
} else {
if (fb != null) {
fb.dispose();
fb = null;
}
}
} catch (Exception e) {
Logger.log(e, Logger.MESSAGE);
}
}
}
}
« Last Edit: August 05, 2011, 10:38:28 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: dummy
« Reply #11 on: August 05, 2011, 11:07:32 pm »
Thanks for the test case. Behaviour is perfectly fine. Maybe it's clearer if you change

Code: [Select]
dummy.addChild(dummy2);
to

Code: [Select]
dummy2.addParent(dummy);
which is the same thing, just with reversed thinking. So dummy becomes a parent of dummy2, meaning that any object that has dummy2 as parent also inherits the transformations of dummy, i.e. -30+30=0

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: dummy
« Reply #12 on: August 06, 2011, 11:46:44 am »
without any changes...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: dummy
« Reply #13 on: August 06, 2011, 12:16:57 pm »
No idea what you mean... ???

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: dummy
« Reply #14 on: August 06, 2011, 12:39:44 pm »
I do not know why object has bad position... first object is translated by first dummy, second object by second dummy and set that second will also translate with first in future...