Home | Forums | What's new | Resources | |
Polygon point data type with Arrays |
Omni - Jan 8, 2005 |
1 | 2 | Next> |
antime | Jan 8, 2005 | |||
That syntax is legal only when initializing arrays/structs. Elsewhere you have to assign to each element separately or use a memcopy or similar. |
Omni | Jan 8, 2005 | |||
Well, I guess I'll get used to it. |
Omni | Jan 9, 2005 | |||
I think I understand the syntax, and I figured out the problem. I was typing "pntb1" instead of "pntbl". I realized it stood for table, but I forgot to change my 1 to an L. ...oops |
Omni | Jan 9, 2005 | |||
I ran into something else...and I believe I know how typecasting should work, but...well, anyway... It's two problems. 1. A simple function to assign values of a POINT SGL type... ------ void oVertex(POINT *point, float x, float y, float z) { //Set the coordinates for a Vertex, or a POINT type structure. point[0] = (FIXED)18; point[1] = (FIXED)18; point[2] = (FIXED)18; } ------ When I compile this, on each of the three lines GCC returns "incompatible types in assignment". I don't see how, as each element of POINT is a FIXED...and I really have no clue here. EDIT: I really suppose I should use toFIXED instead of typecasting FIXED, but it still gives me the same error. 2. Another function, similar, to add a POINT type to a PDATA vertex list. ------- void oModel_SetVertex(PDATA *model, int vertex, POINT *point) { //Set the vertex for a certain point in the point list of a model. //Out of bounds, return; if (vertex > (*model).nbPoint-1) return; (*model).pntbl[vertex][0] = (FIXED)point[0]; (*model).pntbl[vertex][1] = (FIXED)point[1]; (*model).pntbl[vertex][2] = (FIXED)point[2]; } ------- This one compiles fine, but I keep getting warnings about "passing argument 3 from incompatible pointer type" whenever I use it. How is this? I know my problems have to be in typecasting, but I can't figure out what I'm doing wrong...I've looked up typecasting on some reference websites, and I can't quite understand what I'm not doing right. EDIT: fixed. I also need to go look up whatever an "Lvalue" is, because whatever it is, I apparently can't typecast it right, either... |
slinga | Jan 9, 2005 | ||||
I've never used polygons before, but to set sprite coordinates I do this:
Code:
The toFIXED function converts an integer value to whatever it is the saturn uses. Give that toFixed() function a go instead of trying to typecast it. |
Omni | Jan 9, 2005 | |||
But shouldn't x, y, and z be float? (Oh, right, sprite values) Ah, well, I'll try it. I figured out some interesting things about problem #2. When I use two array parameters in a function, and assign the values of one to another: void SetArray(int *dest, int *source) If I access the individual values of the Source array (to assign it), it gives me a warning unless I put "&" in front of the array. But it doesn't give me a warning if I don't put "&" in front of dest; in fact, it gives me a warning if I do! If I don't assign the individual values of Source, but just assign Source's pointer, then I have to leave the "&" off of source or it gives me a warning. ...I'm not sure I understand that, but apparently pointing to an array is supposed to be hard to grasp for the beginner, so I guess I'll get it eventually... Any of these warnings are regarding the "trying to assign incompatible pointer type". EDIT: I also figured out a solution to problem 1. ------- void oVertex(POINT *point, float x, float y, float z) { //Set the coordinates for a Vertex, or a POINT type structure. (*point)[0] = (FIXED)x; (*point)[1] = (FIXED)y; (*point)[2] = (FIXED)z; } ------- I had to set the assignment to assign to a space pointed to by "point", and I had to pass point with & to get the address (even though point was an array). ...I think that's how it works. |
antime | Jan 9, 2005 | ||||
The issue with your problem one, if you didn't figure it out yourself, is that in the code you first posted you were trying to assign to elements in a POINT array, rather than to the elements of a single POINT. By using the indirection operator (*) you say that you are trying to access elements of the POINT array in the given pointer. You must do this in your second function (oModel_SetVertex) as well or you'll end up assigning the addresses of elements of some fictional POINT array instead of the coordinates you want. Also, if you have a pointer to a struct, C has a shorthand syntax for accessing members of that struct:
Code:
Finally, you should never use floats or doubles directly in your code. The only place they're allowed is as constant arguments to the toFIXED macro. The point of this is that converting them as constants lets the compiler do it beforehand, which means you can avoid having to include costly floating-point emulation in your program. Casting to a FIXED is also not the same as using the conversion macro, as casting to an integral type will simply discard the fractional part. |
Omni | Jan 9, 2005 | |||
I remade it using macros rather than typecasting. Thanks for the help, hopefully I won't run into too many array related problems anymore. |
RockinB | Jan 9, 2005 | |||
You got the option to convert existing .DXF 3d models to C include files(named .SGL on Mac and .MDL on Windows). On antimes page you can find the official SEGA 3d editor, which on Mac can open SG3 and DXF files(although the later never worked for me) and on windows got the command line tool DXF2SG3.EXE for conversion. Both of them allow Saturn specific 3d settings and the export to C includes. The SEGA 3D format SG3 is a textual description, like many other formats do. There was this 3D creation software, which got Saturn support through export plugins, I guess. Can someone help me how it was called? Maybe Lightwave 3D? I tried to get it, but never succeeded. |
Omni | Jan 9, 2005 | |||
Hmm. Spiffy. |
antime | Jan 9, 2005 | |||
I believe most modelling packages that targeted consoles also targeted the Saturn at some point. Eg. Softimage 3D... and Alias|Wavefront.... |
RockinB | Jan 10, 2005 | ||||
Now that you list it: I meant Softimage3D(not Lightwave3D), of course. Shit, we need those apps RIGHT NOW! :smash |
antime | Jan 10, 2005 | |||
AFAIK Alias|Wavefront was only available on SGI workstations at that time, better luck with Softimage. Writing exporters for Blender or some other current modeller would still be more valuable, IMO. |
Omni | Jan 18, 2005 | |||
I'm back, with a new data type problem...this has nothing to do with arrays, I'm sure of it I've defined a function before called oModel_SetVertex(PDATA *model, int vertex, int x, int y, int z) Which sets the correct vertex in the point table "pntbl" of PDATA type "model" to the given coordinates. The problem is, my finished polygon, when I was done, wouldn't display. I wondered what the problem is and I decided to make a function to print out all the data on my PDATA models, essentially an slPrintPDATA(PDATA *model). Anyway, I did this, and I found out something unusual. When I use ----------- slPrintFX(toFIXED(-10.0), slLocate(9, 6)); ----------- The Saturn prints -10.0 on the screen. But, when I use... ----------- (*model).pntbl[0][0] = toFIXED(-10.0); slPrintFX((*model).pntbl[0][0], slLocate(9, 6)); ----------- to assign the X coordinate of the model's first vertex, the Saturn prints "8192.00832" on the screen. Why is the directly assigned coordinate value changed so drastically? There's nothing else in my code messing with that value, and I figure this is why I can't get my polygons to display -- they're off the other edge of the visual world. Does anyone know what I'm doing wrong? EDIT: ------- Here's something new. It turns out, the above code actually works. However, if I do the following... ----------- (*model).pntbl[0][0] = toFIXED(-10.0); (*model).pntbl[0][1] = toFIXED(10.0); ----------- Then the vertex coordinate number begins to mess up. Why does assigning a second element alter the value of the first? Is there an important lesson I'm missing here? Perhaps it is an array problem after all. As a side note, I also tried assigning values used the constant X, Y, and Z values in the POINT arrays, ie pntbl[0][X] = toFIXED(-10.0), but that doesn't solve anything. |
antime | Jan 18, 2005 | |||
Try to reduce your program to a minimal testcase and post that, it will be far quicker than us trying to guess from the random bits you have posted. |
Omni | Jan 18, 2005 | ||||
Right.
Code:
The problem is that I believe when my VertexSet applies coordinates to all three array positions, they end up affecting each other. I don't know why. Maybe I'm messing up on a missing type cast or something. But this is enough to bring the error. Note: When I only assign one coordinate, such as X, then it works fine. Values are only weird when I try to assign all three coordinates. |
RockinB | Jan 18, 2005 | |||
Hi Omni! The POINT, POLYGON and ATTR variables are what you named them like: temporary. The storage is lost and possibly used for other stuff after the function oModel_Setup() is exited. As you want to create those variables/arrays of dynamic size, you should use malloc to allocate memory. Something like: model->pntbl = (POINT *)malloc(num_points * sizeof(POINT)); |
1 | 2 | Next> |