Main Menu
Menu

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.

Show posts Menu

Topics - gamerfan

#1
Support / crosshair and weapon
March 31, 2012, 11:57:46 AM
Hi,
I have added a cross hair  as object3d and attached to weapon model.But the problem is that the cross hair is not visible.I am just following the Car tutorial where how the wheels of the Car are attached so that when the car moves the automatically the wheels also also move.I did it the same way here as well.But it does not seem to be working.But when I add the crosshair to weapon like below,

weapon.addChild(crossHair);

cross hair is not visible.Any clues what I am doing wrong here.

Thanks in advance.
#2
Support / .Md3 support
March 10, 2012, 10:04:01 AM
I know that already JPCT does not support .MD3. But is there any support for this in future versions?
#3
Support / paradroidz demo
December 06, 2011, 12:12:45 PM
I happened to see lot of references to paradroidz 3d demo developed in jpct.But I could not download it not found in demos.Can anyone upload this? Thanks in advance
#4
Support / direction between two objects
December 03, 2011, 10:59:49 AM
I have an enemy and a weapon object.I want to get the direction of the bullet for hitting the enemy.For that, I did like this:


SimpleVector direction = (enemy.getTransformedCenter().calcSub( weapon.getTransformedCenter()));

or

SimpleVector direction = (enemy.getTranslation().calcSub( weapon.getTranslation()));


or

SimpleVector direction = (enemy.getZAxis().calcSub(  weapon.getZAxis()));


Among them, which one I have to use?
#5
Support / Gun Collision
November 28, 2011, 06:35:32 PM
May be the answer for this question will have already answered, but I could not find much info needed in the posts.In the 'FPS' sample, the collision detection takes place with camera and wall.But I want when the gun is almost hit on the wall, it will generate collision detection.Now what happens is that when the gun hits on the wall, it just goes through it.So how can I disable it? Thanks in advance.
#6
Support / fire explosion effect
November 26, 2011, 04:33:03 PM
I want to produce some fire explosion effect.For that, can I use partclemanager.java available in alienRunner-ae? if so how can I use it?
#7
Support / Transformed center
November 26, 2011, 03:40:09 AM
one small clarification.What exactly getTransformedCenter is trying to achieve?
#8
Support / loading .bsp or quake level
November 17, 2011, 08:24:37 AM
How can I load a .bsp file or quake level? Is there any size restriction in android environment? Or can I load a .bsp file as it is in Android env?
#9
Support / Using native gl commands
November 10, 2011, 05:31:12 AM
can I use native gl commands in side onDrawFrame(GL10 gl) method? Say for example, if I want to render some objects based on CSG(Constructive Solid Geometry), how can I do it in jpct-Ae?
#10
Support / .md2 model not animating
November 07, 2011, 01:50:26 PM
Hi This is question is inspite of doing all the required steps while loading and animate a .md2 model, it is just displaying it on the screen.But not animating.I have attached the code for loading the model and displaying it on the screen.


   private Object3D drawCrabs(){
       Object3D crab = null;
       Resources res = getResources();
       crab = Loader.loadSerializedObject(res.openRawResource(R.raw.crab));
       Bitmap image = BitmapFactory.decodeResource(res, R.drawable.crab1);
       Texture texture = new Texture(image);
       TextureManager.getInstance().addTexture("crabone", texture);
       crab.setTexture("crabone");
       crab.compile(true, false);
       crab.strip();
       crab.build();
       return crab;
   }

Render animation

public void onDrawFrame(GL10 gl) {
if (touchTurn != 0) {
touchTurn = 0;
yDelta += 0.02f;
}
if (touchTurnUp != 0) {
    touchTurnUp = 0;
}

                        // animating the model to attack
                        crab1.animate(anim, crab1.getAnimationSequence().getSequence("attack"));
                        anim += 0.1f;
                        if (anim >= 1)
                        anim = 0;
                        // end of animation

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++;
}

