r3dux.org

A number-pimping side project from the valleys in *NEW* upside-down flavour.

  • Home
  • ABOUT
  • OLD SITE
  • SEARCH
  • FEEDBACK

How-To: Create A Simple OpenGL 2D Particle Fountain in C++

r3dux | January 12, 2013

I was recently asked about some particle systems I’d put together, so in response, this isn’t really a “look what I’ve coded” post – instead, it’s more of a “this is an easy way to set up a particle system framework” post.

To demonstrate the setup of a particle system using OpenGL, I’ve put together some simple starter code which displays a 2D particle fountain. I was going to just dump this code as a zipped project into a reply, but then (as my wife pointed out) it would be pretty much buried in the comments, so if other people starting OpenGL coding wanted to learn the basics of particle systems my code wouldn’t be as visible. As such, I’ve made this into a separate post – and all our example code does is this:

YouTube Preview Image

It’s a dirt-simple effect, but what it does isn’t so important right now – it’s deliberately simple. How it does what it does is what we’ll talk about.

Looking at particle systems from a high level – you generally have to choose between two different approaches to the system as a whole:

  1. You have a fixed number of particles (i.e. you have a fixed size array of however many particles) and you reset each particle to “recycle” it, or
  2. You have a dynamic number of particles (i.e. you have a dynamically resizable array) and you destroy each particle and create a new one as required.

I’ve gone with the latter approach for this code using a vector of particles (nothing to do with Vec2/Vec3 math – just the name of resizable array kinda construct). Admittedly, there’s more overhead in the creation and destruction of particles, but on the upside you don’t get that initial rush of particles you get when using fixed size arrays and as soon as you start the program BLAM! All your particles going at once.

To demonstrate what I mean, in the video below I’ve modified the code to instantiate ALL particles up to the particle limit at once, and then as soon as a particle goes off the bottom of the screen it gets destroyed and a new particle is created. The effect of which is that you get a single big burst of particles, and then as they all get destroyed and recreated at different times they turn into a smooth flow within a couple of seconds:

YouTube Preview Image

If you’re using a fixed size particle array, you’ll need to implement some mechanism to delay the instantiation or “launch” of the particles – for example, you might give each particle a random framesUntilLaunch value and decrease it by 1 each frame until it gets to 0 and you can let the particle do its thing. I wrote such a delay system for some fireworks code I did a while back if you’d like to see a concrete example.

Anyways, back at this code, our main is using three main classes to encapsulate data and provide methods to manipulate it:

  • Colour4f.hpp – A class to store a colour as red/green/blue/alpha floating point values and manipulate ‘em (including interpolation of colours),
  • Vec2.hpp – A templatised class to store two values as a vector (Not a resizable array this time! An actually “euclidian vector” – i.e. two values which represent a direction and magnitude). It also includes lots of overloaded operators so you can add two vectors together (“up” + “right” gives you “up-right” etc.), multiply a vector by a scalar (i.e. moving “up-right” multiplied by 10 means you’re now moving up-right ten times as fast). By templatised, I mean that you can create a Vec2 of ints, or floats, or doubles, or shorts, or whatever numeric type makes sense for your application – take a look at the source below if you want examples, and finally
  • Particle2D.hpp – A particle class which uses the above Colour4f and Vec2 classes to provide powerful movement and colour modification options in a small & easy to use package.

You can download the complete source code as a Code::Blocks project here, if you’d like: PointSprite_Particle_Fountain_2D.zip.

Note: As my OS of choice is GNU/Linux (LMDE, to be specific), the source files provided will have Linux line-endings – so you’ll need to open them with a good text editor like Notepad++ if you’re in in Windows, otherwise each file will look like a single massive block of noise!

Or, if you’d prefer to just browse the source code so you can copy and paste sections, you’ll find it all laid out below.

I love particle systems – you can do some visually stunning things with really simple code, or you can do amazing things if you take it further. Either way, I hope you have a lot of fun with them (there’s lots more particle stuff on this site if you’re looking for inspiration – try Actionscript tag for a start!) – and if you make anything cool or pretty using and you think I’ve helped – please do show me or let me know – I’ve love to see or hear about what you’ve done! =D

Also – if you make this – show me how, okay?

YouTube Preview Image

Cheers!

Read the rest of this entry »

Comments
1 Comment »
Categories
Coding, OpenGL
Tags
C++, Fountain, How-To, OpenGL, Particle, Vector
Comments rss Comments rss
Trackback Trackback

How To: Remove Adobe Drive

r3dux | February 1, 2010

Adobe Drive is in the default install list for CS4, and even if you deselect it, you still end up with the explorer context entries for it, which point at absolutely nothing. As there’s no separate remove option for Adobe Drive, and I’m not using Version Cue servers, you need to find another way to get rid of said useless, space-occupying junk. Like this one…

