Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (566)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  which api for shapes such as ellipses, bezier...?  (Read 1462 times)
0 Members and 1 Guest are viewing this topic.
Offline beger

Junior Newbie




Java games rock!


« Posted 2004-02-09 11:08:45 »

hi, sorry in advance for bad language, not that good at english nor programming, so i'm having trouble expressing myself explicitly regarding to the programming issues =)

me and some mates are doing this school project, where we are supposed to develop some software in which the user should be able to place shapes such as:

- circles & ellipses, closed or open (like a pie missing one      piece of pie =), without the lines from circle centre to the border )
- bezier curves
- straight lines
- parabolas

.. into a 2-dimensional plane.

these shapes will be given a certain height, and both sides (of the shape, inside/outside) will be given different parametres regarding to absorption og diffusing (dont know if these are the english word for it) of the surfaces.

further on, we are supposed to render this into a 3d-picture, showing some advanced caustics.

the display of these caustics is the main point of the software, as the user of the software wants to get the specific measures of these shapes, so that they can reproduce this setting and caustics in real life. ( they are artists of some kind)

only thing we DO know, is that the GUI will be programmed in Java.

We've found several helpful classes in the Graphics2D for modelling 2d-shapes, but cant seem to find any way to get these shapes into a Java3D context..

So: IS there a way to do it by the help of Graphics2D     shapes?

We've looked into the Java3D API as well, but there seem to be little or none classes that could help our "shaping needs" in such a way as Graphics2D can..

Or is it?

Finally, if the answer to the 2 questions above is NO; which API would you recommend for us?

Or do you have any other ideas?

thanks in advance,

lars petter
NORWAY
Offline Breakfast

Senior Member




for great justice!


« Reply #1 - Posted 2004-02-09 18:13:13 »

There aren't any prewritten classes to do this on your behalf, but it should be easy enough to find the maths to do them for yourselves. Java3D and the Graphics2D APIs don't really talk very well to each other in terms of geometry, although they are fine for passing images back and forth.

Java3d is the most high level 3D java api and so it will probably be easier for you to implement stuff using it than using one of the direct OpenGL ones, but you will probably have to work effectively from scratch whichever you use.
Offline rdcarvallo

Senior Member


Projects: 5
Exp: 15 years


2D Java games forever!


