Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
19 June, 2013, 19:38:24 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: 1 [2] 3   Go Down
  Print  
Author Topic: Rotation- How does it work?? -  (Read 1047 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
Builderboy
Physics Guru
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Today at 08:32:53
Date Registered: 20 April, 2009, 00:28:53
Location: Ravenholm
Posts: 5645


Total Post Ratings: +589

View Profile
« Reply #15 on: 13 March, 2012, 20:12:32 »
+1

That is because you typed it in wrong Big frown You should be using this code:


1
2
x = (sp[c].X-xc)*cosd(d) - (sp[c].Y-yc)*sind(d) + xc;
y = (sp[c].X-xc)*sind(d) + (sp[c].Y-yc)*cosd(d) + yc;

Note the plus sign instead of the minus symbol
Logged

nxtboy III
LV8 Addict (Next: 1000)
********
Offline Offline

Last Login: 22 May, 2013, 02:53:41
Date Registered: 30 March, 2011, 22:57:58
Posts: 784


Topic starter
Total Post Ratings: +23

View Profile WWW
« Reply #16 on: 13 March, 2012, 20:40:01 »
0

Yeah, I did that and added some parentheses and BOOM!!! It worked!!!! Thanks!! Cheesy
Logged

Builderboy
Physics Guru
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Today at 08:32:53
Date Registered: 20 April, 2009, 00:28:53
Location: Ravenholm
Posts: 5645


Total Post Ratings: +589

View Profile
« Reply #17 on: 13 March, 2012, 20:44:22 »
0

Yay! Glad I could help ^^
Logged

nxtboy III
LV8 Addict (Next: 1000)
********
Offline Offline

Last Login: 22 May, 2013, 02:53:41
Date Registered: 30 March, 2011, 22:57:58
Posts: 784


Topic starter
Total Post Ratings: +23

View Profile WWW
« Reply #18 on: 13 March, 2012, 20:46:45 »
0

I tried rotating a picture by getting all the points. It works, but is really slow. Could I speed this up?
Logged

Builderboy
Physics Guru
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Today at 08:32:53
Date Registered: 20 April, 2009, 00:28:53
Location: Ravenholm
Posts: 5645


Total Post Ratings: +589

View Profile
« Reply #19 on: 13 March, 2012, 20:48:23 »
0

The best thing you could do would be to move the cos() and sin() outside the loop, since you really only need to calculate them once per rotation.  Just precalculate them, place them into variables of their own, and use those variables instead Smiley 
Logged

nxtboy III
LV8 Addict (Next: 1000)
********
Offline Offline

Last Login: 22 May, 2013, 02:53:41
Date Registered: 30 March, 2011, 22:57:58
Posts: 784


Topic starter
Total Post Ratings: +23

View Profile WWW
« Reply #20 on: 13 March, 2012, 20:49:33 »
0

I tried that, but for some odd reason, it messes up. Sad
Logged

Builderboy
Physics Guru
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Today at 08:32:53
Date Registered: 20 April, 2009, 00:28:53
Location: Ravenholm
Posts: 5645


Total Post Ratings: +589

View Profile
« Reply #21 on: 13 March, 2012, 20:55:57 »
0

Post your code again?
Logged

nxtboy III
LV8 Addict (Next: 1000)
********
Offline Offline

Last Login: 22 May, 2013, 02:53:41
Date Registered: 30 March, 2011, 22:57:58
Posts: 784


Topic starter
Total Post Ratings: +23

View Profile WWW
« Reply #22 on: 13 March, 2012, 20:57:57 »
0

Ok.

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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
float magnitude(int x1,int y1,int x2,int y2)
{
 return(sqrt(pow(x2-x1,2) + pow(y2-y1,2)));
}

struct floatpoint
{
 float X;
 float Y;
};

byte Data[];
byte Line;
byte offset;

//LocationType poly[] = {{10,10},{
//LocationType sp[]={{10,10},{10,30},{5,27},{10,30},{15,27},{10,30},{10,25},{5,22},{10,25},{15,22},{10,25},{10,20},{5,17},{10,20},{15,17},{10,20}};
floatpoint spf[];


byte __ips_masks[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};

byte isPixelSet(byte Xx, byte Yy)
{
  Line = (63-Yy & 0xF8) / 8;
  offset = Yy % 8;
  GetDisplayNormal(Xx, Line, 1, Data);
  return Data[0] & __ips_masks[offset];
}

task main()
{
 float x,y;
 int xc,yc;
// int dis;
 //x=0;
 //y=50;
 xc= 40;
 yc=40;
 float deg;
 int d;
 //float dis[];
 float c,s;
 int xt1,yt1,xt2,yt2;
 int l;
 //int arrs = ArrayLen(sp);
 int bul = 0;
// ArrayInit(dis,0,arrs);
// ArrayInit(spf,0,arrs);
//RectOut(50,50,3,3);
GraphicOut(50,40,"squirt.ric");
 for(int c=0; c < 100; c++)
 {
  for(int d=0; d < 64; d++)
  {
   if(isPixelSet(c,d))
   {
    l++;
   }
  }
 }
 ArrayInit(spf,0,l);
  for(int c=0; c < 100; c++)
 {
  for(int d=0; d < 64; d++)
  {
   if(isPixelSet(c,d))
   {
    spf[bul].X = c;
    spf[bul].Y = d;
    bul++;
   }
  }
 }
 PlayToneEx(600,30,1,0);
/*   for(int c=0; c < l; c++)
  {
  // dis[c] = magnitude(xc,yc,sp[c].X,sp[c].Y);
   //sp[c].X += 30;
   //sp[c].Y += 30;
   if(
   spf[c].X = sp[c].X;
   spf[c].Y = sp[c].Y;
   }*/

 while(1)
 {
 // x=x*(cosd(30))-y*(sind(30));
  //y=x*(sind(30))+y*(cosd(30));
 // x = cosd(deg--)*magnitude(0,0,x,y);
 // y = sind(deg)*magnitude(0,0,x,y);
 // x -= xc;
  //y -= yc;
  c = cosd(d);
  s = sind(d);
  for(int c=0; c < l; c++)
  {
 // deg = atan2d((sp[c].Y-yc),(sp[c].X-xc));
  // xt1 = ((spf[c].X - xc) * c);
   //yt1 = ((spf[c].Y - yc) * s);
   //xt2 = ((spf[c].X - xc) * s);
   //yt2 = ((spf[c].Y - yc) * c);
   //x = (xt1 - yt1) + xc;
   //y = (xt2 + yt2) + yc;
  // x = sqrt(pow((spf[c].X - xc),2) + pow((spf[c].Y - yc),2))*cosd(atand(spf[c].X - xc)/(spf[c].Y - yc)+ 5)+ xc;
  // y = sqrt(pow((spf[c].X - xc),2) + pow((spf[c].Y - yc),2))*sind(atand(spf[c].X - xc)/(spf[c].Y - yc)+ 5)+ yc;
  //y = dis[c]*sind(deg + 3)+yc;
  x = ((spf[c].X-xc)*c) - ((spf[c].Y-yc)*s) + xc;
  y = ((spf[c].Y-yc)*c) + ((spf[c].X-xc)*s) + yc;
  spf[c].X = x;
  spf[c].Y = y;
  //sp[c].X=spf[c].X;
  //sp[c].Y=spf[c].Y;
  }
  if(ButtonPressed(BTNRIGHT,0))
  d = -5;
  else
  d = 0;
 // sp[0].X=1;
  //CircleOut(x,y,10);
//  PolyOut(sp);
SetDisplayFlags( DISPLAY_REFRESH_DISABLED);
  ClearScreen();
  for(int c=0; c < l; c++)
  {
   PointOut(spf[c].X,spf[c].Y);
  }
   //PolyOut(sp);
  SetDisplayFlags( DISPLAY_ON | DISPLAY_REFRESH);

  Wait(17);
 }
}
Logged

Builderboy
Physics Guru
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Today at 08:32:53
Date Registered: 20 April, 2009, 00:28:53
Location: Ravenholm
Posts: 5645


Total Post Ratings: +589

View Profile
« Reply #23 on: 13 March, 2012, 21:00:11 »
0

For future reference you only have to post the relevant part of your code, not the whole thing Tongue Could it be that the issue is coming from the fact that your for loop variable is also named C?
Logged

nxtboy III
LV8 Addict (Next: 1000)
********
Offline Offline

Last Login: 22 May, 2013, 02:53:41
Date Registered: 30 March, 2011, 22:57:58
Posts: 784


Topic starter
Total Post Ratings: +23

View Profile WWW
« Reply #24 on: 13 March, 2012, 21:02:31 »
0

Wow, I can't believe I did not think of that!! Frustrated Now it works. Smiley
Though it doesn't seem to go much faster. Sad

You should help me program stuff...
« Last Edit: 13 March, 2012, 21:02:48 by nxtboy III » Logged

Builderboy
Physics Guru
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Today at 08:32:53
Date Registered: 20 April, 2009, 00:28:53
Location: Ravenholm
Posts: 5645


Total Post Ratings: +589

View Profile
« Reply #25 on: 13 March, 2012, 21:03:36 »
0

Yeah rotation is slow in general without stuff like Graphics Cards :[ unfortunately I don't think you will be able to get much faster than you have it currently.
Logged

nxtboy III
LV8 Addict (Next: 1000)
********
Offline Offline

Last Login: 22 May, 2013, 02:53:41
Date Registered: 30 March, 2011, 22:57:58
Posts: 784


Topic starter
Total Post Ratings: +23

View Profile WWW
« Reply #26 on: 13 March, 2012, 21:05:09 »
0

yeah....
But you seem to be good at this language. You should help me with other stuff...
Logged

Builderboy
Physics Guru
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Today at 08:32:53
Date Registered: 20 April, 2009, 00:28:53
Location: Ravenholm
Posts: 5645


Total Post Ratings: +589

View Profile
« Reply #27 on: 13 March, 2012, 21:06:53 »
0

On the contrary I have little knowledge about that language, you were just lucky the issues you were having were general issues and not programming specific issues.  And if you ever have any more issues feel free to post about them and I will see what I can do ^^
Logged

nxtboy III
LV8 Addict (Next: 1000)
********
Offline Offline

Last Login: 22 May, 2013, 02:53:41
Date Registered: 30 March, 2011, 22:57:58
Posts: 784


Topic starter
Total Post Ratings: +23

View Profile WWW
« Reply #28 on: 13 March, 2012, 21:14:47 »
0

ok, sure. Wink
Logged

christop
LV3 Member (Next: 100)
***
Offline Offline

Gender: Male
Last Login: 13 April, 2013, 04:04:55
Date Registered: 26 February, 2011, 19:58:44
Location: Arizona, USA
Posts: 87

Total Post Ratings: +20

View Profile
« Reply #29 on: 13 March, 2012, 21:43:23 »
0

I tried rotating a picture by getting all the points. It works, but is really slow. Could I speed this up?
Are you trying to rotate a raster (bitmap) image? That's understandably going to slow because a raster image contains many points.

It might be a lot quicker to rotate it by shearing the bitmap three times: http://www.ocf.berkeley.edu/~fricke/projects/israel/paeth/rotation_by_shearing.html

Or you could try using fixed-point instead of floating-point arithmetic using your current algorithm because your system might not have floating-point hardware, so it has to be emulated in software (which is slooooow).
Logged

Christopher Williams
Pages: 1 [2] 3   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.304 seconds with 30 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.