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
```
ball.translate(Interact2D.reproject2D3D(camera,fb,1000,1000,1));
```
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
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!?
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 :)
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
simpleVector1.add(camera.getPosition());
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.
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
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;
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
world = new World();
ball = Primitives.getSphere(5.0f);
ball.strip();
ball.build();
world.addObject(ball);
// light
world.setAmbientLight(255, 255, 255);
light = new Light(world);
light.setIntensity(255, 255, 255);
ball.getCenter();
// camera
camera = world.getCamera();
camera.moveCamera(Camera.CAMERA_MOVEOUT, 100);
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
if (fb != null) {
fb = null;
}
fb = new FrameBuffer(gl, width, height);
}
@Override
public void onDrawFrame(GL10 gl) {
fb.clear();
world.renderScene(fb);
world.draw(fb);
SimpleVector ray = Interact2D.reproject2D3DWS(world.getCamera(), fb, (int) x, (int) y);
if (ray != null) {
ray.add(camera.getPosition());
ray.normalize();
float f = world.calcMinDistance(camera.getPosition(), ray, 1000);
if (f != Object3D.COLLISION_NONE) {
SimpleVector offset = new SimpleVector(ray);
ray.scalarMul(f);
ray = ray.calcSub(offset);
ball.getTranslationMatrix().setIdentity();
ball.translate(ray);
ball.translate(world.getCamera().getPosition());
}
}
}
}
When click on the screen, another class will set value to x and y
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
Quote
SimpleVector simpleVector1 = Interact2D.reproject2D3DWS(camera, fb, 1000, 1000, 100f /* or whatever depth you need */);
simpleVector1.add(camera.getPosition());
ball.clearTranslation();
ball.translate(simpleVector1);
Something like that should actually do it.
Thank you , This was a great help to me!!!
In addition to the API documentation , and which have a good learning materials???
Mainly the wiki.