Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Problem with Graphics2D

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Evil_Intentions
Expert Cheater
Reputation: 65

Joined: 07 Jan 2010
Posts: 214

PostPosted: Thu Jun 16, 2011 7:42 pm    Post subject: Problem with Graphics2D Reply with quote

I'm making a fractal drawing program using Java. The fractals can have variable angles at each turn. If I keep the angle at 90, everything is fine. If I use ANY other angle amount, a whole slew of problems arise. I'm drawing to a panel which is within a scrollPane. The panel automatically resizes to the fractal after creating bounds, and the scrollPane allows you to look over the entire fractal. If The angle is kept at 90, I can scroll across perfectly fine. If the angle is anything else, scrolling across will delete that part of the fractal. The fractal may also be drawn in different locations, or not at all.

I don't think it's a problem with my math, as I'm multiplying the angle by degrees per radian to get my direction before drawing, so whatever happens to an angle of say 110 also happens to the 90 degree angle.

I've basically been ripping my brains out for the past 2 hours. If this isn't a common or obvious problem, I'll gladly post code.

Thanks guys.

EDIT: I just tried a quick test with the angle set to 60, the fractal would draw and very quickly be erased every single time. Setting the angle to 89 would cause the boundaries to be off, and scrolling over it causes it to disappear at that part.
Back to top
View user's profile Send private message
Cryoma
Member of the Year
Reputation: 198

Joined: 14 Jan 2009
Posts: 1819

PostPosted: Thu Jun 16, 2011 9:26 pm    Post subject: Reply with quote

So 45 and 180 do what?
I'm good with math but I have no idea what you're doing here really, are their any formulas?
Back to top
View user's profile Send private message
Evil_Intentions
Expert Cheater
Reputation: 65

Joined: 07 Jan 2010
Posts: 214

PostPosted: Thu Jun 16, 2011 9:37 pm    Post subject: Reply with quote

Cryoma wrote:
So 45 and 180 do what?
I'm good with math but I have no idea what you're doing here really, are their any formulas?


those are angle amounts, they're used like this to calculate what line to draw.

Code:
g2d.draw(new Line2D.Double(x,y,x+length*Math.cos(radPerDeg*angle),y+length*Math.sin(radPerDeg*angle)));


where g2d is my graphics2D within the paintComponent method of my panel.
length is the chosen length to move.
radPerDeg is radians per degree.
angle is the angle; 90, 180, 45, whatever
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Fri Jun 17, 2011 3:57 am    Post subject: Reply with quote

i suggest if you want someone to test this for you you get it down to the simplest case. ie. make a project that only reproduces this behaviour and nothing else and someone like me will likely look into it when they have time
Back to top
View user's profile Send private message
b6oy
Newbie cheater
Reputation: 0

Joined: 21 Sep 2009
Posts: 10

PostPosted: Fri Jun 17, 2011 2:03 pm    Post subject: Reply with quote

did you use repaint() ?
Back to top
View user's profile Send private message
Evil_Intentions
Expert Cheater
Reputation: 65

Joined: 07 Jan 2010
Posts: 214

PostPosted: Fri Jun 17, 2011 4:30 pm    Post subject: Reply with quote

Slugsnack wrote:
i suggest if you want someone to test this for you you get it down to the simplest case. ie. make a project that only reproduces this behaviour and nothing else and someone like me will likely look into it when they have time


Well now I'm just stumped. I went to recreate it. Made just a JFrame with a Scrollpane containing a panel. I overrided the paintComponent method. In general did everything just like my fractal program. I had it draw 2 lines using Line2D.double(). One with whole numbers, the other with all fractional numbers. I was able to scroll over both completely fine.

I think maybe I'm doing something wrong with my variable for angle. I'll see.

EDIT: See, this is why I need to get sleep before trying some things. I was forgetting to reset the starting x and y in the paintComponent method. Apparently angles with multiples of 90 don't recreate the problem.

All fixed now Very Happy
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Fri Jun 17, 2011 4:56 pm    Post subject: Reply with quote

this is a fundamental concept in fixing bugs. attempt to isolate just the code which could be affecting it. often it's something dumb and you can see it clearly if you do this. in the other cases at least you have a clear example to show people who will have the ability to fix it
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites