Ok, rotation works.
Thanks for help now I can end my work ;p
I was left with only describe all the work , that is the worst part
Thanks for help now I can end my work ;p
I was left with only describe all the work , that is the worst part
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menupublic class ImageTargetsRenderer implements GLSurfaceView.Renderer
{
public boolean mIsActive = false;
/** Reference to main activity **/
public ImageTargets mActivity;
private FrameBuffer fb;
private World world;
private float[] modelViewMat;
private Light sun;
private Object3D cube;
private Camera cam;
private float fov;
private float fovy;
/* Rotation values */
private float xrot; //X Rotation
private float yrot; //Y Rotation
/* Rotation speed values */
private float xspeed; //X Rotation Speed ( NEW )
private float yspeed; //Y Rotation Speed ( NEW )
private float scale = 5.0f;
private float oldX;
private float oldY;
private final float TOUCH_SCALE = 0.4f; //Proved to be good for normal rotation ( NEW )
private int z;
/** Native function for initializing the renderer. */
public native void initRendering();
/** Native function to update the renderer. */
public native void updateRendering(int width, int height);
public ImageTargetsRenderer(ImageTargets activity) throws IOException {
this.mActivity = activity;
world = new World();
world.setAmbientLight(20, 20, 20);
sun = new Light(world);
sun.setIntensity(250, 250, 250);
InputStream objStream = new FileInputStream("/mnt/sdcard/models/armchair.obj");
InputStream mtlStream = new FileInputStream("/mnt/sdcard/models/armchair.mtl");
Object3D[] model = Loader.loadOBJ(objStream, mtlStream, scale);
Object3D o3d = new Object3D(0);
Object3D temp = null;
for (int i = 0; i < model.length; i++) {
temp = model[i];
temp.setCenter(SimpleVector.ORIGIN);
temp.rotateMesh();
temp.setRotationMatrix(new Matrix());
o3d = Object3D.mergeObjects(o3d, temp);
o3d.build();
}
o3d.rotateX(xrot);
o3d.rotateY(yrot);
o3d.rotateZ(z);
world.addObject(o3d);
cam = world.getCamera();
SimpleVector sv = new SimpleVector();
sv.set(o3d.getTransformedCenter());
sv.y -= 100;
sv.z -= 100;
sun.setPosition(sv);
MemoryHelper.compact();
}
public boolean onTouchEvent(MotionEvent event) {
//
float x = event.getX();
float y = event.getY();
//If a touch is moved on the screen
if(event.getAction() == MotionEvent.ACTION_MOVE) {
//Calculate the change
float dx = x - oldX;
float dy = y - oldY;
//Define an upper area of 13% on the screen
int upperArea = fb.getHeight() / 13;
//Zoom in/out if the touch move has been made in the upper
if(y < upperArea) {
scale -= dx * TOUCH_SCALE / 2;
//Rotate around the axis otherwise
} else {
xrot += dy * TOUCH_SCALE;
yrot += dx * TOUCH_SCALE;
}
//A press on the screen
} else if(event.getAction() == MotionEvent.ACTION_UP) {
}
//Remember the values
oldX = x;
oldY = y;
//We handled the event
return true;
}
public boolean onKeyUp(int keyCode, KeyEvent event) {
//
if(keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
} else if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
} else if(keyCode == KeyEvent.KEYCODE_DPAD_UP) {
z -= 3;
} else if(keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
z += 3;
} else if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
}
//We handled the event
return true;
}
/** Called when the surface is created or recreated. */
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
DebugLog.LOGD("GLRenderer::onSurfaceCreated");
// Call native function to initialize rendering:
initRendering();
// Call Vuforia function to (re)initialize rendering after first use
// or after OpenGL ES context was lost (e.g. after onPause/onResume):
QCAR.onSurfaceCreated();
}
/** Called when the surface changed size. */
public void onSurfaceChanged(GL10 gl, int width, int height)
{
DebugLog.LOGD(String.format("GLRenderer::onSurfaceChanged (%d, %d)", width, height));
if (fb != null) {
fb.dispose();
}
fb = new FrameBuffer(width, height);
Config.viewportOffsetAffectsRenderTarget=true;
// Call native function to update rendering when render surface
// parameters have changed:
updateRendering(width, height);
// Call Vuforia function to handle render surface size changes:
QCAR.onSurfaceChanged(width, height);
}
/** The native render function. */
public native void renderFrame();
/** Called to draw the current frame. */
public void onDrawFrame(GL10 gl)
{
if (!mIsActive)
return;
// Update render view (projection matrix and viewport) if needed:
mActivity.updateRenderView();
// Call our native function to render content
renderFrame();
updateCamera();
world.renderScene(fb);
world.draw(fb);
fb.display();
}
public void updateModelviewMatrix(float mat[]) {
modelViewMat = mat;
}
public void updateCamera() {
if (modelViewMat != null) {
Matrix m = new Matrix();
m.setDump(modelViewMat);
cam.setBack(m);
cam.setFOV(fov);
cam.setYFOV(fovy);
}
}
public void setVideoSize(int videoWidth, int videoHeight) {
DisplayMetrics displaymetrics = new DisplayMetrics();
mActivity.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
int widestVideo = videoWidth > videoHeight? videoWidth: videoHeight;
int widestScreen = width > height? width: height;
float diff = (widestVideo - widestScreen) / 2;
Config.viewportOffsetY = diff / widestScreen;
}
public void setFov(float fov) {
this.fov = fov;
}
public void setFovy(float fovy) {
this.fovy = fovy;
}
}
Page created in 0.031 seconds with 12 queries.