Pi3D


211 posts   Page 5 of 9   1, 2, 3, 4, 5, 6, 7, 8, 9
by paddyg » Wed Oct 31, 2012 11:27 pm
Tom,James,Tox
Back from Skyfall and Italian. I've not read Tom's posts, will do that now, but threading was high on my list to check (i.e. for loading stuff in the background) so this certainly needs to be looked at.
Tim Skillman has done most of the development and I will send him an email with a link to this thread to try and re-awaken his interest.
I think the code is structured as it is because it's grown quite organically. It's had one shakedown to split the include stuff out and probably would benefit from a review. Certainly if there is a whole class of users who would just use the OpenGL wrapper parts then it makes a lot of sense to make this available. The more people using, developing and testing the better.
I need to go to bed now but will catch up on the various forum posts in the morning.
Paddy
PS Tom you don't sound grumpy (on this thread anyway) and even if you did; saying '..I can certainly help..' is a licence to be as grumpy as you like
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d
User avatar
Posts: 716
Joined: Sat Jan 28, 2012 11:57 am
Location: Bingley, Yorkshire
by Tom Swirly » Thu Nov 01, 2012 5:42 am
Fantastic, we can get great things done if we work together on this!

I'll be flying out tomorrow or the next day so I shan't have any RP access till Sunday. I'll be monitoring this board while I'm gone, though.

