jPCT-AE - a 3d engine for Android => Support => Topic started by: laihua on August 24, 2016, 08:44:42 am

Title: Just want to ask for help
Post by: laihua on August 24, 2016, 08:44:42 am
Hello  everyone :
      I want to ask you some questions,specific as follows:

The first:
 how to converts the coordinates of the screen to the inside of the camera 3 d coordinate?  because I need to be a model accurately on a certain position of the screen.
I have use
But the ball is in the center of the screen is, fb is 1920 * 1080

The second:
How to get somewhere on the obj model coordinates, because I want to this point as the center of rotation of the model, rather than the center of gravity of the models
Title: Re: Just want to ask for help
Post by: EgonOlsen on August 25, 2016, 09:11:03 am
Try the reproject2D3DWS-method instead. The method that you are using returns the coordinates in camera space, which is most likely not what you want. Also, your z/depth-value is important. You are setting it to 1, which will get you the 3d coodinate on the clipping plane. Maybe that's not what you want here, because placing a ball there won't look very good. It depends on the scene and your needs, which approach is the best. You can have a look at the wiki. It contains a mouse-follow-example, in which you can move an object across a surface with the mouse. It's for desktop jPCT, but the idea stays the same.
To your second question...I'm not sure what you mean!?
Title: Re: Just want to ask for help
Post by: laihua on August 25, 2016, 10:14:39 am
thank for your reply ,and I have use reproject2D3DWS-method like this  (just for test fb is (1080*1920))
 SimpleVector simpleVector1 = Interact2D.reproject2D3DWS(camera, fb, 1000, 1000,1f);

 SimpleVector simpleVector2 = Interact2D.project3D2D(camera, fb, simpleVector1);

and this is debug result:
simpleVector2 = {SimpleVector@3889} "(544.55444,960.39606,0.00990099)"
simpleVector1 = {SimpleVector@3884} "(0.5324074,0.0462963,1.0)"
 why simpleVector2 not (1000,1000,1) 

the second question

For example, I loaded a cuboid model, I need to get a cuboid vertex coordinates, what should I do?

I am a Chinese, English ability is not very good.I believe you should know what I mean :)

Title: Re: Just want to ask for help
Post by: EgonOlsen on August 25, 2016, 12:59:50 pm
That because the returned vector isn't a point in world space but a vector from the camera to a point in world space. The JavaDocs actually say that, but I agree that the difference might be confusing. Just do

Code: [Select]

and you should get the desired results.

To your second question: Have a look at the PolygonManager class as well as at the GenericVertexController class. Maybe one of them provides what you need.
Title: Re: Just want to ask for help
Post by: laihua on August 26, 2016, 04:48:02 am
Thank you very much !  and I have look at MouseFollowDemo  and then make an Android demo ,But I failed :'( .Maybe I use wrong.Maybe I used the wrong, because I'm not very familiar with the coordinate system for JPCT.
My goal is where I click, the ball will appear in where    This goal is very simple, but I am very confused now . so i want to you can help me . thank you :)
and this is my

Code: [Select]
package org.yanzi.camera.preview;

import android.content.Context;
import android.opengl.GLSurfaceView;

import com.threed.jpct.Camera;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Interact2D;
import com.threed.jpct.Light;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.World;

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

public class DeskRenderer implements GLSurfaceView.Renderer {

    private Context mContext;
    private FrameBuffer fb = null;
    private Object3D ball = null;
    private World world = null;
    private Light light = null;
    private Camera camera = null;
    public float horizontal;
    public float vertical;
    public float x = 0;
    public float y = 0;

    public DeskRenderer(Context mContext) {
        this.mContext = mContext;

    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        world = new World();
        ball = Primitives.getSphere(5.0f);
        // light
        world.setAmbientLight(255, 255, 255);
        light = new Light(world);
        light.setIntensity(255, 255, 255);
        // camera
        camera = world.getCamera();
        camera.moveCamera(Camera.CAMERA_MOVEOUT, 100);

    public void onSurfaceChanged(GL10 gl, int width, int height) {
        if (fb != null) {
            fb = null;
        fb = new FrameBuffer(gl, width, height);
    public void onDrawFrame(GL10 gl) {
        SimpleVector ray = Interact2D.reproject2D3DWS(world.getCamera(), fb, (int) x, (int) y);
        if (ray != null) {
            float f = world.calcMinDistance(camera.getPosition(), ray, 1000);
            if (f != Object3D.COLLISION_NONE) {
                SimpleVector offset = new SimpleVector(ray);
                ray = ray.calcSub(offset);


When click on the screen, another class will  set value to x and y
Title: Re: Just want to ask for help
Post by: EgonOlsen on August 26, 2016, 08:51:40 am
The MouseFollow demo relies on the plane. It detect the point on the plane by doing a collision detection between the vector from the eye to the touch-point and the world. In your case, there is no plane, so this doesn't work.
Just do

SimpleVector simpleVector1 = Interact2D.reproject2D3DWS(camera, fb, 1000, 1000, 100f /* or whatever depth you need */);

Something like that should actually do it.
Title: Re: Just want to ask for help
Post by: laihua on August 26, 2016, 10:37:43 am
Thank you ,  This was a great help to me!!!   
 In addition to the API documentation , and which have a good learning materials???
Title: Re: Just want to ask for help
Post by: EgonOlsen on August 26, 2016, 12:04:40 pm
Mainly the wiki.