Show Posts

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.


Messages - gamerfan

Pages: 1 ... 4 5 [6] 7
76
Support / Re: Displaying multiple boxes
« on: September 09, 2011, 12:55:21 pm »
how can I make a polygon ?

77
Support / Re: Displaying multiple boxes
« on: September 09, 2011, 07:14:06 am »
I do not have that much idea about it.However, I just tried that way and a I said earlier, it got working. :)  So I thought of continuing that way,but not able to figure out the issues.How it can be improved according to you?

I searched some examples in the net to build a wall using this API and found some solutions.However, that too has some some little implementational issues.These are the links.
Code: [Select]
          http://stackoverflow.com/questions/6003828/stretch-2d-plane-to-3d-cube
          http://i.stack.imgur.com/en1UL.png
          http://i.stack.imgur.com/s8hyX.png
And in my case, this(above links) also did not work the way expected.So I adopted the earlier one .Please share with me if you have better solutions.

78
Support / Displaying multiple boxes
« on: September 08, 2011, 03:06:59 pm »
I am displaying a solid wall (platform) using Box primitive.The code works fine and it displays th boxes continuously on x-axis.But the problem is that it gives a space between the two adjuscent boxes.That way it reduces the impression of wall.
Code: [Select]
package org.me.home;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import com.threed.jpct.Camera;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Light;
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.World;
import com.threed.jpct.util.MemoryHelper;
import java.lang.reflect.Field;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.opengles.GL10;

/**
 *
 * @author Gamerfan
 */

public class MainActivity extends Activity {

// Used to handle pause and resume...
private static MainActivity 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 cube = null;
        private Object3D box = null;
        private Object3D newbox = null;

       
private int fps = 0;

private Light sun = null;

        private float xDelta = 0;
        private float yDelta = 0;
        private float zDelta = 0;
        private int counter = 0;
       
       
    @Override
protected void onCreate(Bundle savedInstanceState) {

Logger.log("onCreate");

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

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

mGLView.setEGLConfigChooser(new GLSurfaceView.EGLConfigChooser() {
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
// Ensure that we get a 16bit framebuffer. Otherwise, we'll fall
// back to Pixelflinger on some device (read: Samsung I7500)
int[] attributes = new int[] { EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE };
EGLConfig[] configs = new EGLConfig[1];
int[] result = new int[1];
egl.eglChooseConfig(display, attributes, configs, 1, result);
return configs[0];
}
});

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

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

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

@Override
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);
}
}

    @Override
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);
}

    @Override
        public boolean onKeyDown(int keyCode, KeyEvent msg) {
          if( keyCode == KeyEvent.KEYCODE_A ) {
              System.out.println(" total angle swept " + box.getTransformedCenter().calcAngle(box.getXAxis()) );
              newbox = box.cloneObject();
              newbox.setAdditionalColor(new RGBColor(225, 0, 10));
              SimpleVector sv = new SimpleVector();
              sv.x+=xDelta;
//              sv.y+=yDelta;
//              sv.z+=zDelta;
              newbox.translate( sv );
              world.addObject( newbox );
             
              world.buildAllObjects();
              xDelta+=1.5f;
             // yDelta+=0.25f;
  //            zDelta+=1.25f;
              return true;
          }
         return true;
        }

        private Object3D drawRectangle() {
            Object3D rectangle = new Object3D(20);
            for (int y=0; y < 10; y++) {
        float fY = y / -10f;
        rectangle.addTriangle(new SimpleVector(-1, fY, 1), 0, 0,
                        new SimpleVector(-1, fY, -1), 0, 1,
                        new SimpleVector(1, fY, -1), 1, 1);
        rectangle.addTriangle(new SimpleVector(1, fY, -1), 1, 1,
                        new SimpleVector(1, fY, 1), 1, 0,
                        new SimpleVector(-1, fY, 1), 0, 0);
    }

            return rectangle;
        }
protected boolean isFullscreenOpaque() {
return true;
}