I btw have my echomesh program whizzing, spinning and expanding images now, so I'm a Happy Camper(tm).
Posts: 160
Joined: Tue Sep 25, 2012 1:08 am
by paddyg » Thu Nov 01, 2012 10:05 am
Tom, having slept on this, I think what you sound to be doing is one of the core uses of the RPi. It would be nice if the Pi3d library was in a state where an art student, say, new to programming, could cobble a good sound and graphics installation together without too much difficulty using fairly simple python. (Plus cardboard boxes and duct tape, obviously)
Kind of related to that; I know what you mean about the tidyness of the more standard apt-get install approach. However, as I am pondering my third or fourth SD card 'upgrade' to operating system I can see the attraction of being able to just copy ~/ with a usb stick without having to remember all the packages I have added (probably possible to extract it from dpkg but I don't know how)
And more distantly related: I did install cython on the SD card before last and found that it was quite easy to use. I just applied it to one function (pRec() in loaderEgg.py) and didn't do more than add a few 'cdef int' lines but there was a significant speed improvement.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d
User avatar
Posts: 716
Joined: Sat Jan 28, 2012 11:57 am
Location: Bingley, Yorkshire
by paddyg » Thu Nov 01, 2012 10:29 am
[quote="JamesR"I haven't worked it out I'm afraid, but I've figured conceptually how the texture map basically works. What are the white bits for?
So if you draw a greyscale gradient from white to black, you should get a slope basically?
It's easy enough to spot mymap and mymap1, and two definitions of size from.
Dark grey equals a narrow wall path with light grey a wider path area I guess, although 0.1 seems a bit small.
It's translating the values that makes the difference.
But if I create a line drawing in greyscale the it should follow?
I would need similar sizing, but you can't use white for the ground I guess.[/quote]

James, it might be worth looking at the use of createElevationMapFromTexture() in ForestWalk.py as it's simpler to see what's going on (better view with rolling vistas rather than canyons). There is one image mountainsHgt.jpg that is passed to the constructor to work out elevations of the polygons. White is highest and black lowest. The constructor also has the number of polygons to divide the map into and, not used in ForestWalk, how many divisions to use for tiling later on. For my maze I just started with a white sheet and drew black lines for the ditches, I then modified it so the ridges and ditches were not extreme to allow me to put in holes and higher peaks. The sole reason for doing this was to provide some kind of landmarks for orientation as the maze was just impossible for me to get through!!! The odd colours on the texture image are there for the same reason.

Later on (inside the loop) the draw method is fed the image file from mountains3_512.jpg and this gives the surface texture. You could change the image you used depending on location or direction you were pointing or any other game feature and the landscape [surface texture not shape] would change instantly. You could cycle through images to make a water, fire, lava etc surface.

Hope this helps, Paddy
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d
User avatar
Posts: 716
Joined: Sat Jan 28, 2012 11:57 am
Location: Bingley, Yorkshire
by paddyg » Thu Nov 01, 2012 4:59 pm
Tom Swirly wrote:I btw have my echomesh program whizzing, spinning and expanding images now, so I'm a Happy Camper(tm).

Not sure what an echomesh does. 'array of noisy, reactive little computers' sounds very promising but covers a lot of ground. Is it anything to do with psych o delic circus. If so this might be interesting to you (or probably not!) https://www.youtube.com/watch?v=HrDFpDNN2cw my attempt at on the fly composition plus synth from an atmega32 (pin output basically stuck directly onto jack plug).
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d
User avatar
Posts: 716
Joined: Sat Jan 28, 2012 11:57 am
Location: Bingley, Yorkshire
by paddyg » Thu Nov 01, 2012 6:20 pm
OK I've now read echomesh.org which explains a LOT more than the cryptic one-liner on github.
This is REALLY interesting and I can think of lots of possibilities.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d
User avatar
Posts: 716
Joined: Sat Jan 28, 2012 11:57 am
Location: Bingley, Yorkshire
by Forrrge » Thu Nov 01, 2012 6:42 pm
Hi, Just a quick question. By its name "Pi3D" implies that this module is aimed at the Raspberry Pi, will it be at some point be possible to use the module on Linux, Windows and Macs, so any code will be compatible across the systems?
User avatar
Posts: 57
Joined: Fri Apr 27, 2012 6:07 am
Location: Gateshead, UK.
by paddyg » Thu Nov 01, 2012 7:19 pm
Forrrge wrote:will it be at some point be possible to use the module on Linux, Windows and Macs, so any code will be compatible across the systems?

This did crop up before. At the moment it doesn't work as the required libraries aren't there for arm opengl (on the laptop and PC I tried it on, for obvious reasons) It might be possible to put in a test for processor type and load the appropriate ones at that stage. It would be really nice if this could be the case but I'm not very sure. However I arrived at the pi3d thread after struggling for a while to get panda3d running on the rPi. In my opinion this would still be an ideal solution but it's a bit of monstrous chunk of code and pi3d seemed to be pretty well working.

Paddy
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d
User avatar
Posts: 716
Joined: Sat Jan 28, 2012 11:57 am
Location: Bingley, Yorkshire
by Tom Swirly » Thu Nov 01, 2012 7:56 pm
Greetings from Indianapolis!

Thanks for the kind words on the project. We're getting a lot of interest for some reason - I think it's my partner-in-crime who's well-organized and energetic. I delivered something sorta working last night, even...

I don't see any reason in principle that pi3d couldn't run on multiple platforms, but my attempt to get it to run on the Mac failed - and not for any reason to do with pi3d, but that it was very hard to install PIL, the Python imaging library, and seemingly impossible to install without tweaking the installer by hand it for something that isn't the default Python that comes with your Mac - but pyaudio, the other part I'm using, won't install properly WITH the default Python.

I hope to tackle that issue by-and-by but my guess is that'll be early next year.

Getting it to run on Windows might be easier. I took possession of a nice PC, my first ever, a day or two before I left, and I have a need to deliver something on Windows at some point, so that might get done first...
Posts: 160
Joined: Tue Sep 25, 2012 1:08 am
by JamesR » Thu Nov 01, 2012 10:01 pm
It would be a godsend to use a windows pc IMO, especially trying to obviously create the necessary files on a desktop environment and work them into the pi. It's cumbersome.

Thanks for the tip about the forest walk Paddy, hopefully I can get some time to sort through it.
Posts: 78
Joined: Sun Aug 05, 2012 11:21 pm
by Tom Swirly » Thu Nov 01, 2012 10:35 pm
I'm wondering if we could convince the organizers of this board to create a dedicated pi3d section?

It might focus attention and help us mount a development effort.

As I said earlier in the thread, there really is no other viable solution for high-powered graphics in Python on the RP, and Python is IMHO the logical language for RP programming because it's accessible to even beginners but also extremely powerful...
Posts: 160
Joined: Tue Sep 25, 2012 1:08 am
by paddyg » Sun Nov 04, 2012 6:43 pm
JamesR wrote:Thanks for the tip about the forest walk Paddy, hopefully I can get some time to sort through it.

James, following a suggestion elsewhere to use Pi3D just for the 2D graphics to make a simple pong game I thought it wouldn't actually be any (aka much) harder to make a 3D version using the elevation map class. Here's the result of not much work http://youtu.be/R03QLvFwU3g and shows very obviously how the elevation is created from the image. There is also a bit of useful code for working out the normal at a point on the map and how to do the vector arithmetic for reflection. These could well be added to pi3d.py as a method of the elevation map. The collision testing is a bit approximate but I suppose that this could too be improved then added as a callable method. I've committed the code here
https://github.com/paddywwoof/pi3d/comm ... 40883a5933

Paddy
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d
User avatar
Posts: 716
Joined: Sat Jan 28, 2012 11:57 am
Location: Bingley, Yorkshire
by Tom Swirly » Sun Nov 04, 2012 8:58 pm
Kind of related to that; I know what you mean about the tidyness of the more standard apt-get install approach. However, as I am pondering my third or fourth SD card 'upgrade' to operating system I can see the attraction of being able to just copy ~/ with a usb stick without having to remember all the packages I have added (probably possible to extract it from dpkg but I don't know how)


Oh, if you use a simple installation scheme then you can either install it automatically, or just drag the code into your own codebase and use it that way if you like, Python's very flexible that way.

The tweaks needed to make pi3d work as a subdirectory of someone's code base or an installed product are small. I'll fork off a version and demonstrate in the next couple of days...
Posts: 160
Joined: Tue Sep 25, 2012 1:08 am
by JamesR » Sun Nov 04, 2012 9:46 pm
Loads of explanations please ;)
Posts: 78
Joined: Sun Aug 05, 2012 11:21 pm
by toxibunny » Sun Nov 04, 2012 9:48 pm
Explanations for what?
note: I may or may not know what I'm talking about...
Posts: 999
Joined: Thu Aug 18, 2011 9:21 pm
by Tom Swirly » Sun Nov 04, 2012 10:09 pm
Explanations for everything! ;-)

I forked pi3d and made a tiny change to it to get rid of the dangerous
Code: Select all
sys.path.append("include")
and use simpler and more Pythonic ways of importing code from a subdirectory.

(You need the empty __init__.py files to make sure that python knows that code exists in that directory...)
Posts: 160
Joined: Tue Sep 25, 2012 1:08 am
by toxibunny » Sun Nov 04, 2012 10:18 pm
I am absolutely terrible at programming, otherwise I'd lend a hand. I've got a github, but not a single clue how to use it!
note: I may or may not know what I'm talking about...
Posts: 999
Joined: Thu Aug 18, 2011 9:21 pm
by JamesR » Sun Nov 04, 2012 10:52 pm
Paddy's little game looks fantastic, glad I asked really as you only need to add a speed change/ level difficulty, different textures and you've made a little angry birds game there.

Is it daft to say package it up and get people to notice it, play on their pi's networked and more interest may come this way.

Toxicbunny, I wasn't aiming the explanations bit at you, it was for people like you and I so we know what the code does. Gives us a chance.
Basically then if you create subdirectory, you can place your files in there and using the empty files, the files will launch?
Posts: 78
Joined: Sun Aug 05, 2012 11:21 pm
by Tom Swirly » Sun Nov 04, 2012 11:05 pm
Basically then if you create subdirectory, you can place your files in there and using the empty files, the files will launch?


Well, this is more to do with finding one Python file from within another.

The original code uses this line to find code in /include, but that's problematic, because it assumes that "./include" is in fact the path for the pi3d library code, and because it affects sys.path.

Instead, you can directly say
Code: Select all
import include.loaderEgg
because the /include directory contains that __init__.py file.
Posts: 160
Joined: Tue Sep 25, 2012 1:08 am
by paddyg » Mon Nov 05, 2012 9:12 am
Tom, This certainly needed to be tidied up and there will be lots of other things. Tim's original code was adapted from lots of places with copy and pasting so there are random tabs and spaces (and trailing spaces as you noticed). I have tried to contact Tim at various email addresses several times and I am starting to think he might have just dropped off the radar - last messages were from some long holiday in Seychelles or such like. Maybe he decided to just stay! I will try the phone numbers on skillmanmedia.com but maybe we should transfer the central repository to someone else (I vote for you on the basis of your alter ego's CV) However it would be good to get hold of all of Tim's OpenGL2.0 stuff, he sounded to have pretty much got it working before he went quiet.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d
User avatar
Posts: 716
Joined: Sat Jan 28, 2012 11:57 am
Location: Bingley, Yorkshire
by Tom Swirly » Mon Nov 05, 2012 4:42 pm
Oh, that's very flattering, thank you!

