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 - 32kda

Pages: [1]
Do you mean

It solved the problem, thanks alot.

Got a problem - created a poly (two triangles), used grass texture (transparent png) for it. When rotating camera up/down, black line sometimes appears at the top of "grass" poly. See
 Is it a result of inproper texture mapping (maybe line is actually bottom row of grass texture?) or smth other.
Size of texture is 512*128, size of poly is 4*1.
How to make texture to fit this poly properly?

Support / Re: Making explosion/animated sprite
« on: June 27, 2012, 11:10:35 am »
Thanks alot, now it works
My code looks as following:
Code: [Select]
public void handleTimer(int time) {
if (needsToRemove())
sumTime += time;
if (sumTime >= PERIOD) {
sumTime = 0;
if (x == 16) {
remove = true;
texMat.set(3,0,0); //reset x translation
texMat.set(3,1,0); //reset y translation
texMat.translate(0.25f * x % 4, 0.25f * (x / 4),0); //set new translation

One more Q - sprite appears upside down for me, how can I mirror or rotate 180 deg?

Support / Re: Making explosion/animated sprite
« on: June 25, 2012, 03:11:25 pm »
Thanks alot Egon, this kind of animation works fine.

One more Q: how to make this texture transparent?
Code: [Select]

texture = new Texture(context.getAssets().open("ani4.png"),true);
TextureManager.getInstance().addTexture("explode", texture);
With png file containing alpha channel & black-backgrounded png file. Can't get transparent texture(

Support / Making explosion/animated sprite
« on: June 22, 2012, 08:47:18 am »
Hi guys,
I need to create explosion effect, AFAIK it's made with animated sprite. Please tell, how this can be done with JPCT.
Found this topic:,1406.0.html

but unable to get sources linked from it.

Thank you very much. It works fine now.
It would be great to have this explanation somewhere in project wiki.

Thanks for your answer, Egon.

Done so:
Code: [Select]
Object3D precompiledObject = PrecompiledObjectManager.getInstance().getPrecompiledObject(ID);
Object3D object = new Object3D(precompiledObject, true);
And it works OK withoout exceptions. But unfortunately I can still see 1-2s lag when creating object and adding it to world. Compilation is still called and takes very significant time. Note - when I run app on my device without eclipse debugging, lag is much smaller and only a bit sensible. All other time rendering speed with & without debug differs not significantly.
Maybe some object initialization causes hevy-weight recompile?
Is there some sample code, how spawning units/projectiles or some other such objects should be done?

Support / How to re-use precompiled data for newly created objects?
« on: June 15, 2012, 12:33:52 pm »
Good day.
In my app I need to create projectile objects several times on user input. If I create new Object3d every time, it causes terrible lag like
Object 3/shell1 compiled to 1 subobjects in 936ms!
Tried to precrerate one object and use it's compiled data:

Code: [Select]
Object3D precompiledObject = PrecompiledObjectManager.getInstance().getPrecompiledObject(ID);
Object3D object = new Object3D(precompiledObject);

But it crashes throwing " ERROR: Can't share data from different meshes!"

Can't find samples for this, please tell how it should be done.

I've tried solving this problem in bit simplier way, using accelerometer values only.
In activity class, onSensorChanged method:

Code: [Select]

    public void onSensorChanged(SensorEvent event) {
        if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER)
         * record the accelerometer data, the event's timestamp as well as
         * the current time. The latter is needed so we can calculate the
         * "present" time during rendering. In this application, we need to
         * take into account how the screen is rotated with respect to the
         * sensors (which always return data in a coordinate space aligned
         * to with the screen in its native orientation).

        switch (mDisplay.getRotation()) {
            case Surface.ROTATION_0:
                mSensorX = event.values[0];
                mSensorY = event.values[1];
            case Surface.ROTATION_90:
                mSensorX = -event.values[1];
                mSensorY = event.values[0];
            case Surface.ROTATION_180:
                mSensorX = -event.values[0];
                mSensorY = -event.values[1];
            case Surface.ROTATION_270:
                mSensorX = event.values[1];
                mSensorY = -event.values[0];
        if (gameManager != null)
        gameManager.handleSensor(mSensorX, mSensorY);
This method is mostly copied from Android sample ball game

gameManager is the instance of my game's class, which handles user input, game loop, creating game objects etc. gameManager.handleSensor(mSensorX, mSensorY) can be be replaced with your  method handling accelerometer values.

Then goes GameManager class:

Code: [Select]

final int TICKS_PER_SECOND = 50;
final int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
* Game loop thread
* @author 32kda
protected class GameLoop extends Thread {

public GameLoop() {

public void run() {
long ticks = System.currentTimeMillis();
while (!isPaused()) {
long current = System.currentTimeMillis();
if (current - ticks < SKIP_TICKS) {
try {
sleep(SKIP_TICKS - (current - ticks));
} catch (InterruptedException e) {
updateGame(System.currentTimeMillis() - ticks); //Call update game method with some time interval
ticks = current;

public boolean isPaused () {
return false;


final SimpleVector initialVectorUp = new SimpleVector(0f,-1f,0f); //Initial vector pointing up
SimpleVector vectorUp = new SimpleVector(0f,-1f,0f); //Camera's up vector. We reinit & rotate it any time we change camera orientation to set camera up/down angle with it

private float sensorX; //Accelerometer X & Y values
private float sensorY;
private float initialY = Float.MIN_VALUE; //field for storing initial y accelerometer value
private SimpleVector cameraVector = new SimpleVector(0f,0f,1f);  //Camera horizontal orientation/azimuth vector
private SimpleVector orthoVector = new SimpleVector(); //Vector for rotating camera up/down. should be orthogonal to cameraVector when rotating
private Matrix cameraMatrix = new Matrix();  //Camera up vector rotation matrix
private float angle = 0; //Camera up/down rotation angle

*handleSensor method. Simply remember sensorX / sensorY val for future use
public void handleSensor(float mSensorX, float mSensorY) {
this.sensorX = mSensorX;
this.sensorY = mSensorY;

*This method is called from game loop & used to update our world, camera, etc.
protected void updateGame(long delta) {

if (Math.abs(sensorX) > 0.3) { //If x accelerometer value is greater than some threshold - rotate camera direction vector according to it
cameraVector.rotateY(-sensorX / 150);
Camera camera = world.getCamera();
if (initialY == Float.MIN_VALUE || initialY == 0.0) //Because it's not convenient to play with device placed strictly horizontally, I use some "initial" value
initialY = sensorY; //for vertical angle, and use it as position corresponding to zero vertical angle for camera
float yDiff = sensorY - initialY; //Calc the differnce
if (Math.abs(yDiff) > 0.3) {
angle -= yDiff / 200;
if (angle > 0.40f) //Limit vertical angle
angle = 0.40f;
if (angle < -0.40f)
angle = -0.40f;
vectorUp.set(initialVectorUp); //Re-init camera up-vector before rotating it to necessary angle
orthoVector.x = cameraVector.z; //Calculate vector orthogonal to camera vector (camera up/down riotation vector)
orthoVector.z = -cameraVector.x;
calcRotMatrix(cameraMatrix,orthoVector,angle); //Calculate rotation matrix
vectorUp.rotate(cameraMatrix); //rotate camera up vector
camera.setOrientation(cameraVector,vectorUp); //Set camera orientation

* Calculates rotation matrix for arbitrary axis
* @param matrix Matrix to fill
* @param rotVector Arbitrary rotation axis vector
* @param angle Rotation angle
         * Calculation algorythm got from the Internet & it works. Can't explain in details how(
protected void calcRotMatrix(Matrix matrix, SimpleVector rotVector, float angle) {
double sin = Math.sin(angle);
double cos = Math.cos(angle);
double subcos = 1 - cos;
float x = rotVector.x;
float y = rotVector.y;
float z = rotVector.z;

matrix.set(0,0,(float) (cos + subcos*x*x));
matrix.set(0,1,(float) (subcos*x*y - sin*z));
matrix.set(0,2,(float) (subcos*x*z + sin*y));

matrix.set(1,0,(float) (subcos*y*x + sin*z));
matrix.set(1,1,(float) (cos + subcos*y*y));
matrix.set(1,2,(float) (subcos*y*z - sin*x));

matrix.set(2,0,(float) (subcos*z*x - sin*y));
matrix.set(2,1,(float) (subcos*z*y + sin*x));
matrix.set(2,2,(float) (cos + subcos*z*z));

Hi Guys.
I'm trying to wite simple shooting game using jpct-AE. Thought about making view/aim control with the accelerometer, by rotating camera to some angle after turning the device around some (x or y) axis, like it's done in some racing games.

But I can't get a logics of accelerometer values and camera rotation angles, looking right-left works OK (used cam.rotateCameraY), but trying to add up-down looking using rotateCameraX goofs camera navigation, camera begins to rotate strangely.

Can you please give a link for some sample code for such navigation or explain how to do that.
Best regards, D.A.

Pages: [1]