On 32-Bit Windows:
Go to Start | Run… and enter:

regsvr32 /u "%CommonProgramFiles%\Adobe\Adobe Drive CS4\ADFSMenu.dll"

Or on 64-Bit Windows:
Go to Start | Run… and enter:

regsvr32 /u "%CommonProgramFiles(x86)%\Adobe\Adobe Drive CS4\ADFSMenu.dll"

This will unregister the Adobe Drive DLL and get rid of the context menus in one fell swoop…

If you (wisely) didn’t install it in the first place and just want to get rid of the context menu entries, fire up regedit and delete the following keys:

HKEY_CLASSES_ROOT\AllFilesystemObjects\shellex\ContextMenuHandlers\{C95FFEAE-A32E-4122-A5C4-49B5BFB69795}
HKEY_CLASSES_ROOT\Directory\Background\shellex\ContextMenuHandlers\{C95FFEAE-A32E-4122-A5C4-49B5BFB69795}

Job done.

Source: here.

Comments
No Comments »
Categories
How-To
Tags
Context, Drive, How-To, Menu, Remove, Uninstall
Comments rss Comments rss
Trackback Trackback

How To: Install Thunderbird 3 in Linux

r3dux | January 5, 2010

Update: In Ubuntu 10.04 Thunderbird 3 is now in the repositories so you can just install it through Synaptic or use sudo apt-get install thunderbird

Thunderbird is my email client of choice, but Thunderbird 2.x has some issues that bug me, like poor search facilities, no tabbed emails etc. so I want the next version with all its added goodness. However, Thunderbird 3 isn’t packaged in the Ubuntu repos yet, and I don’t feel like adding a PPA to my software sources (where Thunderbird is oddly branded as its project codename: Shredder) or waiting a couple of months until it’s available – so I’ve installed the new version manually and hooked it up to my Thunderbird 2 emails like this:

Thunderbird Logo

1.) Get Thunderbird 3 from http://www.mozillamessaging.com/en-US/thunderbird/

2.) Extract it by right-clicking on the file and selecting Extract Here, or from the console with something along the lines of:

tar xfvj thunderbird-3.0.tar.bz2

Why xfvj? Because:
x = Extract
f = File mode (use the file listed on the command line)
v = Verbose (print a bunch of stuff to the screen so you can see what’s happening)
j = The file is compressed (you can tell because it’s called thunderbird-3.0.tar.bz2), so pipe it through bzip2 to decompress it first

3.) Copy it to a more reasonable location where you want it to live with:

sudo mv ./thunderbird /opt/

4.) Sort out your email profile:

Thunderbird 2.0 uses the location ~/mozilla-thunderbird (i.e. a folder called .mozilla-thunderbird located in your home directory) to store your email, while Thunderbird 3 uses ~/.thunderbird, so when I did this I hedged my bets to make sure TB3 didn’t knacker the only copy of my email hive by creating a copy of the ~/.mozilla-thunderbird folder and renaming it to .thunderbird

5.) Create a launcher for our new Thunderbird install:

Assuming you’re using gnome, right-click on the top gnome panel and select Add to Panel, then select Custom Application Launcher and enter the following details:

Thunderbird 3 Launcher Details

6.) Launch Thunderbird 3 from your spiffy new launcher

Ch-Ching! New, emaily goodness is yours for the taking. You might want to uninstall Thunderbird 2 from Synaptic and nuke your old ~/.mozillia-thunderbird folder once everything’s up and running as it’s pretty unlikely you’ll ever be going back to an older version.

Shouts out to Parick Micka for his post which got me started, as the official Thunderbird install/upgrade instructions for linux – well, I couldn’t find them, and don’t know if they even exist.

Comments
3 Comments »
Categories
How-To, Linux
Tags
Email, How-To, install, Linux, Thunderbird, Thunderbird 3
Comments rss Comments rss
Trackback Trackback

How To: Fix a Separated Zip / Zipper

r3dux | January 4, 2010

Do it like this lovely gentleman does do it:

YouTube Preview Image

But, heed this cautionary note from YouTube user Jammanen3; who so eloquently outlines a possible pitfall thus:

DON’T put that thing in the middle of the other thing. It broke my thing -.-. Use the thing on the sides of the sides of the other thing. That will work and hopefully not break the thing. :P Now I have to use some super glue to fix it -.-. Small pieces on the thing so it took me like 20 mins to fix it D:

Or in other words, don’t compress the top of the slider (the bit that actually meshes/unmeshes the teeth of the zip) with pliers, instead compress each side of the slider separately. Otherwise the piece of metal joining the pull-tab (take a wild guess..) to the slider can get mangled and come off, which you’ll then have to superglue back.

