Make the camera follow an object3d

Started by clown611, February 05, 2017, 01:46:31 AM

Previous topic - Next topic

clown611

Is this possible? Or how should I do this? I have a spaceship that is a loaded modell into a object3d, I want this spaceship to be in the center of my camera at all times. How do I do this?

AeroShark333

camera.lookAt(spaceship.getTransformedCenter());
Something like that?

clown611

I tested it out but it wasnt what I was looking for. I want the object to move along the camera. If I "movein" the camera I want the object to movein with me.

Thanks for the fast response tho

AeroShark333

Hmmm, I see...

What about:
camera.setPosition(spaceship.getTransformedCenter());
camera.moveCamera(Camera.CAMERA_MOVEOUT, someDistance);

someDistance is a float value that would be totally up to you :)

clown611

the camera took the spaceships centerposition so it put itself on the spaceship so I cant see him :P. Here is my code https://1drv.ms/u/s!AvWnW88CHl4QhQ3HZryfAKLpa139

EgonOlsen

Look at the car example of desktop jPCT. Maybe that helps.

clown611

ty guys for your help checking around in the car example right now. I only have one last question. I use android studio and I want to add textures but I have understood that androidstudio doenst use java.awt. So how do I do this?

EgonOlsen

Running desktop applications in Android Studio ist doomed to failure. I once tried. It is possible to a degree, but it's no fun at all. Either download Eclipse and use that for desktop jPCT or just look at the executable to see what it does and extract the important part from the sources if ist does what you want (or can be adopted to it).

clown611

but im using the jcpt-ae. How can I load a texture into the Texture?

clown611

Im sorry if I made myself unclear I was kinda sleepy yesterday. After I looked into the carexample i understod What I did wrong. But I still have this question about textures in jcptAe. When i look it up in the wiki i can see that i uses Java.awt as a input wish I cant use in android studio . I tried diffrent examples with setting a picture as texture with no success. But setting a rbgcolor works fine. Im I stupid?

AeroShark333

Quote from: clown611 on February 05, 2017, 03:37:11 PM
the camera took the spaceships centerposition so it put itself on the spaceship so I cant see him :P. Here is my code https://1drv.ms/u/s!AvWnW88CHl4QhQ3HZryfAKLpa139
That was kind of the idea of the code I gave you...
But try messing a bit more with the second line.
The first line puts the camera at the center of the spaceship and the second line should move the camera 'backwards' with a certain distance.
Try increasing the value of this distance (I'd say somewhere between 3f and 21f...? But it depends how big your spaceship object is too...)

camera.setPosition(spaceship.getTransformedCenter());
camera.moveCamera(Camera.CAMERA_MOVEOUT, someDistance);



Quote from: clown611 on February 06, 2017, 01:08:34 PM
but im using the jcpt-ae. How can I load a texture into the Texture?
Eh... I suppose you're making an Android app... right?
You can use load images from drawables in Android and turn it into a Bitmap and then turn it into a Texture
http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Texture.html
http://www.jpct.net/jpct-ae/doc/com/threed/jpct/util/BitmapHelper.html
Tip: since OpenGL prefers textures with sides that are a power of 2... I recommend you to place the images in a 'drawable-nodpi' folder so Android won't resize these...

clown611

Ye aeroshark you gave me the correct Idea but I didnt play around with it to understand the value. I Will try out to make a texture with your instructions tomorrow. Ty guys for the help

EgonOlsen

The wiki provides information about desktop jPCT as well as about jPCT-AE. Whenever you see something with AWT in it, you are basically in the wrong section. The basics still apply to both engines, but stuff like texture creation differs. Just look at the Android examples in the Wiki instead.

clown611

Ye I realised that you had two wikis one for AE and one regular. It was my mistake , got it working now tho. Ty guys