Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Java 2D / Changing a color on a bitmap with Color matrix on: 2012-03-03 05:28:31
OK, I know how to change red, blue, and green to other colors using a ColorMatrix, but how do go about using it to change black to white for example?

Let's say I have a bitmap with a bunch of black dots on a mostly white background that also has some other colors on it. I do not want to touch the other colors, but I need to convert the black pixels to white but I cannot see how that can be done with the ColorMatrix.

Can it, and if so how?  If not, how can you do this efficiently? I know that you can do a setPixel on a Bitmap, but it is horribly slow.

Thanks!
2  Java Game APIs & Engines / Java 2D / Re: Basic 2D math problem on: 2012-02-21 21:20:47
Actually I think I might have it using my own calculation. At least I think it seems to be working. Haven't tested it thoroughly yet. Code looks something like this:

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  
   private void corelatePoints(Rect phoneRect, Rect imageRect, int xTouch, int yTouch)
   {
      //Shift out the pan
     int xIntermediate = xTouch - phoneRect.left;
      int yIntermediate = yTouch - phoneRect.top;

      //Now correct for the zoom
     float xRatio = (phoneRect.right  - phoneRect.left) / (float)(imageRect.right  - imageRect.left);
      float yRatio = (phoneRect.bottom - phoneRect.top)  / (float)(imageRect.bottom - imageRect.top);

      int xOriginal = (int)(xIntermediate / xRatio);
      int yOriginal = (int)(yIntermediate / yRatio);
     
      Point pImage = new Point();
      pImage.x = xOriginal;
      pImage.y = yOriginal;
     
      Point pPhone = new Point();
      pPhone.x = (int)mState.getTouchX();
      pPhone.y = (int)mState.getTouchY();
     
     
      callback.coordinateTouched(pPhone, pImage);
   }

[code]
[/code]
3  Java Game APIs & Engines / Java 2D / Re: Basic 2D math problem on: 2012-02-20 16:56:33
OK, I tried that but it doesn't seem like it works.

In short, I did this:


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
   float t = panX * viewWidth;
               
          float p;
               
        //Do this in case the zoom is very close to 1
         if(zoomX > 0.95 && zoomX < 1.05)
          {
             p = t;
          }
          else
          {
             p = t / (1 - zoomX);
          }



I think you are saying that t needs to be in pixels and not in a percentage right? That's why I calculated it like I did.  

Hmm...looks like the thing is flipping the panX and viewWidth values to be what they should be in portrait rather than landscape mode (this is on a phone). That might have been part of the problem. I'll play around with it some more and post back what I come up with.

Thanks.
4  Java Game APIs & Engines / Java 2D / Re: Basic 2D math problem on: 2012-02-17 21:06:01
I will try that and let you know.

Thanks!

5  Java Game APIs & Engines / Java 2D / Basic 2D math problem on: 2012-02-16 23:12:08
I am a 2D novice so please forgive this question for being so simple, but at the same time no one seems to be able to give me an answer that works either so maybe it isn't so simple?

All I want to know is given a point on an image that you pan and zoom, what would that point be on the image had it not been panned and zoomed?

I have code that zooms and pans that looks like this. All I want to know is what needs to be done to get the new point (mState.touchX) projected back to what it would be in the original image.

Someone mentioned a formula that I tried to use (see the Log statements for details on it) but that didn't do it so I am asking here in the hope that someone knows how to do this.

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  
private void calculateAspectQuotient() 
    {
        if (mBitmap != null)
        {
            mAspectQuotient = (((float)mBitmap.getWidth()) / mBitmap.getHeight()) / (((float)getWidth()) / getHeight());
        }
    }

    // Superclass overrides

    @Override
    protected void onDraw(Canvas canvas)
    {
        if (mBitmap != null && mState != null)
        {
            final int   viewWidth    = getWidth();
            final int   viewHeight   = getHeight();
            final int   bitmapWidth  = mBitmap.getWidth();
            final int   bitmapHeight = mBitmap.getHeight();
            final float panX         = mState.getPanX();
            final float panY        = mState.getPanY();
           
            final float zoomX       = mState.getZoomX(mAspectQuotient) * viewWidth / bitmapWidth;
            final float zoomY       = mState.getZoomY(mAspectQuotient) * viewHeight / bitmapHeight;

            // Setup source and destination rectangles
           mRectSrc.left   = (int)(panX * bitmapWidth  - viewWidth  / (zoomX * 2));
            mRectSrc.top    = (int)(panY * bitmapHeight - viewHeight / (zoomY * 2));
            mRectSrc.right  = (int)(mRectSrc.left + viewWidth / zoomX);
            mRectSrc.bottom = (int)(mRectSrc.top + viewHeight / zoomY);
           
            mRectDst.left   = getLeft();
            mRectDst.top    = getTop();
            mRectDst.right  = getRight();
            mRectDst.bottom = getBottom();

            // Adjust source rectangle so that it fits within the source image.
           if (mRectSrc.left < 0)
            {
                mRectDst.left += -mRectSrc.left * zoomX;
                mRectSrc.left = 0;
            }
           
            if (mRectSrc.right > bitmapWidth)
            {
                mRectDst.right -= (mRectSrc.right - bitmapWidth) * zoomX;
                mRectSrc.right = bitmapWidth;
            }
           
            if (mRectSrc.top < 0)
            {
                mRectDst.top += -mRectSrc.top * zoomY;
                mRectSrc.top = 0;
            }
           
            if (mRectSrc.bottom > bitmapHeight)
            {
                mRectDst.bottom -= (mRectSrc.bottom - bitmapHeight) * zoomY;
                mRectSrc.bottom = bitmapHeight;
            }

            if(DebugOptions.DEBUG_ENABLED)
            {
               Log.d(TAG, "View width: " + viewWidth   + " View height: " + viewHeight);
               Log.d(TAG, "Bmap width: " + bitmapWidth + " Bmap height: " + bitmapHeight);
               Log.d(TAG, "panX:       " + panX        + " panY:      " + panY);

               Log.d(TAG, "mRectSrc.left:   " + mRectSrc.left);
               Log.d(TAG, "mRectSrc.top:    " + mRectSrc.top);
              Log.d(TAG, "mRectSrc.right:  " + mRectSrc.right);
               Log.d(TAG, "mRectSrc.bottom: " + mRectSrc.bottom);

                Log.d(TAG, "zoomX:  " + zoomX);
               Log.d(TAG, "zoomY: "  + zoomY);
               
               
               double dx = 0.5 * viewWidth - panX * bitmapWidth * zoomX;

                //This is the formula someone sugested...
              Log.d(TAG, "dx = 0.5 * viewWidth - panX * bitmapWidth * zoomX");

               Log.d(TAG, "dx = 0.5 * " + viewWidth + " - " +  panX + " * " + bitmapWidth + " * " + zoomX + " = " + dx);

               Log.d(TAG, "xo = (xt - dx) / zoomX");

               double xo = (mState.getTouchX() - dx) / zoomX;

                //Note mState.getTouchX() returns the X coordinate where the user touched the screen
              Log.d(TAG, "xo = (" + mState.getTouchX() + " - " + dx + ")" + "/" + zoomX + " = " + xo);

                //So in short, what SHOULD have been done to translate back to get the correct xo here?
              Log.d(TAG, "TouchX: " + mState.getTouchX() + "  Translated: " + xo);

               
            }
           
            canvas.drawBitmap(mBitmap, mRectSrc, mRectDst, mPaint);
        }
    }
6  Java Game APIs & Engines / JOGL Development / Re: Any corollary to this in JOGL? on: 2006-03-09 14:05:37
I cannot speak for any extra utilities, but as for core JOGL, I'm pretty sure there is no such thing to equate to CompressedGeometry.  It's simply a set of well-done bindings for Java (with some nicer extra things thrown in for cross-platform niceness and AWT integration and such).  OpenGL does not (as far as I'm aware) specify any compressed geometry things, so JOGL wouldn't.  I bet you'd be more than welcome, however, to create your own add-on library which does that! ^_^

--Scott

Ahh...yes, I bet you are right on that one!

Thanks for the reply.  That explains why I couldn't find anything like it (CompressedGeometry) in JOGL. 
7  Java Game APIs & Engines / JOGL Development / Any corollary to this in JOGL? on: 2006-03-08 21:56:46
There are some things in JOGL that Java3D does not yet support, but one thing that Java3D does give you is a CompressedGeometry class that allows you to compress models in Wavefront (.obj) format quite nicely.  Does JOGL have any such utility yet?  Huh

Thanks.
8  Game Development / Artificial Intelligence / Re: Steering behaviors. ¬†We need a Java version! on: 2005-01-07 12:21:35
Yes, that is Craig's site you are referring to.

The only problem is, the applet code was done while Craig was working for another company, and that company hasn't (and it doesn't seem likely it will) released the source to those applets!

Craig sent me to another place (Fuze3D) who has supposedly made the conversion, but they never responded to me (hmmnm...).

I cannot believe that someone hasn't done this already and made the code available to the open source community.  

This is something really needed for AI apps of many kinds!
9  Game Development / Artificial Intelligence / Steering behaviors.  We need a Java version! on: 2005-01-05 16:43:34
I have tried to get a Java version of Craig Reynolds C++ based steering behaviors code but have not had much luck.

I wrote Craig Reynolds and he passed me along to another person at Fuze3D who has not replied (BTW, Mr. Reynolds would like to have the ported code too it seems).

So does anyone know of a Java port for steering behaviors like OpenSteer?

It would seem almost essential for non trivial Java based games to use steering in some respect.  Surely someone has this done or is close to doing it and making it available to the open source community!
10  Java Game APIs & Engines / JOGL Development / Re: Jist3D - JOGL Based 3D Engine on: 2004-05-13 15:48:27
Ah..early June maybe?

Been waiting....and waiting.... Cry
11  Java Game APIs & Engines / Java 2D / Re: Drawing on top of a bitmap...basics please on: 2003-05-09 11:22:39
Cheesy

Thanks.  I'll do that.
12  Java Game APIs & Engines / Java 2D / Drawing on top of a bitmap...basics please on: 2003-05-08 12:50:15
I want to load an image (bitmap most likely, but maybe .gif as well...no big deal one way or the other) and on top of the image be able to draw lines, circles, and text.  The thing is I need to be able to move the lines, circles, and text without affecting the underlying image.

How is this done?


It would be GREAT if anyone had sample code, but I'd be really happy with just the high level aspects (use this class this way, then that one another way, etc.)

BTW, this will be done in a JSP.

Many thanks.
13  Java Game APIs & Engines / Java Sound & OpenAL / Anyone know when 3D sound will get supported? on: 2003-03-12 11:29:28
Most of the backbone seems to be in, but the wiring still has a ways to go since you can only select sterophonic or monaural sound.

Has anyone heard when full 3D sound support (ie, left right, left rear, right rear, center) sound support will go into Java?
14  Java Game APIs & Engines / Java 2D / Re: Showing old BufferedImage after rotate. Why? on: 2003-03-11 15:10:49
Thanks.  

I read that one years ago but I assumed at the time that it applied to multi-threaded apps since it was titled "Threads and Swing".
15  Java Game APIs & Engines / Java 2D / Re: Showing old BufferedImage after rotate. Why? on: 2003-03-11 11:51:38
That isn't the way I understood it.  I was always under the impression that you were safe in a single threaded application, and have never read anything that  mentions the use of invokeAndWait or invokeLater outside the context of a multi-threaded application.

Yes, there are multiple threads being run in a single threaded app, but these, it is my understanding, do not mess with the EventDispatch thread to cause it problems.

Thanks for setting me straight!  

Still, can someone point me to some documentation  (I looked on the Net, but couldn't find any) that says that all references to a Swing component to do things like show() must be done using invokeAndWait or invokeLater for a single threaded application?  I'd like to read it for myself to understand what is going on to require this in a single threaded application.

Thanks.

BTW, I've never had a problem with this, but then again I normally use multi-threaded apps too!
16  Java Game APIs & Engines / Java 2D / Re: Showing old BufferedImage after rotate. Why? on: 2003-03-10 10:50:41
Thanks for the reply, but it brings up a quesiton:

Given that the application is single threaded, do you still think that invokeLater or invokeAndWait are needed to update the swing components?

17  Java Game APIs & Engines / Java 2D / Showing old BufferedImage after rotate. Why? on: 2003-03-07 15:19:54
After I rotate a BufferedImage, I still see the old one.

I can flip (vertical, and horizontal) an image but when I try to scale or rotate it, the old image is still showing up. I've tried every repaint, remove, removeall, etc that I can think of but still have double vision!  Shocked

Note that if I resize the window large enough ( just a little movement won't do it) then the old image does go away!


Here is the code that I use to rotate a loaded BufferedImage:


public static BufferedImage rotateImage(BufferedImage bi)
{
BufferedImage new_bi = new BufferedImage( bi.getHeight(),
bi.getWidth(),
bi.getType());

Graphics2D g2d = new_bi.createGraphics();
AffineTransform at = g2d.getTransform();
AffineTransform rotation = new AffineTransform();
rotation.rotate(Math.PI / 2, bi.getWidth() / 2, bi.getHeight() / 2);

g2d.transform(rotation);

g2d.drawImage( bi,
                           null,
                           bi.getWidth() / 2 - new_bi.getWidth() / 2,
                          (bi.getHeight() / 2 - new_bi.getHeight() / 2) * -1);

g2d.setTransform(at);

return new_bi;
}


The code that displays the new BufferedImage that is returned from the rotateImage method looks like this

private void displayBufferedImage(BufferedImage bif)
{
jpMainPanel = new JPanel();
jpMainPanel.setLayout(new BorderLayout());
jpMainPanel.setOpaque(false);
setTitle("Display Program");


if(jlBackground != null)
{
//This doesn't help...but I tried it
getLayeredPane().remove(jlBackground);
getLayeredPane().repaint();

this.getContentPane().removeAll();
this.repaint();
}

jlBackground = new JLabel();

ImageIcon backImage = new ImageIcon(bif);

jlBackground.setIcon(backImage);
jlBackground.setBounds(0, 0, backImage.getIconWidth(), backImage.getIconHeight());
getLayeredPane().add(jlBackground, new Integer(Integer.MIN_VALUE));

setContentPane(jpMainPanel);

//Tried all of the following too...no help
jlBackground.repaint();
getLayeredPane().repaint();
jpMainPanel.repaint();
this.repaint();
this.getContentPane().repaint();
}

I think if I can get the Rotate to work, then the scale will follow the same principle.

Can anyone help me cure my double vision please?
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

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

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

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

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

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

BurntPizza (33 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (103 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
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!