Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (499)
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  
  JIGAXtended (the RenderingScene):a static method for some unplugged graphics FX  (Read 1339 times)
0 Members and 1 Guest are viewing this topic.
Offline broumbroum

Junior Member





« Posted 2008-03-08 05:11:41 »

This a sample of the RenderingScene class of the JIGAXtended API; it provides support for at least 2 graphics FX that can be combined together by using a bitwise-inclusive-OR combination : Wink
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  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
/** angular speed rad/msec for the PerspectiveTransform effect */
    public static float perspective_ANGULARSPEED = (float) Math.PI / (24f * 1000f);
    /** map for the last transform angular values */
    private static Map<String, Float> lastTransformTheta = Collections.synchronizedMap(new HashMap<String, Float>());
    /** map for the last transform timestamps */
    private static Map<String, Long> lastTransformTime = Collections.synchronizedMap(new HashMap<String, Long>());
    /** map for the reflexion fx*/
    private static Map<String, GradientPaint> gradients = Collections.synchronizedMap(new HashMap<String, GradientPaint>());
    /** reflexion fx on the bottom side */
    public final static int FX_DOWNREFLEXION = 4;
    /** the rotation FX*/
    public final static int FX_ROTATION = 2;
    /** the no fx */
    public final static int FX_NONE = 1;

    /** draws a logo caught with getLogo() using a specific layout position. a rotation effect can be added
    @param g2 te Graphics2D isntance where to draw onto
    @param logo the file name of the logo to draw
    @param size the size at which to draw the logo
    @param hpos the horizontal position
    @param vpos the vertical postion
    @param fx dis/enables the selected FX (a bitwise-inclusive-OR combination of FX)
     * @param c the Component to draw onto
     * @see #FX_NONE
     * @see #FX_ROTATION
     * @see #FX_DOWNREFLEXION
    1    @see #getLogo(String, Dimension)
    @see GUIConsoleOutput#LEFT
    @see GUIConsoleOutput#CENTER
    @see GUIConsoleOutput#RIGHT
    @see GUIConsoleOutput#TOP
    @see GUIConsoleOutput#BOTTOM*/

    public static void _drawLogo(Component c, Graphics2D g2, String logo, Dimension size, int hpos, int vpos, int fx) throws InterruptedException {
        Sprite logo_sp = _getLogo(c, logo, size);
        GraphicsJAI g = Sprite.createGraphicsJAI(g2, c);
        g.setRenderingHints(Sprite._getRenderingHints());
        // screen postioning
        Point translate = new Point(0, 0);
        Insets insets = new Insets(10, 10, 10, 10);
        switch (hpos) {
            case GUIConsoleOutput.LEFT:
                translate.x = insets.left;
                break;
            case GUIConsoleOutput.CENTER:
                translate.x = (int) ((float) c.getWidth() / 2.0f - (float) size.width / 2.0f);
                break;
            case GUIConsoleOutput.RIGHT:
                translate.x = -insets.right + (int) (c.getWidth() - size.width);
                break;
            default:
                break;
            }
        switch (vpos) {
            case GUIConsoleOutput.TOP:
                translate.y = insets.top;
                break;
            case GUIConsoleOutput.CENTER:
                translate.y = (int) ((float) c.getHeight() / 2.0f - (float) size.height / 2.0f);
                break;
            case GUIConsoleOutput.BOTTOM:
                translate.y = -insets.bottom + (int) (c.getHeight() - size.height);
                break;
            default:
                break;
            }
        AffineTransform tx = null;
        AffineTransform tx2 = null;
        System.err.println("FX " + logo + " fx & rotation = " + (fx & FX_ROTATION) + " fx & reflexion = " + (fx & FX_DOWNREFLEXION));
        if ((fx & FX_ROTATION) != 0) {
            long now = System.currentTimeMillis();
            if (!(lastTransformTime.get(logo) instanceof Long)) {
                lastTransformTime.put(logo, now);
            }
            float lastTransformTheta = RenderingScene.lastTransformTheta.containsKey(logo) ? RenderingScene.lastTransformTheta.get(logo) : (1f - 1f / 360f) * 2f * (float) Math.PI;
            lastTransformTheta -= (float) (now - lastTransformTime.get(logo)) * perspective_ANGULARSPEED;
            lastTransformTheta = lastTransformTheta % (2f * (float) Math.PI);
            tx = AffineTransform.getRotateInstance(lastTransformTheta, (float) size.width / 2f, (float) size.height / 2f);
            tx2 = (fx & FX_DOWNREFLEXION) != 0 ? AffineTransform.getRotateInstance(-lastTransformTheta, (float) size.width / 2f, (float) size.height / 2f) : tx;
            RenderingScene.lastTransformTheta.put(logo, lastTransformTheta);
            lastTransformTime.put(logo, now);
        }
        if ((fx & FX_DOWNREFLEXION) != 0) {
            Sprite shadow = (Sprite) logo_sp.clone();
            if (shadow == null) {
                return;
            }
            shadow.setTX(tx2);
            shadow.setFlipEnabled(true, Sprite.VERTICAL);
            shadow.setCompositeEnabled(true);
            if (!(gradients.get(logo) instanceof GradientPaint)) {
                gradients.put(logo, new GradientPaint(0, 0, new Color(1.0f, 1.0f, 1.0f, 1.0f), 0, (float) size.height * 0.66f, new Color(1.0f, 1.0f, 1.0f, 0.0f), false));
            } else if (gradients.get(logo).getPoint2().distance(gradients.get(logo).getPoint1()) != (float) size.height * 0.66f) {
                gradients.put(logo, new GradientPaint(0, 0, new Color(1.0f, 1.0f, 1.0f, 1.0f), 0, (float) size.height * 0.66f, new Color(1.0f, 1.0f, 1.0f, 0.0f), false));
            }
            Paint shadow_gradient = gradients.get(logo);
            shadow.setPaint(shadow_gradient);
            shadow.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_IN, 1.0f));
            shadow.validate();
            g.translate(translate.x, translate.y + size.height);
            shadow.draw(c, g);
            g.translate(-translate.x, -translate.y - size.height);
        }
        g.translate(translate.x, translate.y);
        logo_sp.validate();
        logo_sp.draw(c, g, tx, null);
        g.translate(-translate.x, -translate.y);
    }


::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
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.

xsi3rr4x (45 views)
2014-04-15 18:08:23

BurntPizza (41 views)
2014-04-15 03:46:01

UprightPath (57 views)
2014-04-14 17:39:50

UprightPath (39 views)
2014-04-14 17:35:47

Porlus (55 views)
2014-04-14 15:48:38

tom_mai78101 (78 views)
2014-04-10 04:04:31

BurntPizza (137 views)
2014-04-08 23:06:04

tom_mai78101 (237 views)
2014-04-05 13:34:39

trollwarrior1 (198 views)
2014-04-04 12:06:45

CJLetsGame (206 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!