What I am missing here.
#11
I have a problem here.I am trying to load a.md2 model first by using Loader.loadSerialize....() method.The size of .ser file is 363 kb.The original size of the .md2 file is 370kb.But at this time there is no error reported in the console and the model does not load or display in the screen or not getting any error on the console. So I decided to load the model using Loader.loadMd2() method. It loads all the animations and finally it says model loaded and followed by it throws this error.This error happens exactly at this line.


world.compileAllObjects(fb);

=========The method that loads the md2 model
So I removed all of the animations except one from it.But still I am getting the same error.

private Object3D drawCrabs(){
       Object3D crab = null;
                Resources res = getResources();
         //       try {
                    System.out.println("Start loading crab md2 model");
                    crab = Loader.loadMD2(res.openRawResource(R.raw.crab), 0.1f);
                    //crab = Loader.loadSerializedObject(new GZIPInputStream(res.openRawResource(R.raw.crabser)));
                    System.out.println("End loading crab md2 model");
         //       }
         //    catch (IOException ex) {
           //     java.util.logging.Logger.getLogger(GameActivity.class.getName()).log(Level.SEVERE, null, ex);
         //   }
                //crab = Loader.loadSerializedObject(res.openRawResource(R.drawable.crabser));
               // crab = Loader.loadMD2(getAssets().open("model/crabser.ser"), 1.0f);
              //  Bitmap image = BitmapFactory.decodeResource(res, R.drawable.crab1);
              //  Texture texture = new Texture(image);
             //   TextureManager.getInstance().addTexture("crabone", texture);
             //   crab.setTexture("crabone");
               // removing some of the animation sequences from the model
                    int flip   = crab.getAnimationSequence().getSequence("flip");
                    int salute = crab.getAnimationSequence().getSequence("salute");
                    int point  = crab.getAnimationSequence().getSequence("point");
                    int attack = crab.getAnimationSequence().getSequence("attack");
                    int pain   = crab.getAnimationSequence().getSequence("pain");
                    int jump   = crab.getAnimationSequence().getSequence("jump");
                    int taunt  = crab.getAnimationSequence().getSequence("taunt");
                    int wave   = crab.getAnimationSequence().getSequence("wave");   
                    int crstnd   = crab.getAnimationSequence().getSequence("crstnd");
                    int crwalk   = crab.getAnimationSequence().getSequence("crwalk");
                    int crattack   = crab.getAnimationSequence().getSequence("crattack");
                    int crpain  = crab.getAnimationSequence().getSequence("crpain");
                    int crdeath  = crab.getAnimationSequence().getSequence("crdeath");
                    int death  = crab.getAnimationSequence().getSequence("death");


                    crab.getAnimationSequence().remove(flip);
                    crab.getAnimationSequence().remove(salute);
                    crab.getAnimationSequence().remove(point);
                    crab.getAnimationSequence().remove(attack);
                    crab.getAnimationSequence().remove(pain);
                    crab.getAnimationSequence().remove(jump);
                    crab.getAnimationSequence().remove(taunt);
                    crab.getAnimationSequence().remove(wave);
                    crab.getAnimationSequence().remove(crstnd);
                    crab.getAnimationSequence().remove(crwalk);
                    crab.getAnimationSequence().remove(crattack);
                    crab.getAnimationSequence().remove(crpain);
                    crab.getAnimationSequence().remove(crdeath);
                    crab.getAnimationSequence().remove(death);
                   
                crab.compile();
             //   crab.strip();
                crab.build();
                System.out.println("....Returning from draw method...");
            return crab;
   }

I am using netbeans android emulator for development.
#12
I am getting the following Runtime Exception when I change to OpenGL ES 2.0.I have updated with the latest japct-ae.jar.