class MyRenderer implements GLSurfaceView.Renderer {

private long time = System.currentTimeMillis();

public MyRenderer() {
}

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

if (master == null) {

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

sun = new Light(world);
sun.setIntensity(250, 250, 250);

// Create a texture out of the icon...:-)
//Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.icon)), 64, 64));
//TextureManager.getInstance().addTexture("texture", texture);

cube = Primitives.getCube(1);
//cube.calcTextureWrapSpherical();
//cube.setTexture("texture");
//cube.strip();
//cube.build();


                                box = Primitives.getBox(1.5f, 0.75f);
                                box.translate(-10, 10, 0);
                                box.translateMesh();

world.addObject(cube);
                                world.addObject(box);

Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
cam.lookAt(cube.getTransformedCenter());

SimpleVector sv = new SimpleVector();
sv.set(cube.getTransformedCenter());
sv.y -= 100;
sv.z -= 100;
sun.setPosition(sv);
MemoryHelper.compact();

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

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

public void onDrawFrame(GL10 gl) {
if (touchTurn != 0) {
    cube.rotateY(touchTurn);
                            box.rotateY(touchTurn) ;
                           
                            if( newbox != null)
                            newbox.rotateY(touchTurn) ;

    touchTurn = 0;
                            yDelta +=0.02f;
}

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

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++;
}
}
}
When I press 'A' key , a new box is created using cloning the existing one.The following piece of code that performs it.
Code: [Select]
@Override
        public boolean onKeyDown(int keyCode, KeyEvent msg) {
          if( keyCode == KeyEvent.KEYCODE_A ) {
              System.out.println(" total angle swept " + box.getTransformedCenter().calcAngle(box.getXAxis()) );
              newbox = box.cloneObject();
              newbox.setAdditionalColor(new RGBColor(225, 0, 10));
              SimpleVector sv = new SimpleVector();
              sv.x+=xDelta;
//              sv.y+=yDelta;
//              sv.z+=zDelta;
              newbox.translate( sv );
              world.addObject( newbox );
             
              world.buildAllObjects();
              xDelta+=1.5f;
             // yDelta+=0.25f;
  //            zDelta+=1.25f;
              return true;
          }
         return true;
        }


[attachment deleted by admin]

79
Support / Re: Calculating rotation angle
« on: September 08, 2011, 10:55:12 am »
Thanks it worked.I used box.getTransformedCenter().calcAngle(box.getXAxis()) this will return angle swept by the rotation

80
Support / Re: Calculating rotation angle
« on: September 08, 2011, 09:42:01 am »
The box rotates on y-axis.so every time when I press a key it rotates on y-axis. At that point can we know how much angle swept by this 'rotation'.Is it clear now?  :)

81
Support / Calculating rotation angle
« on: September 08, 2011, 09:29:27 am »
Hi,
I am rotating a box and want to calculate the rotation angle for every point that it rotates in 3d world.The box rotates on Y-axis.How can I do that? Thanks in advance

82
Support / Re: Sample Example for Android not working
« on: September 07, 2011, 12:09:33 pm »
This has been solved.The jpct_ae.jar must be present where my applications class file are.It was pure environmental issue.Thanks

83
Support / Re: Sample Example for Android not working
« on: September 07, 2011, 11:37:50 am »
I have added the following lines in my build.xml file and ran the sample.But this time no error comes in DDMS, but still I am getting the same old error.
Code: [Select]
<target name="-pre-jar">
       <copy todir="${build.classes.dir}">
       <fileset dir="C:\jpct-ae\jpct-ae\lib" />
      </copy>
      </target> 
This entry for jpct.jar file while running the application.

84
Support / Re: Sample Example for Android not working
« on: September 07, 2011, 11:03:10 am »
Please find the log output
Code: [Select]
09-07 14:27:47.820: ERROR/AndroidRuntime(791): FATAL EXCEPTION: main
09-07 14:27:47.820: ERROR/AndroidRuntime(791): java.lang.NoClassDefFoundError: com.threed.jpct.RGBColor
09-07 14:27:47.820: ERROR/AndroidRuntime(791):     at org.me.home.MainActivity.<init>(MainActivity.java:42)
09-07 14:27:47.820: ERROR/AndroidRuntime(791):     at java.lang.Class.newInstanceImpl(Native Method)
09-07 14:27:47.820: ERROR/AndroidRuntime(791):     at java.lang.Class.newInstance(Class.java:1429)
09-07 14:27:47.820: ERROR/AndroidRuntime(791):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
09-07 14:27:47.820: ERROR/AndroidRuntime(791):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
09-07 14:27:47.820: ERROR/AndroidRuntime(791):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-07 14:27:47.820: ERROR/AndroidRuntime(791):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-07 14:27:47.820: ERROR/AndroidRuntime(791):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-07 14:27:47.820: ERROR/AndroidRuntime(791):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-07 14:27:47.820: ERROR/AndroidRuntime(791):     at android.os.Looper.loop(Looper.java:123)
09-07 14:27:47.820: ERROR/AndroidRuntime(791):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-07 14:27:47.820: ERROR/AndroidRuntime(791):     at java.lang.reflect.Method.invokeNative(Native Method)
09-07 14:27:47.820: ERROR/AndroidRuntime(791):     at java.lang.reflect.Method.invoke(Method.java:521)
09-07 14:27:47.820: ERROR/AndroidRuntime(791):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-07 14:27:47.820: ERROR/AndroidRuntime(791):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-07 14:27:47.820: ERROR/AndroidRuntime(791):     at dalvik.system.NativeStart.main(Native Method)
09-07 14:27:47.850: WARN/ActivityManager(60):   Force finishing activity org.me.home/.MainActivity
I have this class in my classpath and it is not giving any compile time errors.

85
Support / Sample Example for Android not working
« on: September 07, 2011, 10:41:50 am »
Hi,
I have been working on the sample example provided in Wiki and I am using NetBeans with Android to develop and run.I have modified the code in such a way that it is not using texture support and commented those lines.However, this is not producing any result and I am getting an error saying "this program has stopped unexpectedly.Please try again"

Code: [Select]
package org.me.home;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.MotionEvent;
import com.threed.jpct.Camera;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Light;
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.World;
import com.threed.jpct.util.MemoryHelper;
import java.lang.reflect.Field;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.opengles.GL10;

/**
 *
 * @author gamerfan
 */

public class MainActivity extends Activity {

// Used to handle pause and resume...
private static MainActivity 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 cube = null;
private int fps = 0;

private Light sun = null;

    @Override
protected void onCreate(Bundle savedInstanceState) {

Logger.log("onCreate");

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

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

mGLView.setEGLConfigChooser(new GLSurfaceView.EGLConfigChooser() {
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
// Ensure that we get a 16bit framebuffer. Otherwise, we'll fall
// back to Pixelflinger on some device (read: Samsung I7500)
int[] attributes = new int[] { EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE };
EGLConfig[] configs = new EGLConfig[1];
int[] result = new int[1];
egl.eglChooseConfig(display, attributes, configs, 1, result);
return configs[0];
}
});

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

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

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

@Override
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);
}
}

    @Override
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();

public MyRenderer() {
}

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

if (master == null) {

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

sun = new Light(world);
sun.setIntensity(250, 250, 250);

// Create a texture out of the icon...:-)
//Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.icon)), 64, 64));
//TextureManager.getInstance().addTexture("texture", texture);

cube = Primitives.getCube(10);
//cube.calcTextureWrapSpherical();
//cube.setTexture("texture");
//cube.strip();
cube.build();

world.addObject(cube);

Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
cam.lookAt(cube.getTransformedCenter());

SimpleVector sv = new SimpleVector();
sv.set(cube.getTransformedCenter());
sv.y -= 100;
sv.z -= 100;
sun.setPosition(sv);
MemoryHelper.compact();

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

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

public void onDrawFrame(GL10 gl) {
if (touchTurn != 0) {
cube.rotateY(touchTurn);
touchTurn = 0;
}

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

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++;
}
}
}
Not able to figure out why this is happening.Thanks in advance.

86
Support / Re: Object translation clarification
« on: July 04, 2011, 08:51:54 am »
It woked  well !!!. Now I am trying to understand this API. Thanks for your assistance.

87
Support / Object translation clarification
« on: July 01, 2011, 04:02:23 pm »
I am further understanding this rotation and camera movement of collisionDemoSoftware.This time I have added the code for moving the cube along Y-axis.And this is the following code I have added.But what happens is that the camera itself is moving up and the cube disappears.
Code: [Select]
if(keyA) {
                    SimpleVector t = cube.getYAxis();
    t.scalarMul(SPEED);
    moveRes.add(t);
                    moveRes = cube.checkForCollisionEllipsoid(moveRes, ellipsoid, 8);
                     if(moveRes.y < 0) {
                         System.out.println(" less than zer0....");
                         cube.translate(0, 0.25f, 0);
                     }   
                     else {
                        cube.translate(moveRes);
                     }
                   
                    cube.translateMesh();
                    cube.clearTranslation();
                }
I have added the above two lines. But the cube is not moving along y-axis, similarly the way it is moving along z-axis. Instead of that, the camera itself is moving up as I described earlier.What exactly I am missing here?

88
Support / Re: Object rotation
« on: July 01, 2011, 04:35:46 am »
I am further understanding this rotation and camera movement.This time I have added the code for moving the cube along Y-axis.And this is the following code I have added.But what happens is that the camera itself is moving up and the cube disappears.
Code: [Select]
if(keyA) {
                    SimpleVector t = cube.getYAxis();
    //t.scalarMul(SPEED);
    moveRes.add(t);
                    System.out.println(" keyA x " + moveRes.x+ " keyA y " + moveRes.y + " keyA z " + moveRes.z);
                    moveRes = cube.checkForCollisionEllipsoid(moveRes, ellipsoid, 8);
                    System.out.println(" x " + moveRes.x+ " y " + moveRes.y + " z " + moveRes.z);
                     if(moveRes.y < 0) {
                         System.out.println(" less than zer0....");
                         cube.translate(0, 0.25f, 0);
                     }   
                     else {
                        cube.translate(moveRes);
                     }
                   
                    cube.translateMesh();
                    cube.clearTranslation();
                }
I have added the above two lines. But the cube is not moving along y-axis, similarly the way it is moving along z-axis. Instead of that, the camera itself is moving up as I described earlier.

89
Support / Re: Object rotation
« on: June 29, 2011, 12:52:09 pm »
sorry to ask one thing here. when we say clearRotation what exactly happens?

90
Support / Re: Object rotation
« on: June 29, 2011, 12:49:27 pm »
Thanks, It worked !!!

Pages: 1 ... 4 5 [6] 7