This is a good time to take this on - I'm working about 60% of my time on the RP these days.

The bad part is that I don't really know much about OpenGL at all. Ideally, we'd have others who knew about that part and I could just scribble Python with guidance and give credit where credit was due to the OpenGL people.

Particularly, getting the 2.0 code, even if in a bad state, would be fantastic!
Posts: 160
Joined: Tue Sep 25, 2012 1:08 am
by toxibunny » Mon Nov 05, 2012 4:58 pm
I'm not sure of the correct terminology, but how hard would it be to add pi3d's OpenGles display setup stuff to pygame's Display module/class, and substitute pygame's Sprite draw/scale/rotate stuff with the pi3d methods, so that the end result would be accelerated pygame with minimal modification?

Would you have to go into the pygame source code, or could you do that with clever python stuff like extending classes, polymorphism and aliasing etc..?
note: I may or may not know what I'm talking about...
Posts: 999
Joined: Thu Aug 18, 2011 9:21 pm
by Tom Swirly » Mon Nov 05, 2012 5:09 pm
Overall comment - I'm getting sick of typing OpenGL ES 2.0, so from now on I'm calling it O2. :-D

Oh, interesting question! (Your terminology is fine...)

I don't think it'd be impossible. Python's inheritance is very flexible - you don't even have to call the base class's constructor if you don't want to (and in this case, you wouldn't want to). I've read a bunch of the pygame code and I don't remember seeing anything that would cause issues (which is a pretty limp claim really :-D but something).

The downside is that pygame doesn't support a lot of the cool stuff that O2 does support - for example, 3d, rotation of images, and that sort of thing. And you'd have to be a little careful shoehorning the new classes into the old.

My theory is that the best way to go about it would be to start by creating a basic pi3d that simply wrapped the O2 primitives, and then use that library on top of pygame. That would also have the advantage that someone who knew pygame really well could do the port without really understanding O2.
Posts: 160
Joined: Tue Sep 25, 2012 1:08 am
by Tom Swirly » Mon Nov 05, 2012 5:21 pm
Tim's original code was adapted from lots of places with copy and pasting so there are random tabs and spaces (and trailing spaces as you noticed).


The ugly, poorly-formatted code that does something completely trumps the beautiful code that doesn't.
Posts: 160
Joined: Tue Sep 25, 2012 1:08 am
by toxibunny » Mon Nov 05, 2012 5:59 pm
Linux editors seem to want a tab to = 8 spaces while on windows it was normally 4...
note: I may or may not know what I'm talking about...
Posts: 999
Joined: Thu Aug 18, 2011 9:21 pm