10-25 13:50:59.462: ERROR/AndroidRuntime(592): java.lang.RuntimeException: [ 1319530859409 ] - ERROR: java.lang.RuntimeException: [ 1319530859350 ] - ERROR: java.lang.RuntimeException: [ 1319530859305 ] - ERROR: java.lang.RuntimeException: [ 1319530859286 ] - ERROR: Couldn't read file from InputStream
10-25 13:50:59.462: ERROR/AndroidRuntime(592):     at com.threed.jpct.Logger.log(Logger.java:189)
10-25 13:50:59.462: ERROR/AndroidRuntime(592):     at com.threed.jpct.Loader.loadBinaryFile(Loader.java:1111)
10-25 13:50:59.462: ERROR/AndroidRuntime(592):     at com.threed.jpct.Loader.loadTextFile(Loader.java:71)
10-25 13:50:59.462: ERROR/AndroidRuntime(592):     at com.threed.jpct.Loader.loadTextFile(Loader.java:61)
10-25 13:50:59.462: ERROR/AndroidRuntime(592):     at com.threed.jpct.GLSLShader.<init>(GLSLShader.java:210)
10-25 13:50:59.462: ERROR/AndroidRuntime(592):     at com.threed.jpct.GL20.<init>(GL20.java:118)
10-25 13:50:59.462: ERROR/AndroidRuntime(592):     at java.lang.Class.newInstanceImpl(Native Method)
10-25 13:50:59.462: ERROR/AndroidRuntime(592):     at java.lang.Class.newInstance(Class.java:1429)
10-25 13:50:59.462: ERROR/AndroidRuntime(592):     at com.threed.jpct.GLRenderer.init(GLRenderer.java:469)
10-25 13:50:59.462: ERROR/AndroidRuntime(592):     at com.threed.jpct.GLRenderer.init(GLRenderer.java:458)
10-25 13:50:59.462: ERROR/AndroidRuntime(592):     at com.threed.jpct.FrameBuffer.<init>(FrameBuffer.java:92)
10-25 13:50:59.462: ERROR/AndroidRuntime(592):     at com.threed.jpct.FrameBuffer.<init>(FrameBuffer.java:117)
10-25 13:50:59.462: ERROR/AndroidRuntime(592):     at org.me.home.GameActivity$MyRenderer.onSurfaceChanged(GameActivity.java:207)

I have done the modifications the way it were specified in wiki.Am I missing anything?
#13
Support / Displaying multiple boxes
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.

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.

@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]
#14
Support / Calculating rotation angle
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
#15
Support / Sample Example for Android not working
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"


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.
#16
Support / Object translation clarification
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.

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?
#17
Support / Object rotation
June 29, 2011, 11:44:23 AM
Hi,
I was going through the CollisionDemoSoftware and trying to understand how it works.There I noticed one thing that the small cube has been placed on the plane.Here I need to rotate the small cube along X-axis to a certain degree.But when rotated the cube, the entire scene was away from the other objects along with small cube. (In fact, only the small cube is visible). What I want to achieve here is everything should be there as expected but the small cube should be rotated along x axis. This is the code I have used.
               
                cube = Primitives.getCube(2);
cube.translate(-50, -10, -50);
                cube.rotateX(SPEED);
                cube.rotateMesh();
               

How to handle this? Thanks in advance.
#18
Support / loading .obj file
June 20, 2011, 07:37:56 PM
Hi,
I am new to jPCT and am using this framework to develop a sample game.I am trying yo load .obj file under 3ds folder.I have created .obj file from .blender file using its exporter.But when I run the following code I am getting this exception:

Quote
Text file 3ds\butterfly.obj loaded...287934 bytes
Processing object from OBJ-file: Cube_Cube.001
Object 'Cube_Cube.001_jPCT0' created using 12 polygons and 8 vertices.
Processing object from OBJ-file: Plane.001_Plane
Object 'Plane.001_Plane_jPCT1' created using 10368 polygons and 5329 vertices.
Processing object from OBJ-file: butterfly_logic
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -10000
        at com.threed.jpct.Loader.createOBJObject(Unknown Source)
        at com.threed.jpct.Loader.loadOBJ(Unknown Source)
        at com.threed.jpct.Loader.loadOBJ(Unknown Source)
        at jpctdemo.Main.<init>(Main.java:46)
        at jpctdemo.Main.main(Main.java:83)

Let me paste the code here.This sample I have taken from the forum only.


package jpctdemo;

import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;
import com.threed.jpct.*;
import java.io.File;