Fixed my shorts with a wonky zip double-fine :D

Although saying that, a few less pies and a bit more exercise and the zip wouldn’t have been knackered to begin with…

Comments
2 Comments »
Categories
How-To, Life
Tags
Fix, How-To, Pliers, Separated, Zip, Zipper
Comments rss Comments rss
Trackback Trackback

How To: Set up a FTP Server in Linux

r3dux | December 2, 2009

A mate of mine who shall remain nameless [cough]Shetboy[/cough] wanted to send me a 30MB file the other day, so at 30MB it’s not going to fit through email without splitting the file up and sending multiple emails with a section-per-mail, and we didn’t want to use dropsend either, so I ended up spending the best part of a day researching and setting up a FTP server on my box so he could just connect and upload the file. Here’s how I did it:

1.) Get yourself a FTP server

pro-FTPd seems to be the server of choice when I was researching, so I went with that and a copy of the docs (note that I’m not going to be using mysql for the user authentication, so I don’t need to get proftpd-mysql as well):

sudo apt-get install proftpd-basic proftpd-doc

When installing, it’ll pop up a window asking if you want a Standalone installation of FTPD, I did, and you probably do too, so just hit Next | Next | Finish or whatever to complete the installation.

2.) Get yourself a GUI to configure the server

This is optional, and you might just want to get elbow-deep in the config files, but I decided to use a GUI to configure most things, and then just tweak the resulting config file:

sudo apt-get install gadmin-tools

With that done (in Gnome, at least) you’ll have a set of GUI tools for configuring things, including proFTPd in your Applications | System Tools menu.

3.) Configure the FTP Server

This is the fun bit…

- Open GADMIN-PROFTPD and it’ll moan it doesn’t have a valid configuration file and ask you if you’d like to create a standard installation configuration, why yes, yes you would.
- As I’m not using mysql for authentication, and I don’t want to have to use real users of my system to connect, I’m going to use virtual users. To do so, just check the Enable virtual users checkbox.
- I don’t want my FTP running on the standard port (21), so I’ve moved the ftp service to run on port 2121
- I’m behind a router, so I need to tell proFTPd what my external IP is, for this guide, lets just say it’s 1.2.3.4. Enter whatever your external IP is (whatismyip.com comes in useful here) and don’t forget to change the NAT Router setting to On to enable it.
- We’re going to be using additional ports (i.e. passive FTP), so we need to leave the range of 49152 to 65534 alone, and we’re going to port-forward these from our router to our internal server IP later.

You should end up with something looking pretty much like this (bar entering YOUR external IP, not just 1.2.3.4):

proFTPConfig1proFTPConfig2

4.) Set up your Virtual Users and Groups

If we want to use actual system users (i.e. user accounts which exist to log in to our machine) we can, but it’s a bit safer to use virtual users, and do you really want to create additional accounts on your machine when you don’t have to? Thought not. So to create our virtual users we use a script called ftpasswd which comes with proFTPd.

From the shell enter the following:

cd /etc/proftpd
sudo ftpasswd --passwd  --name ftpmonkey --home /home/ftpuploads --shell=/dev/null --uid=5000 --gid=5000

Explanation:

  • The ftpasswd tool creates your user and group files in your present working directory, if we move to where we want them to be created first, we don’t have to move them later.
  • The name field is the username you want to use to log in to your ftp server.
  • /home/ftpuploads is a directory I’ve created to store all the FTP files we’re going to serve, and is the location files will be uploaded to. You’ll need to create this directory, or another directory and then set them to be owned by the nobody group and user by using sudo chown nobody /home/ftpuploads and sudo chgrp nobody /etc/ftpuploads commands.
  • –shell=/dev/null disables any FTP users from starting their own shell session where they could potentially cause mischief.
  • –uid=xxxx and –gid=xxxx – A virtual user must have a UserID and GroupID. You don’t have to use 5000 for them, just any unused User and Group IDs will do – and I picked 5000 out of the air as they’re both free on my box.

After hitting enter you’ll be prompted for the user’s desired password and confirmation of the password, then a file called ftpd.passwd will be written in your current directory.

Next we need to create the group access file using ftpasswd again as follows:

sudo ftpasswd --group --name=ftpd --gid=5000 --member=ftpmonkey

The group name can be anything you want, and make sure you put the same gid value as you used when creating your user(s) above. If you’ve got multiple users you want to be able to connect to your FTP server, just add on additional –member=someuser –member=anotheruser switches when creating the group.

If you want to add additional users later on, just create a new user using ftpasswd as we’ve done above but specify a different, unique UID for the user, then edit the ftpd.group file and tack on the users you’ve just created. For example, you’d modify the ftpd.group file so that:

ftpd:x:5000:ftpmonkey

