PolyOut
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
PolyOut
Can someone please post an example of how to use PolyOut in NXC? According to the documentation, you are supposed to pass it an array in the format of x0, y0, x1, y1, x2, y2, ... xn, yn. However, I can't seem to get it to work. The only way I can get PolyOut to display anything but a singe pixel at 0,0 is to declare the array as "LocationType", and then the array acts as a constant (I can't change the values). The program needs to be able to change the values of the array during execution.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: PolyOut
Seems that is the only type of array it will accept - http://bricxcc.sourceforge.net/nbc/nxcd ... 1ef4c.html
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: PolyOut
I figured it out. It wants a 2D array, like this: int PolyArray[3][2] = {{50,40},{50,45},{60,50}};
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: PolyOut
Matt,
I don't think that is right. It wants a 1-d array of LocationType structs where each element in the 1-d array has an x and a y value. If you posted some code that tries to use the LocationType which doesn't work I can help fix it so that it does. I think you are getting lucky that NXC and the underlying firmware are not as type-strict as they ought to be. You definitely should not be using a 2d array.
Can you explain what you mean by saying that you can't change the values of the array if it is declared as LocationType? Do you get a compiler error?
John Hansen
I don't think that is right. It wants a 1-d array of LocationType structs where each element in the 1-d array has an x and a y value. If you posted some code that tries to use the LocationType which doesn't work I can help fix it so that it does. I think you are getting lucky that NXC and the underlying firmware are not as type-strict as they ought to be. You definitely should not be using a 2d array.
Can you explain what you mean by saying that you can't change the values of the array if it is declared as LocationType? Do you get a compiler error?
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Re: PolyOut
This code compiles fine for me and I am fairly confident that it works correctly too:
Note that there are many different ways that you can modify the elements in myPoints. One way is as I show above. You can also define a LocationType variable, set its X and Y members and assign it into an array element using myPoints[0] = tmpPoint; You can also directly modify every X and Y value in every LocationType struct within the array in a single operation using myPoint += 10; // add 10 to each field in each element. I am not 100% sure that works but fairly confident that it does. You can also add a tmpPoint to each element in the array using myPoints += tmpPoint. Again, not entirely certain what that does inside the firmware but there is a decent chance that it does something that makes sense. I'd test it but I don't have any NXTs with me right now. You could also add two arrays of LocationType together or an array of LocationType with an array of integers. The firmware tries to figure out what the sensible thing to do is in all of these cases.
John Hansen
Code: Select all
LocationType myPoints[] = {16,16, 8,40, 32,52, 20,36, 52,36, 56,52, 64,32, 44,20, 24,20};
task main()
{
PolyOut(myPoints, false);
Wait(SEC_2);
ClearScreen();
for(int i=0;i<10;i++) {
PolyOut(myPoints, DRAW_OPT_LOGICAL_XOR|DRAW_OPT_FILL_SHAPE);
Wait(SEC_1);
}
myPoints[0].X = 10;
myPoints[0].Y = 10;
PolyOut(myPoints, true|DRAW_OPT_FILL_SHAPE);
Wait(SEC_2);
ClearScreen();
for (int i=0;i<100;i++) {
PolyOut(myPoints, DRAW_OPT_LOGICAL_XOR|DRAW_OPT_FILL_SHAPE);
Wait(MS_100);
}
Wait(SEC_1);
}
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: PolyOut
Alright, I'll rewrite my code to use something like myPoints[0].X = 10; and myPoints[0].Y = 10;
Thanks for the help.
BTW, I made a pressure gauge with a needle (on the LCD), and wanted it to be more than just a line (I wanted a filled-in shape). PolyOut seems to work just fine, now that I know how to set the values on the fly.
Thanks for the help.
BTW, I made a pressure gauge with a needle (on the LCD), and wanted it to be more than just a line (I wanted a filled-in shape). PolyOut seems to work just fine, now that I know how to set the values on the fly.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Who is online
Users browsing this forum: No registered users and 7 guests