« Reply #2 - Posted 2004-02-10 10:38:23 »

 The shapes that you want to draw are Beziers (4 control points) or general NURBS?? I have a program that renders Beziers curves and surfaces, (the algorithm for the surfaces has errors).
 For the curves I evaluate  a set of points and use Lines for the Geometry.. The same method can be used to calculate the points in a ellipses or the others shapes needed..

  I have the code in my home (now I'm  at work), I can post the bezier code as an example.

  I don't understand well, what will you do with the curves after.. setting height and sides. Render into 3d.
  The final image has the profile of a hill, mountain??

  Rafael
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline esvxm

Senior Newbie




Java games rock!


« Reply #3 - Posted 2004-02-10 19:57:24 »

Is it possible for you to post the code for the curves...

Cheers
Offline beger

Junior Newbie




Java games rock!


« Reply #4 - Posted 2004-02-10 20:39:30 »

hi again, thanks for the responses


Quote
The shapes that you want to draw are Beziers (4 control points) or general NURBS??


i'm not sure what NURBS are, so i cant answer that=)

an example:

in the 2d plane, i want to place a circle, assign a height to it, place a light source, and then get a rendered image, including the caustics. like this:

http://usurped.net/renders/caustics.jpg

it's these lighting effects that are the main point.

we've been thinking of using java3d in the 2d-plane as well, since that would make it much easier for us to get the 3d render done. the problem is then, how we easily can get the shape modelling done.

the modelling is supposed to be somewhat like how you do it in adobe illustrator, with the bezier curves, you add start & end point as well as control points, and these should be draggable. the rotate/move/scale funtionality from illustrator is also desirable.

hope this clears things up a bit.

EDIT: i'm also wondering if java3d supports such a detailed level of lighting/shadowing effects. can i get something as detailed as in the picture i linked?

- lars petter
Offline rdcarvallo

Senior Member


Projects: 5
Exp: 15 years


2D Java games forever!


« Reply #5 - Posted 2004-02-11 09:19:04 »

Woa! Nice lightning..
 But I don't think you could get this efects woth Java3D (maybe one of the OpenGL bindings). The shading model in Java3D hasn't shadows..
 Other option is to program your won methods for raytracing/rendering in Java2d/awt.

  For the GUI, I recomend to use 2 frames/panels, one with the drawing in 2D sharing the model with the 3d display(which also knows how to extrude de shape from 2d to 3d)
  In the drawing panel you can listen the mouse events to edit your shapes. And the 3d display will update its contents(it can be automatically or manually).

 Ask in the Jogl or LWJGL forums to know if there is a possibility to achieve what you want..

 Rafael
Offline beger

Junior Newbie




Java games rock!


« Reply #6 - Posted 2004-02-11 10:54:02 »

i've just been asking around.. and what we need is not supported by opengl nor directx.. so what we'll be doing is (like you are suggesting) using a raytracer, probably povray (http://www.povray.org), exporting povray "code" from the 2d plane.

however, thanks for the help, we really appreciate your effort. now, off to read povray documentation:)

- lars petter
Offline esvxm

Senior Newbie




Java games rock!


« Reply #7 - Posted 2004-02-11 14:13:02 »

Try visiting this website and have a look at the chapter for lathe shapes. It might be of interest


http://fivedots.coe.psu.ac.th/~ad/jg/


Offline rdcarvallo

Senior Member


Projects: 5
Exp: 15 years


2D Java games forever!


« Reply #8 - Posted 2004-02-13 04:16:13 »

esxvm, there goes the code, it subdivides the curve until the distance of the fitst to points is less then the parameter.
The code has spanish comments, (almost all the vars and methods are in english)..
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
import javax.media.j3d.*;
import javax.vecmath.*;

public class Curva {
  BranchGroup BG;
  public Curva(Point3d[] elem,Appearance ap,double prec) {
    BG = new BranchGroup();
    Shape3D[] r = generatePatchs(elem,ap,prec);
    for(int i=0;i<r.length;i++)
      BG.addChild(r[i]);
  }
  public BranchGroup getBG(){
    return BG;
  }
  Shape3D[] generatePatchs(Point3d[] v,Appearance ap,double dst){
    if(v[0].distance(v[1])<dst  || v[2].distance(v[3]) < dst){
      Shape3D[] res = new Shape3D[1];
      Point3d[] d = new Point3d[6];
      d[0]=v[0];
      d[1]=v[1];
      d[2]=v[1];
      d[3]=v[2];
      d[4]=v[2];
      d[5]=v[3];
      res[0]=new Shape3D();
      LineArray qa=new LineArray(6,QuadArray.COORDINATES);
      qa.setCoordinates(0,d);
      res[0].setGeometry(qa);
      res[0].setAppearance(ap);
      return res;

    }
    else{
      Point3d tmp = new Point3d(v[1]);
      tmp.add(v[2]);
      tmp.scale(0.25);
      //primero v1;
     Point3d[] v1 = new Point3d[4];
      v1[0] = new Point3d(v[0]);
      v1[1] = new Point3d(v[0]);
      v1[1].add(v[1]);
      v1[1].scale(0.5);
      v1[2] = new Point3d(v1[1]);
      v1[2].scale(0.5);
      v1[2].add(tmp);

      //luego v2
     Point3d[] v2 = new Point3d[4];
      v2[3] = new Point3d(v[3]);
      v2[2] = new Point3d(v[2]);
      v2[2].add(v[3]);
      v2[2].scale(0.5);
      v2[1] = new Point3d(v2[2]);
      v2[1].scale(0.5);
      v2[1].add(tmp);
     
      //falta la union, v1[3], v2[0];
     
      v1[3] = new Point3d(v1[2]);
      v1[3].add(v2[1]);
      v1[3].scale(0.5);
     
      v2[0] = new Point3d(v1[3]);
     
      Shape3D[] r1 = generatePatchs(v1,ap,dst);
      Shape3D[] r2 = generatePatchs(v2,ap,dst);
      Shape3D[] res = new Shape3D[r1.length+r2.length];
      int j=0;
      for(int i=0;i<r1.length;i++){
        res[j+i]=r1[i];
      }
      j+=r1.length;
      for(int i=0;i<r2.length;i++){
        res[j+i]=r2[i];
      }
      return res;

    }
  }
}

It receives the four control points, the appearance and the minimum distance.
To add it in the scene use getBG() returns a branchgroup with the Shape inside.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (35 views)
2014-09-24 16:13:29

Pippogeek (28 views)
2014-09-24 16:12:22

Pippogeek (17 views)
2014-09-24 16:12:06

Grunnt (40 views)
2014-09-23 14:38:19

radar3301 (23 views)
2014-09-21 23:33:17

BurntPizza (58 views)
2014-09-21 02:42:18

BurntPizza (29 views)
2014-09-21 01:30:30

moogie (34 views)
2014-09-21 00:26:15

UprightPath (47 views)
2014-09-20 20:14:06

BurntPizza (51 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!