www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: zammbi on February 28, 2012, 09:54:32 pm

Title: Drawing an advance line
Post by: zammbi on February 28, 2012, 09:54:32 pm
Hi, it's been a while since I've visited here, this time it's for work :)

I'm here in behalf of CricHQ (http://www.crichq.com/) and looking if this library is suited for what they want for it. We are creating an Android version of CricHQ mobile. One of the things needed is a 3d wagon wheel just like the current iPhone version.

Everything has been going well however it seems that Jpct doesn't support primitive line drawing by default which has put a halt in my work and I don't want to use another library if possible.

I basically need one basic method like the iPhone engine 'populateAsLineStripWith', which basically you give it a width and an array of points. And of course allows to colour it with any colour.
Everything else I can port over.

Here is an example of the wagon wheel:
(http://a4.mzstatic.com/us/r1000/060/Purple/75/56/8a/mzl.hhbtjgfg.320x480-75.jpg)
Title: Re: Drawing an advance line
Post by: EgonOlsen on February 28, 2012, 10:44:30 pm
Are the line coordinates given in world or in object space?
Title: Re: Drawing an advance line
Post by: zammbi on February 28, 2012, 10:56:34 pm
World.
Title: Re: Drawing an advance line
Post by: EgonOlsen on February 28, 2012, 11:09:58 pm
There's no direct support for line primitives...the "usual" way is to fake them using small triangles. Maybe the code in this thread helps: http://www.jpct.net/forum2/index.php/topic,2567.0.html (http://www.jpct.net/forum2/index.php/topic,2567.0.html)? It draws a trail behind an object in world space. It's hacky, but if you treat your line points in world space as the parts of the trail, it may be possible to use something like this. If won't work when looking at the lines from the side though...
Title: Re: Drawing an advance line
Post by: zammbi on February 28, 2012, 11:34:04 pm
Quote
There's no direct support for line primitives
Is there any reason? I personally think it would be a good to have simple support by default.

Quote
Maybe the code in this thread helps
Goes over my head atm :P but I'll dig into it and see if I can get what I need. Thanks.
Title: Re: Drawing an advance line
Post by: EgonOlsen on February 28, 2012, 11:42:45 pm
Is there any reason? I personally think it would be a good to have simple support by default.
I guess you are right. There are several reasons, but none of them is a killer one. It all comes down to personal preference, i suppose. Actually, i don't think that lines belong in this kind of engine. They have no depth, they have no textures, no lighting, no shaders...they are simply no real 3d elements for me like triangles are. But as said, these are no real reasons...i'll see, if there's a way to add at least some basic support for them...
Title: Re: Drawing an advance line
Post by: zammbi on February 28, 2012, 11:57:03 pm
Quote
But as said, these are no real reasons...i'll see, if there's a way to add at least some basic support for them...
Cool, I can do any testing if needed.
The 2 graphics libraries we have been using for the wagon wheel for our flash stuff and iPhone both had line support. I think it would only help jpct.
Title: Re: Drawing an advance line
Post by: zammbi on February 29, 2012, 03:37:16 am
Found some code before on the forum, which I believe was from Paul. I've modified it to allow what I want. It seems to work, now to test it... Hopefully this will help anyone else looking for lines :)

Code: [Select]
public static Object3D createLine (SimpleVector[] points, float width, String textureName)
{
    Object3D line = new Object3D( 8 * points.length);
    float offset = width / 2.0f;
   
    int count = 0;
    while(count+1 < points.length){
    SimpleVector pointA = points[count];
    SimpleVector pointB = points[count+1];
   
    // Quad A:
    line.addTriangle( new SimpleVector( pointA.x, pointA.y - offset, pointA.z ), 0, 0,
                     new SimpleVector( pointA.x, pointA.y + offset, pointA.z ), 0, 1,
                     new SimpleVector( pointB.x, pointB.y + offset, pointB.z ), 1, 1,
                     TextureManager.getInstance().getTextureID( textureName ) );
    line.addTriangle( new SimpleVector( pointB.x, pointB.y + offset, pointB.z ), 0, 0,
                     new SimpleVector( pointB.x, pointB.y - offset, pointB.z ), 0, 1,
                     new SimpleVector( pointA.x, pointA.y - offset, pointA.z ), 1, 1,
                     TextureManager.getInstance().getTextureID( textureName ) );
    // Quad A, back-face:
    line.addTriangle( new SimpleVector( pointB.x, pointB.y - offset, pointB.z ), 0, 0,
                     new SimpleVector( pointB.x, pointB.y + offset, pointB.z ), 0, 1,
                     new SimpleVector( pointA.x, pointA.y + offset, pointA.z ), 1, 1,
                     TextureManager.getInstance().getTextureID( textureName ) );
    line.addTriangle( new SimpleVector( pointA.x, pointA.y + offset, pointA.z ), 0, 0,
                     new SimpleVector( pointA.x, pointA.y - offset, pointA.z ), 0, 1,
                     new SimpleVector( pointB.x, pointB.y - offset, pointB.z ), 1, 1,
                     TextureManager.getInstance().getTextureID( textureName ) );
    // Quad B:
    line.addTriangle( new SimpleVector( pointA.x, pointA.y, pointA.z + offset ), 0, 0,
                     new SimpleVector( pointA.x, pointA.y, pointA.z - offset ), 0, 1,
                     new SimpleVector( pointB.x, pointB.y, pointB.z - offset ), 1, 1,
                     TextureManager.getInstance().getTextureID( textureName ) );
    line.addTriangle( new SimpleVector( pointB.x, pointB.y, pointB.z - offset ), 0, 0,
                     new SimpleVector( pointB.x, pointB.y, pointB.z + offset ), 0, 1,
                     new SimpleVector( pointA.x, pointA.y, pointA.z + offset ), 1, 1,
                     TextureManager.getInstance().getTextureID( textureName ) );
    // Quad B, back-face:
    line.addTriangle( new SimpleVector( pointB.x, pointB.y, pointB.z + offset ), 0, 0,
                     new SimpleVector( pointB.x, pointB.y, pointB.z - offset ), 0, 1,
                     new SimpleVector( pointA.x, pointA.y, pointA.z - offset ), 1, 1,
                     TextureManager.getInstance().getTextureID( textureName ) );
    line.addTriangle( new SimpleVector( pointA.x, pointA.y, pointA.z - offset ), 0, 0,
                     new SimpleVector( pointA.x, pointA.y, pointA.z + offset ), 0, 1,
                     new SimpleVector( pointB.x, pointB.y, pointB.z + offset ), 1, 1,
                     TextureManager.getInstance().getTextureID( textureName ) );
    count++;
    }
   
    line.setLighting( Object3D.LIGHTING_NO_LIGHTS );
    line.setAdditionalColor(new RGBColor(255, 255, 255));
    line.setCulling(Object3D.CULLING_DISABLED);
//     line.setTransparency(0);
    line.forceGeometryIndices(false);
    line.build();

    return line;
}
Title: Re: Drawing an advance line
Post by: EgonOlsen on February 29, 2012, 10:52:53 pm
Ok, i did something...please give this version a try: http://jpct.de/download/beta/jpct_ae.jar (http://jpct.de/download/beta/jpct_ae.jar)

It adds a new class called Polyline. You can define static lines with that one and add them to the world. They will be rendered after all other objects.

Please let me know if it

Title: Re: Drawing an advance line
Post by: zammbi on February 29, 2012, 11:31:46 pm
Awesome it works and looks a lot better than what I had.

Are you able to support width and transparency with the colour? Line width is quite important for us.

Other than the new Polyline class is the code stable?
Title: Re: Drawing an advance line
Post by: EgonOlsen on February 29, 2012, 11:46:03 pm
Are you able to support width and transparency with the colour? Line width is quite important for us.

Other than the new Polyline class is the code stable?
Please re-download. I've added a setter for the width to Polyline. Transparency should be possible as the color already has alpha, but it's currently not enabled by the drawing method. I'll look into it, but not today.

The code is stable as far as i know. It's the code base of what i expect to be the next official release version. It adds some new features that might cause trouble, but if you don't use them, there shouldn't be any problem. As mentioned in the other thread, i'm using this for me RPG game, which is pretty demanding and it works fine so far.
Title: Re: Drawing an advance line
Post by: zammbi on March 01, 2012, 12:19:37 am
Quote
Please re-download. I've added a setter for the width to Polyline. Transparency should be possible as the color already has alpha, but it's currently not enabled by the drawing method. I'll look into it, but not today.
Great width works perfectly!

Thanks for your help.
Title: Re: Drawing an advance line
Post by: zammbi on March 01, 2012, 04:13:54 am
Performance seems to be good. 400 lines on a Motorola Flipout seems smooth enough. The X1 is like 1fps but that's ok :P Usually the user will use it as a static screen and not change the camera angle.
Title: Re: Drawing an advance line
Post by: zammbi on March 08, 2012, 11:20:47 pm
Is it possible to allow to modify current lines? That would allow me do pooling and would be friendlier for line animation if I needed to do it.
Or could even have a 'Polyline.create' method like 'SimpleVector.create' :)
Title: Re: Drawing an advance line
Post by: EgonOlsen on March 09, 2012, 08:32:04 pm
It should be possible, but i decided not to add it until somebody asks for it (mainly because i was in a hurry when adding this feature). I'll look into it...
Title: Re: Drawing an advance line
Post by: EgonOlsen on March 09, 2012, 08:55:49 pm
I've updated the beta-jar with a method update(<SimpleVector[]>) in Polyline. You can update a line with any array of SimpleVectors which length is equals or lower than the one that was used to create the Polyline. The update performance isn't tweaked for performance, but it might be fast enough as it is. If it isn't, please let me know and i'll see if i can improve it slightly.
Title: Re: Drawing an advance line
Post by: zammbi on March 10, 2012, 02:34:09 am
Thanks Egon.

And I was right, work asked about animating the line. Which I just thought of an easy idea if you want to add it in :P Would save me from updating the points themselves.
A "setVisableLength(float length)" which could accept 0 to 1.0f. 0 meaning seeing nothing and 1 seeing 100% of the line.
It's not important atm, but would make animating the lines optimised/easier once I get to that.

 
Title: Re: Drawing an advance line
Post by: EgonOlsen on March 10, 2012, 02:35:54 pm
I've updated the jar and added a method to Polyline called setPercentage(<float> [0..1]); It defines how much of the line is visible (0= nothing, 1=fully visible). Only full segments can be visible/invisible, i.e. if the line contains only one segment, everyhing below 1 will render it invisible.
Title: Re: Drawing an advance line
Post by: zammbi on March 10, 2012, 03:13:11 pm
Awesome stuff. That will make things easier once I get to the animating of lines.