class Main extends JFrame
{
   private FrameBuffer _buffer = null;
   private World _world = null;
   private TextureManager _texMgr = null;
   private Camera _camera = null;
   private int _width = 800;
   private int _height = 600;
   private Graphics _graphics = null;
   private int _titleBarHeight = 0;
   private int _leftBorderWidth = 0;
   private Object3D[] _model = null;
   private ClassLoader _classLoader = getClass().getClassLoader();

   public Main()
   {
      super("jPCT " + Config.getVersion());
      Config.glFullscreen = false;
      Config.glMipmap = true;
      Config.glColorDepth = 16;
      Config.maxPolysVisible = 64000;
      Config.fadeoutLight = false;
           
      _world = new World();
      _world.getLights().setOverbrightLighting(Lights.OVERBRIGHT_LIGHTING_DISABLED);
      _world.getLights().setRGBScale(Lights.RGB_SCALE_2X);
      _world.setAmbientLight(25, 30, 30);
      _world.addLight(new SimpleVector(-1000, -150, 1000), 22, 5, 4);
      _world.addLight(new SimpleVector(1000, -150, -1000), 4, 2, 22);     

      _texMgr = TextureManager.getInstance();
   char c = File.separatorChar;
  _texMgr.addTexture("prop_butterfly_diff", new Texture("textures"+c+"prop_butterfly_diff.png"));
      _texMgr.addTexture("fx_sparkles", new Texture("textures"+c+"fx_sparkles.png"));

//      _texMgr.addTexture("tex", new Texture(_classLoader.getResourceAsStream("model/Mat.jpg")));

      _model = Loader.loadOBJ("3ds"+c+"butterfly.obj", "3ds"+c+"butterfly.mtl", 1f);
     
      for (int i = 0; i < _model.length; i++)
      {
         _world.addObject(_model[i]);
         _model[i].setTexture("prop_butterfly_diff");
      }
     
      _camera = _world.getCamera();
      _camera.setPosition(-12, 90, 0);  // ARGGGHH  how can I center the camera over the stick figure?
      _camera.lookAt(_model[0].getTransformedCenter());

      _world.buildAllObjects();
      Config.tuneForOutdoor();

      Insets insets = getInsets();
      _titleBarHeight = insets.top;
      _leftBorderWidth = insets.left;
      setSize(_width + _leftBorderWidth + insets.right, _height + _titleBarHeight + insets.bottom);
      setResizable(false);
      setVisible(true);     
     
      _graphics = getGraphics();

      addMouseMotionListener(new MouseDragListener());

      _buffer = new FrameBuffer(_width, _height, FrameBuffer.SAMPLINGMODE_NORMAL);
      _buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE);
      _buffer.setBoundingBoxMode(FrameBuffer.BOUNDINGBOX_NOT_USED);
      _buffer.optimizeBufferAccess();
      _buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
     
      drawWorld();     
   }

   public static void main(String[] args)
   {
      new Main();
   }

   private void drawWorld()
   {
      _buffer.clear();
      _world.renderScene(_buffer);
      _world.draw(_buffer);
      _buffer.update();
      _buffer.display(_graphics, _leftBorderWidth, _titleBarHeight);
   } 
   
   private class MouseDragListener implements MouseMotionListener
   {
      final float speed = 0.05f;
      int lastX = 0;
      int lastY = 0;
     
      public void mouseDragged(MouseEvent me)
      {
         int currentX = me.getX();
         int currentY = me.getY();
         
         if (currentX > lastX)
         {
            // the mouse is going to the right
            _model[0].rotateX(speed);
         }
         else if (currentX < lastX)
         {
            // the moust is going to the left
            _model[0].rotateX(-speed);
         }
                 
         if (currentY > lastY)
         {
            // we are going down on the screen
            _model[0].rotateY(speed);
         }
         else if (currentY < lastY)
         {
            // we are going up on the screen
            _model[0].rotateY(-speed);
         }
         
         lastX = currentX;
         lastY = currentY;
         drawWorld();
      }

      public void mouseMoved(MouseEvent arg0)
      {
      }
   }
}


Can you please look into this issue and tell what I am doing wrong here.

Thanks,