WiiLi Wiki frontpage Include your post in the News Get links Hoteles Quito
WiiLi.org Forum Index WiiLi.org
a new revolution
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

IR
Goto page 1, 2  Next
 
Post new topic   Reply to topic    WiiLi.org Forum Index -> WiiremoteJ
View previous topic :: View next topic  
Author Message
Degen



Joined: 23 Sep 2007
Posts: 16

Digg It
PostPosted: Sat Mar 01, 2008 9:31 am    Post subject: IR

Hi this question doesn't really concern WiiremoteJ. In the test application at the IRInputReceived im not sure what the : in the loop does.

for (IRLight light : evt.getIRLights())

Is it a logic operator?

I did it like this but your code is mush nicer so I want to understand it Very Happy

Thx for answers!

light = new IRLight[4];
light = evt.getIRLights();
System.out.println("X:");
for(int i=0; i<4 && light[i] != null; i++){

System.out.println("X: "+light[i].getX());
System.out.println("Y: "+light[i].getY());
}
Back to top
View user's profile Send private message
guiguito



Joined: 16 Dec 2007
Posts: 14

Digg It
PostPosted: Sat Mar 01, 2008 11:48 am    Post subject:

if i'm correct, his code means his iterating over the lights.

it is exactly what you do, instead light in his loop his equal to light[i] in your loop.
His way is much nicer Very Happy
Back to top
View user's profile Send private message
Cha0s
Site Admin


Joined: 17 Jan 2007
Posts: 421

Digg It
PostPosted: Sat Mar 01, 2008 1:09 pm    Post subject:

Hehe. Yep, as of Java 5, there's a nice new for-each loop. Just be careful using it with threading. It works by creating an Iterator and Iterators aren't thread-safe. Wink
_________________
Cha0s
Back to top
View user's profile Send private message
Degen



Joined: 23 Sep 2007
Posts: 16

Digg It
PostPosted: Sat Mar 01, 2008 1:26 pm    Post subject:

Ok thx!
So you dont have to define the length before starting the loop? Will it loop for every IRLight objekt found in the event and store it in light?

Have I understod this right?
Back to top
View user's profile Send private message
Cha0s
Site Admin


Joined: 17 Jan 2007
Posts: 421

Digg It
PostPosted: Sat Mar 01, 2008 9:51 pm    Post subject:

Yep. It goes through each element in Iterable (that's an interface that means the thing can be iterated through. Arrays, ArrayLists, etc are all Iterable) and puts the value in light. Then you do something with it and it puts the next value in light, etc. until it goes through all the values in the Iterable.
_________________
Cha0s
Back to top
View user's profile Send private message
Shuzz



Joined: 14 Jan 2008
Posts: 12

Digg It
PostPosted: Tue Mar 04, 2008 8:19 am    Post subject: Re: IR

Degen wrote:
light = new IRLight[4];
light = evt.getIRLights();
System.out.println("X:");
for(int i=0; i<4 && light[i] != null; i++){

System.out.println("X: "+light[i].getX());
System.out.println("Y: "+light[i].getY());
}


Careful with that code: It is possible that e.g. when the Wiimote "sees" three lights that the second element in the array is null and the other three aren't.
Your code would stop going over the array when hitting the first null element and therefore might miss out on some IRLights.
Back to top
View user's profile Send private message
Degen



Joined: 23 Sep 2007
Posts: 16

Digg It
PostPosted: Wed Mar 05, 2008 11:29 am    Post subject:

I know,I dont use that any more it was my first try Razz

Thx for the tip!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    WiiLi.org Forum Index -> WiiremoteJ All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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


Powered by phpBB © 2001, 2005 phpBB Group