Challenge nr 1 - "Vegetation" (aka one million bushes challenge)

AbstractVegetation.java


import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.scene.Node;
import com.jme.scene.Spatial;

public abstract class AbstractVegetation extends Node {
   protected Camera cam;
   protected float viewDistance;

   public AbstractVegetation( String string, Camera cam, float viewDistance ) {
      super( string );
      this.cam = cam;
      this.viewDistance = viewDistance;
   }

   public void initialize() {
   }

   public abstract void addVegetationObject( Spatial target, Vector3f translation, Vector3f scale, Quaternion rotation );

   public void setup() {
   }
}



NaiveVegetation.java


import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.Renderer;
import com.jme.scene.*;

public class NaiveVegetation extends AbstractVegetation {
   private Vector3f tmpVec = new Vector3f();

   public NaiveVegetation( String string, Camera cam, float viewDistance ) {
      super( string, cam, viewDistance );
   }

   public void addVegetationObject( Spatial target, Vector3f translation, Vector3f scale, Quaternion rotation ) {
      if ( ( target.getType() & SceneElement.NODE ) != 0 ) {
         SharedNode node = new SharedNode( "SharedNode", ( Node ) target );
         node.setLocalTranslation( translation );
         node.setLocalScale( scale );
         node.setLocalRotation( rotation );
         this.attachChild( node );
      }
      else if ( ( target.getType() & SceneElement.TRIMESH ) != 0 ) {
         SharedMesh node = new SharedMesh( "SharedMesh", ( TriMesh ) target );
         node.setLocalTranslation( translation );
         node.setLocalScale( scale );
         node.setLocalRotation( rotation );
         this.attachChild( node );
      }
   }

   public void draw( Renderer r ) {
      if ( children == null ) {
         return;
      }
      Spatial child;
      for ( int i = 0, cSize = children.size(); i < cSize; i++ ) {
         child = children.get( i );
         if ( child != null ) {
            float distSquared = tmpVec.set( cam.getLocation() ).subtractLocal( child.getLocalTranslation() ).lengthSquared();
            if ( distSquared <= viewDistance * viewDistance ) {
               child.onDraw( r );
            }
         }
      }
   }
}

So the winner gets like $10,000,000?  :-o



darkfrog

even better, he/she gets the honour, a medal from me and a romantic dinner with you froggy :slight_smile:

Hmm, so what kind of medal exactly…

renanse is just looking for an excuse to get that romantic dinner with me. :-p



darkfrog

Hey never turn down free food!

if someone makes a contribution that beats my tests on this challenge i'll send them a t-shirt that says "I crushed MrCoder", or pay for a middle sized dinner…if that makes people more motivated, i'll really do it! :slight_smile:



but more than that, i just thought it would be really interesting to see in what ways other people would attack that problem…and i think a good solution would be a nice addition to all the terrain stuff that people love to build their games on(or rather, that's often what is lacking on their naked terrains)



and i think we should have a monthly challenge that is not too big codingwise, but is something that is both fun to do and useful when making games…



next challenge someone else could come up with(or if we devs come up with one)

Any issues in passivating the data to a map file for data which is far from the player, or are you wanting it all to be in memory

you can do whatever you wish outside the framework(in your own vegetationclasses or whatever)

MrCoder said:

if someone makes a contribution that beats my tests on this challenge i'll send them a t-shirt that says "I crushed MrCoder"...


It just got interesting. :)

You realize that now I'm going to be working on this instead of doing my refactoring that I should be doing on JGN? :-p

darkfrog

just want you to do some "real" programming :wink:

Actually, I do like this idea, I like the fact that we can give people challenges and the fun of solving them, at the end we have something cool to add to the engine, and it makes the process fun.



I'll give a "jME Code Challenge Winner" shirt to the one that can beat the NaiveVegetation implementation. And by beat I'd put these rules on it (feel free to add to it):


  1. It must run faster than NaiveVegetation.
  2. It must look as good or better.
  3. It must be designed well.



    1 is an easy metric, 2 and 3 are a bit more subjective, but should be easy to agree upon.



    Lastly, there should be a time limit. Mr Coder?

I'd be willing to throw in a plush jmonkey doll.  :slight_smile:

I would suggest a months deadline, say submit code by 30th June

As there will be images and resources, a jar should be submitted, but where and who to.



Maybe split the points system up into categories

Artistic Merit

Code Clarity

Performance



Otherwise all that will be rendered are pretty looking quads



btw, about the prize, does darkfrog have to wear a dress at the dinner

This isn't a contest in the traditional sense, just a coding challenge. I don't care if each running application submitted looks exactly the same. I care if one is faster than the others and better designed. So Artistic Merit has no place here.

getting only quads wont be an issue if you follow the rules…you have to render the models added by the TestVegetation framework…



a coding challenge winner t-shirt should be given to the one with the fastest, most nicely desiged code? not anyone beating naivevegetation?



i would also like to add that memory usage should not be over the top…

…but I don't want to wear a dress.  :cry:



@renanse: do you actually have a plush jmonkey doll?



darkfrog

Nah, I'm thinking of procurring jME shwag for this and future jME code challenges though.  It's a cool idea (the challenges)

I'd shell out the $10 for a jME doll. :-p



…I'd shell out more for that autographed, "I crushed Mr. Coder" t-shirt though…



darkfrog

Ok, it's official…



Prizes: jME T-Shirt and plush doll.

Time Frame: June 30th midnight (US Central Standard Time - GMT-6)

Submitions must be mailed to contest@jmonkeyengine.com by this time.



I'll also be creating a contests forum and moving this thread.