Vincent14
Posts: 9
Joined: Wed Jun 01, 2016 11:39 am

Pi3d: Multiple cameras or displays for a split screen game?

Wed Jun 01, 2016 12:00 pm

Hi, I'm new on this forum and at pi3d. I've followed the pi3d book found on Github (very instructive) and the two tutorials on Youtube.

I would create a fullscreen window showing the same scene from different cameras, and render them as a slit-screen like this one:
Image

I'm not sure that pi3d is able to do that, and I'm not sure to understand which way I would follow. Could you help me please?

User avatar
paddyg
Posts: 2243
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3d: Multiple cameras or displays for a split screen ga

Wed Jun 01, 2016 6:00 pm

@vincent14,

I think a way would be to do as suggested in the previous thread and set up series of masked areas using https://www.khronos.org/opengles/sdk/do ... cissor.xml moving the Camera to a new location and redrawing the required objects. There is a performance overhead doing the drawing four times and it sounds like you might have to reset the MFlg each time round.

I will try to write a very simple demo for you tonight.

Paddy
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

User avatar
paddyg
Posts: 2243
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3d: Multiple cameras or displays for a split screen ga

Wed Jun 01, 2016 7:02 pm

Hi, This is the kind of thing you could do.

Code: Select all

import pi3d

DISPLAY = pi3d.Display.create(w=800, h=400)
CAMERA = pi3d.Camera()
shader = pi3d.Shader('mat_light')
shape1 = pi3d.Cuboid(x=-2.0, y=1.0,z=10.0, ry=45)
shape1.set_material((1.0, 1.0, 0.0))
shape2 = pi3d.Sphere(x=-1.0, y=-0.5, z=5.0)
shape2.set_material((1.0, 0.0, 1.0))
shape3 = pi3d.Plane(w=60.0, h=40.0, y=20.0, z=40.0, rx=45, ry=45)
shape3.set_material((1.0, 0.0, 0.0))

keys = pi3d.Keyboard()
mouse = pi3d.Mouse(restrict=False)
mouse.start()
camx = camz = rot = tilt = 0.0
# offsets for camera views x, y, z, ry
cam_off = ((0.0, 0,0, -10.0, 0.0), (20.0, 0,0, 2.0, -65.0), (-15.0, 0.0, 4.0, 45.0), (0.0, 1.0, 4.0, 0.0))
scissors = ((0, 0, 400, 200), (0, 200, 400, 200), (400, 0, 400, 200), (400, 200, 400, 200))

while DISPLAY.loop_running():
  for i in range(4):
    CAMERA.relocate(rot=rot+cam_off[i][3], tilt=tilt, point=(camx+cam_off[i][0], cam_off[i][1], camz+cam_off[i][2]))
    pi3d.opengles.glScissor(*scissors[i])
    pi3d.opengles.glEnable(pi3d.GL_SCISSOR_TEST)
    shape1.draw()
    shape2.draw()
    shape3.draw()
    pi3d.opengles.glDisable(pi3d.GL_SCISSOR_TEST)

  mx, my = mouse.position()
  rot = - mx * 0.2
  tilt = my * 0.2

  k = keys.read()
  if k == ord('w'):
    camz += 0.1
  elif k == ord('s'):
    camz -= 0.1
  elif k == ord('a'):
    camx -= 0.1
  elif k == ord('d'):
    camx += 0.1
  elif k == 27:
    break
There is an additional issue in that the camera perspective matrix transformation is unchanged for each view point as if the camera is positioned in the middle of the screen. What you need is the camera positioned in the middle of each viewport but that would probably involve hacking the matrix construction method in Camera. If you set the Camera to be fairly telephoto (lens with small fov) then the edge distortion might be less.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

Vincent14
Posts: 9
Joined: Wed Jun 01, 2016 11:39 am

Re: Pi3d: Multiple cameras or displays for a split screen ga

Thu Jun 02, 2016 8:41 am

damned, it's really hard! I thought I could use different cameras for that. My final goal is to create a game for a holographic pyramid.

So my split screen is actually four triangles in a X to generate this:
Image

And I would either "pilot" each cameras with gamepads, either render a single scene under four angles.

User avatar
paddyg
Posts: 2243
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3d: Multiple cameras or displays for a split screen ga

Thu Jun 02, 2016 10:33 am

Ah! In many ways that makes it easier. Presumably you don't want any background, just black so that you can look through the glass and just see the real world (apart from where there's a butterfly or Kate Moss etc). i.e. if you have an uncluttered scene you can move the camera around and draw the same object.

However because of the way rotations are 'stacked' (read up on Euler rotation and quaternions etc.) it is actually much easier to keep the camera in one place and position the objects you want to draw as children of a parent 'empty' object then rotate the empty so you get the front, back and side views of the objects. Like this:

https://youtu.be/fwGmHhpXmww

Code: Select all

import pi3d

DISPLAY = pi3d.Display.create(w=800, h=800, background=(0.0, 0.0, 0.0, 0.0))
CAMERA = pi3d.Camera()
shader = pi3d.Shader('uv_light')
texture = pi3d.Texture('textures/shed1.jpg')
empty = pi3d.Triangle(corners=((-0.01, 0.0), (0.0, 0.01), (0.01, 0.0)), z=10.0)
shape1 = pi3d.Cone(y=2.5)
shape1.set_draw_details(shader,[texture])
empty.add_child(shape1)
shape2 = pi3d.Helix(radius=0.5, y=2.5, x=0.5, z=0.5)
shape2.set_draw_details(shader,[texture])
empty.add_child(shape2)

keys = pi3d.Keyboard()
mouse = pi3d.Mouse(restrict=False)
mouse.start()
camx = camz = rot = tilt = 0.0
# rotations for camera views ry, rz
views = ((0.0, 0.0), 
         (-90.0, 90.0), 
         (90.0, -90), 
         (180.0, 180.0))

while DISPLAY.loop_running():
  shape1.rotateToY(rot)
  shape1.rotateToX(tilt)
  shape2.rotateToY(rot * 2.0)
  for v in views:
    empty.rotateToY(v[0])
    empty.rotateToZ(v[1])
    empty.draw()

  mx, my = mouse.position()
  rot = - mx * 0.2
  tilt = my * 0.2

  if keys.read() == 27:
    break
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

Vincent14
Posts: 9
Joined: Wed Jun 01, 2016 11:39 am

Re: Pi3d: Multiple cameras or displays for a split screen ga

Thu Jun 02, 2016 11:41 am

Oh well you got it! Black background yes, and moving the object in front of the cameras, also yes. Your demo on Youtube is EXACTLY what I'm looking for, you're an angel =)

As previously, I see your code and try to understand it:
- You have an only camera looking straight ahead
- First, you create a pi3d Triangle (the "empty" variable)
- Second, you attach two 3D objects on it
- Then you draw the Triangle four times in front of the camera, according to four points of view (different angles)
- Finally, you rotate the initial Triangle object on Y and Z axis

Am I right? Is that mean that it is difficult to separately move the four points of view? (like it's done in Mario Kart for example?)

I would experiment easy 3D things, I'm looking for possibilities, pi3D is a great project in that it bring 3D acceleration to beginners. You demo is basically enough for my future experiments (if you're interested in, I could notice you).

User avatar
paddyg
Posts: 2243
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Pi3d: Multiple cameras or displays for a split screen ga

Thu Jun 02, 2016 1:04 pm

When you move or rotate an object that's a childof another one the changes are relative to it. But you will want the camera to keep pointing at the cart (say) so probably not move it much from the empty. Might have to move other things relative to it
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

Return to “Graphics programming”