Shield effect

I am considering a simple shield effect for my game. I simply want to do a translucent sphere around the avatar (later on my have swriling colors, etc…). OpenGL has a Sphere(float, int, int), is this object bad on performance or is this the way to go?

Thanks a ton!

Kev has a nice shield in Grav2, and I thought that Alien Flux had one as well… should be able to hunt around in the source to find it…

The way I would do it is to render a transparant quad over the avatar. Any graphic effect you want to do can be done using particle effects or manipulaiton of the transparant quad’s sprite.

Perhaps an animated sequence of images? The method at that point is up to you, but I’d definatly go with the blended quad.

forgot to mention I am in a full 3D mode, not overhead. Still use a quad?

Those games have great effects, but I was looking for more of the star trek, encompassing “globe” effect. without the wavyness or impact point, just “poof” theres a translucent bubble around the avatar.

Of course this leads into my other question here on transparent/translucent issues LOL ;D

Well for a 2D game I would use the quad… For a 3D game I would go with the sphere - bluish with a nice alpha blending…

Idea 1:
Make each shot that hits feed the alpha value so multiple shots make shield look less transparent

Idea 2: Link shield aplha to shield strength. Less strength small aplha…

Idea 3:

Make each point on the sphere have an alpha value which contantly tends up towards to some upper limit (shield recharging). When something hits you effect the points alpha based on their distance from the point of impact. That way you’ll get blips eminating out from impact points.

Kev

absolutely sweet!!! all 3 ideas.

I used the Sphere class and with a faint blue hint (before I read you guys comments) and it looks pretty good, BUT it does have an obvious performance hit while displayed so may have to make my own sphere (with triangle_strip or something?).

self note: If I get CubeWars up and running, it will be time to convert GalaxyTraders 6 to lwjgl and add ideas 2 and 3 to ship shields.

I assume you’re using the GLU sphere, in which case its very easy to generate a sphere with a huge poly count - what seems like a small amount of slices/stacks can be much worse than you initially think.

Another snag is that its generated at the time you call .draw(), a simple optimisation might be to shove it into a display list so you only generate the geometry once.

Depending on how you want your shield to look, you could still render a normal opaque quad over your ship in 3d. Just switch to ortho mode and translate the ship’s coordinates relative to the camera before you draw. This should speed things up considerably over the sphere.

This of course all depends on how you want things to look. The effect you get with the method I just described makes it look like the shield from smash brothers.

Here is some code that will make a sphere for you. It will not be faster than the GLU method. But you have all the points here and can put them into some vertex array or something and do the kevglass idea.



                  double r      = _radius;
                  int n      = _n;
                  Coord  c      = _center;
      
            
                  final double PI       = Math.PI;
                  final double TWOPI = Math.PI *2.0f;
                  final double PID2       = Math.PI * 0.5f;
            
                  int i,j;
                  double theta1,theta2,theta3;
                  //Coord e,p;
                  Coord e= new Coord();
                  Coord p= new Coord();
            
                  if (r < 0)
                        r = -r;
                  if (n < 0)
                     n = -n;
                  if (n < 4 || r <= 0) {
                     GL11.glBegin(GL11.GL_POINTS);
                     GL11.glVertex3f(c.getX(),c.getY(),c.getZ());
                     GL11.glEnd();
                     return;
                  }
                  for (j=0;j<n/2;j++) {
                     theta1 = j * TWOPI / n - PID2;
                     theta2 = (j + 1) * TWOPI / n - PID2;

                     GL11.glBegin(GL11.GL_QUAD_STRIP);
                     for (i=0;i<=n;i++) {
                          theta3 = i * TWOPI / n;
             
                          e.setX((float)(Math.cos(theta2) * Math.cos(theta3)));
                          e.setY((float)(Math.sin(theta2)));
                          e.setZ((float)(Math.cos(theta2) * Math.sin(theta3)));
                          p.setX((float)(c.getX() + r * e.getX()));
                          p.setY((float)(c.getY() + r * e.getY()));
                          p.setZ((float)(c.getZ() + r * e.getZ()));

                          GL11.glNormal3f(e.getX(),e.getY(),e.getZ());
                          GL11.glTexCoord2f(i/(float)n,2*(j+1)/(float)n);
                          GL11.glVertex3f(p.getX(),p.getY(),p.getZ());

                          e.setX((float)(Math.cos(theta1) * Math.cos(theta3)));
                          e.setY((float)(Math.sin(theta1)));
                          e.setZ((float)(Math.cos(theta1) * Math.sin(theta3)));
                          p.setX((float)(c.getX() + r * e.getX()));
                          p.setY((float)(c.getY() + r * e.getY()));
                          p.setZ((float)(c.getZ() + r * e.getZ()));

                          GL11.glNormal3f(e.getX(),e.getY(),e.getZ());
                          GL11.glTexCoord2f(i/(float)n,2*j/(float)n);
                          GL11.glVertex3f(p.getX(),p.getY(),p.getZ());
                     }
                     GL11.glEnd();

                  }



[quote]I assume you’re using the GLU sphere, in which case its very easy to generate a sphere with a huge poly count - what seems like a small amount of slices/stacks can be much worse than you initially think.

Another snag is that its generated at the time you call .draw(), a simple optimisation might be to shove it into a display list so you only generate the geometry once.
[/quote]
I will try the list and see what happens as well as lower the slices, etc…

Thanks Middy, I do like the kevglass idea and may give this awhirl also.

EDIT: Fantastic. I have the MiddySphere() up and running. I was using Sphere() not gluSphere or glutSphere, just Sphere and honestly I dont know enough OpenGL to know where it is coming from. Anyway, If I change Sphere(1.0f, 20, 16) to Sphere(1.0f, 10, 8 ) it runs beautifully and since it is only visible during impact of shield hindered projectiles, it should be ok.

I switched Sphere to the MiddySphere and still runs very well. I may leave the fluctuation/modulation of the shield for the GT6 conversion and stick with the simple for CubeWars. (and the fact that I am not fure how to implement it yet :slight_smile: )

Doh, got my code home and it runs on my gaming box, but my text is gone…LOL always something!

When its ready to test I will throw it into “your games here”

How about some screenshots :slight_smile:

Sure, but I must apologize for the location. Brinkster is not image link friendly

http://www22.brinkster.com/mbowles/

Thumbs on that page.

Out of curiosity since it had 0 replies on the clubies thread.
http://68.57.86.113:11211/cw/CubeWars.jnlp
It will more than likely fail.