became:

ftpd:x:5000:ftpmonkey,someuser,anotheruser

Note: You may need to add write permissions to ftpd.passwd and ftpd.conf via sudo chmod 644 ./ftpd.passwd and sudo chmod 644 ./ftpd.group if you want to manually edit them.

Finally, don’t forget to add in your new users as allowed to login to the FTP server from the proftpd.conf file by finding the section at the bottom that looks like (angle brackets changed to square brackets in the below text to avoid HTML woes):

[Limit LOGIN]
  AllowUser ftpmonkey
  DenyALL
[/Limit]

and changing it to something like:

[Limit LOGIN]
  AllowUser ftpmonkey
  AllowUser someuser
  AllowUser anotheruser
  DenyALL
[/Limit]

5.) Tweak the config

We used GADMIN-PROFTPD to create our initial configuration (which is stored in /etc/proftpd/proftpd.conf), now we’re going to tweak it a little to use our created passwd and group files. To do this, add in the following lines to the top of your proftpd.conf file (making sure you don’t have the same directives twice! i.e. if there’s another AuthUserFile directive somewhere, remove it etc.):

DenyFilter			\*.*/
# Use this to jail all users in their homes 
DefaultRoot			~
ServerType standalone
DefaultServer on
Umask 022 022
# Authentication using AuthUserFile
AuthUserFile                    /etc/proftpd/ftpd.passwd
# AuthOrder to use mod_auth_file.c only, no local user allowed
AuthOrder                       mod_auth_file.c

Once you’ve done this, strip out the Anonymous section from the bottom of the file – we don’t want anonymous logins, and GADMIN-PROFTPD uses a cludgy, incorrect way to try to add in users as anonymous users anyway.

You should end up with a file looking something like the one here.

6.) Test it locally

Stop and then start the FTP server so it’s running with our new config by using:

sudo /etc/init.d/proftpd restart

Try connecting to your server in Firefox on ftp://localhost:2121 – if you’ve followed the steps correctly you should be able to log in. If not, have a look to see if you’ve missed any steps, and maybe do a little additional reading on Virtual Users, Authentication, and basicconfig.com has a proFTPd setup guide which I found halfway through writing this one!

7.) Open it up to the world

If you can connect from inside your local network, and you want users to be able to access the FTP server from anywhere, we need to do a bit of port-forwarding to allow the server to be accessed from the outside world. Port forwarding is a big topic, and I’m not going to cover it in depth here – if you need help try portforward.com, but what we’re going to do is forward port 2121 to the local IP of our FTP server (in my case the FTP server’s just running on my laptop at local IP 192.168.1.101), and then port forward the range of ports 49152 to 65534 for our actual FTP traffic.

I tried doing this initially with the DD-WRT firmware on my router, but the router config had got a bit mangled and wouldn’t work properly. As I’d been meaning to move to the Tomato firmware anyway, I just threw that on the router and things started working properly in no-time, so just be aware that your router and not your FTP configuration can be the weak link when things aren’t working sometimes.

proFTPConfig3

With that done, try accessing your FTP server through a web browser with: ftp://YOUR-EXTERNAL-IP:2121

If you get a login box then your port-forwards are fine. If you can’t login you need to stop the FTP server and go look at the Virtual Users part again then restart the FTP server. If you can access and login, but can’t upload or download, you need to look at your ftpuploads directory and maybe change the permissions on them (try sudo chgrp 5000 /home/ftpuploads -R, for example).

Last thing, try using FileZilla or something to upload some files to your FTP server – if it works, you’ve done it. Congrats!

Oh, and the mate who wanted to FTP me a 30MB file? He’d misread the file size – it was actually 3MB… ls -alh ftw!

Final note: If you’re running DD-WRT on your router, and want to change to the Tomato firmware, don’t forget to telnet into the router and get the password hash first!

Comments
3 Comments »
Categories
How-To, Linux
Tags
FTP, How-To, Linux, Port, Port Forwarding, proFTPD, Server, Ubuntu
Comments rss Comments rss
Trackback Trackback

« Previous Entries

Translate

Categories

Archives

Tags

3D ActionScript ActionScript 3.0 Adobe AI Ballarat Bash C++ Class Convert CS4 Effect Error Film Flash FPS GLFW Glitch GLSL Hack How-To install Java Kinect Linux Live Mash-Up Microsoft Motion mount OpenGL Particle Problem PS3 Remix Retro script Slides Sound Ubuntu Video VirtualBox Wii Windows XBox

Gamercard

OpenR3dux

Misc.

Flattr this

RSS Feed

r3dux twitter feed



“The man who does things makes many mistakes, but he never makes the biggest mistake of all - doing nothing.”

 - Benjamin Franklin

rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox