Game Design using Panda3D

Hello,

I have an instrumentation setup where multiple inertial sensors (IMU’s ) sends orientation information to the PC at 50Hz. I wanted to develop a game which takes these input from inertial sensors and uses as a control parameter of the game. I am not sure how to do this on Panda (and I am new to game development) and any help in this regard would make the process easier and I would like to know your opinion in this regard.

Best Regards,
Akhil

First question is how the information is sent to the pc (serial, bluetooth, usb, etc) to determine the library you need to read the raw data.

If there is a driver for said device you might be able to use ctypes or cffi to write your own wrapper.

If the OS reads it as a controller you could use pygame or pyglut (or some variant) controller library.

Hello,

@ Croxis, Thanks for your response.

I am sending the data from microcontroller using a bluetooth module (Bluegiga WT12 module). As of now, I was using pyserial to read the data and VPython for simple animation purposes. Can you explain a bit more how it could be implemented either Panda3D or pygame.

A simple game like Ping Pong with some adaptive nature would be enough for me as of now.

Best Regards,
Akhil

Sounds like you can use your existing pyserial code. Here is how I would do it.

Create and run a panda task function (the function will run once every panda frame) that reads a non-blocking pyserial connection. You might need to use a string variable as a buffer for incomplete data.

After the port is read, process your input data into how you want panda3d to react to it. Sounds like you also already have some of this done with your vpython code. I would then communicate the instructions using panda’s event system. You will then have nodepaths (such as pong paddles) listen for the event. You can also package additional data with the event, such as how fast to move a pong paddle for example.

Let me know if you need some small code examples.

@Croxis, What I have done with vpython is a cube animation using the serial data from the inertial sensors. I have started watching the video tutorials and I am not getting it easily. I am new to this gaming platform and it would be great if you can provide some sample code for the same.

Thanks for your suggestion.

Best Regards,
Akhil

Here is a very rough and untested sample

from __future__ import print_function
from direct.showbase.ShowBase import ShowBase
import serial

ser = serial.Serial(1, 38400, timeout=0, parity=serial.PARITY_EVEN, rtscts=1)
buffer = ""

MyProgram(ShowBase):
    __init__(self):
        ShowBase.__init__(self)
        self.accept("move-x", self.move_x)

    def poller(self, task):
        buffer += ser.read(100)
        #Code for reading buffer goes here
        commands = {}
        #Interprit buffer into commands. Any incomplete instructions remain in buffer
        #Commands dict looks like {"move-x": 3}
        for command, ammount in commands.values():
            self.messenger.send(command, [ammount])
        return task.cont
    
    def move_x(self, ammount):
        print("Move x by", ammount)


if __name__ == "__main__":
    app = MyProgram()
    app.run()

Hello,

I will do the complete coding and let you know the results.
Thanks for your time and suggestion.

Best Regards,
Akhil