Author Topic: Make the camera follow an object3d  (Read 4860 times)

Offline clown611

  • byte
  • *
  • Posts: 34
    • View Profile
Make the camera follow an object3d
« on: February 05, 2017, 01:46:31 am »
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?

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Re: Make the camera follow an object3d
« Reply #1 on: February 05, 2017, 11:07:22 am »
camera.lookAt(spaceship.getTransformedCenter());
Something like that?

Offline clown611

  • byte
  • *
  • Posts: 34
    • View Profile
Re: Make the camera follow an object3d
« Reply #2 on: February 05, 2017, 12:53:48 pm »
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

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Re: Make the camera follow an object3d
« Reply #3 on: February 05, 2017, 02:09:45 pm »
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 :)

Offline clown611

  • byte
  • *
  • Posts: 34
    • View Profile
Re: Make the camera follow an object3d
« Reply #4 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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Make the camera follow an object3d
« Reply #5 on: February 05, 2017, 08:16:29 pm »
Look at the car example of desktop jPCT. Maybe that helps.

Offline clown611

  • byte
  • *
  • Posts: 34
    • View Profile
Re: Make the camera follow an object3d
« Reply #6 on: February 06, 2017, 09:23:13 am »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Make the camera follow an object3d
« Reply #7 on: February 06, 2017, 11:56:15 am »
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).

Offline clown611

  • byte
  • *
  • Posts: 34
    • View Profile
Re: Make the camera follow an object3d
« Reply #8 on: February 06, 2017, 01:08:34 pm »
but im using the jcpt-ae. How can I load a texture into the Texture?

Offline clown611

  • byte
  • *
  • Posts: 34
    • View Profile
Re: Make the camera follow an object3d
« Reply #9 on: February 07, 2017, 01:05:29 am »
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?

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Re: Make the camera follow an object3d
« Reply #10 on: February 07, 2017, 01:07:42 am »
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);



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...

Offline clown611

  • byte
  • *
  • Posts: 34
    • View Profile
Re: Make the camera follow an object3d
« Reply #11 on: February 07, 2017, 01:22:17 am »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Make the camera follow an object3d
« Reply #12 on: February 07, 2017, 08:30:47 am »
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.

Offline clown611

  • byte
  • *
  • Posts: 34
    • View Profile
Re: Make the camera follow an object3d
« Reply #13 on: February 07, 2017, 08:56:48 am »
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