### Author Topic: Vector Editor  (Read 3972 times)

• Guest
##### Vector Editor
« on: 2010-Jul-23 »
Here is the beta of my vector editor.

Its all pretty self-explanatory really - Add will add the current node type, Delete will delete it,  Move will move a node whilst Insert will add the current node, but resort the node list into ascending X and Y values.

As all the node positions are held in integers, you will find that rotating an object will cause rounding errors and thus slightly affect the objects shape.

Let me know of any problems...

#### Wampus

• Prof. Inline
• Posts: 1004
##### Re: Vector Editor
« Reply #1 on: 2010-Jul-23 »
Couldn't find any problems other than the rounding error you mentioned. I can think of vital & helpful features you could add but I'm sure you've already considered them as things you might include later.

This is looking like a very useful little proggy for creating 2D wire vectors for games. You are awesome.

• Guest
##### Re: Vector Editor
« Reply #2 on: 2010-Jul-23 »
Here is a little test program I've started to test the output.  It could do with being optimised a bit :

Code: (glbasic) [Select]
`// --------------------------------- //// Project: TestVector// Start: Friday, July 23, 2010// IDE Version: 8.036GLOBAL graphic AS TVectorIF graphic.TVector_Load("Media/Test.VEC")=FALSE DEBUG "Error!"ENDIFLOCAL scale=1.0LOCAL x,y,anglex=100y=100angle=0.0WHILE TRUE graphic.TVector_Display(x,y,angle,scale) SHOWSCREEN INC scale,MOUSEAXIS(2) INC x,MOUSEAXIS(0)*0.5 INC y,MOUSEAXIS(1)*0.5 INC angle,0.25WEND`
Code: (glbasic) [Select]
`// --------------------------------- //// Project: TestVector// Start: Friday, July 23, 2010// IDE Version: 8.036TYPE tCoord x yENDTYPETYPE tGroup pos[] AS tCoordENDTYPETYPE tObject author\$ objectName\$ handleX%;handleY% groups[] AS tGroupENDTYPETYPE TVector vectorObject AS tObject SECTION_OBJECT\$ = "OBJECT" KEY_AUTHOR\$ = "AUTHOR" KEY_NAME\$ = "NAME" KEY_HANDLE\$ = "HANDLE" KEY_INUSE\$ = "INUSE" KEY_DATA\$ = "DATA" FUNCTION TVector_Initialise%: DIM self.vectorObject.groups[0] ENDFUNCTION FUNCTION TVector_Load%:fileName\$ LOCAL vector AS tCoord LOCAL group AS tGroup LOCAL temp\$,loop%,error\$ LOCAL array\$[],dataArray\$[] IF DOESFILEEXIST(fileName\$) TRY INIOPEN fileName\$ self.vectorObject.author\$=INIGET\$(self.SECTION_OBJECT\$,self.KEY_AUTHOR\$,"") self.vectorObject.objectName\$=INIGET\$(self.SECTION_OBJECT\$,self.KEY_NAME\$,"") DIM array\$[0] DIM self.vectorObject.groups[0] // Get the handle positions - for information only IF SPLITSTR(INIGET\$(self.SECTION_OBJECT\$,self.KEY_HANDLE\$,"0,0"),array\$[],",")=2 self.vectorObject.handleX%=INTEGER(array\$[0]) self.vectorObject.handleY%=INTEGER(array\$[1]) ELSE // Ignore anything else and carry on ENDIF // Now we get a list of data sections that are in use DIM array\$[0] IF SPLITSTR(INIGET\$(self.SECTION_OBJECT\$,self.KEY_INUSE\$,""),array\$[],",")>0 FOREACH temp\$ IN array\$[] DIM dataArray\$[0] DIM group.pos[0] IF SPLITSTR(INIGET\$(self.SECTION_OBJECT\$,self.KEY_DATA\$+temp\$,""),dataArray\$[],",")>0 FOR loop%=0 TO BOUNDS(dataArray\$[],0)-2 STEP 2 vector.x=INTEGER(dataArray\$[loop%])*1.0 vector.y=INTEGER(dataArray\$[loop%+1])*1.0 DIMPUSH group.pos[],vector NEXT // Push group into array DIMPUSH self.vectorObject.groups[],group ELSE THROW "No data in key : "+self.KEY_DATA\$+temp\$ ENDIF NEXT ELSE THROW "No data to be found!" ENDIF INIOPEN "" RETURN TRUE CATCH error\$ DEBUG error\$ STDERR error\$ INIOPEN "" RETURN FALSE FINALLY ELSE RETURN FALSE ENDIF ENDFUNCTION FUNCTION TVector_Display%:x,y,angle,scale LOCAL group AS tGroup LOCAL coords%,size% LOCAL ox,oy,nx,ny,n%,cv,sv cv=COS(angle) sv=SIN(angle) FOREACH group IN self.vectorObject.groups[] size%=BOUNDS(group.pos[],0) FOR loop%=0 TO size%-1 ox=(cv*group.pos[loop%].x*scale)-(sv*group.pos[loop%].y*scale) oy=(cv*group.pos[loop%].y*scale)+(sv*group.pos[loop%].x*scale) n%=loop%+1 IF n%>=size% THEN n%=0 nx=(cv*group.pos[n%].x*scale)-(sv*group.pos[n%].y*scale) ny=(cv*group.pos[n%].y*scale)+(sv*group.pos[n%].x*scale) DRAWLINE x+ox,y+oy,x+nx,y+ny,RGB(255,255,255) NEXT NEXT ENDFUNCTIONENDTYPE`
This uses just lines for a no-thrills display.  I'll be doing a polyvector version later...

Quote
I can think of vital & helpful features you could add but I'm sure you've already considered them as things you might include later.
Let me know what you think is vital!

Quote
You are awesom
That is so true!

« Last Edit: 2010-Aug-25 by MrTAToad »

#### Wampus

• Prof. Inline
• Posts: 1004
##### Re: Vector Editor
« Reply #3 on: 2010-Jul-23 »
Even though REMOVE will take away the last x,y point an UNDO feature would be very useful, especially a successive UNDO feature so many steps can be retraced. Very few people remember to save at every major step of what they're working on.

What I would see as helpful but not vital is this: as well as ADD and INSERT, a MIDPOINT function would be cool. It would add a new x,y point between the nearest two other points, so you can add more complexity to shapes.

• Guest
##### Re: Vector Editor
« Reply #4 on: 2010-Jul-23 »
Some good suggestions there!

I'll have to implement a nearest neighbour search for a MIDPOINT function, but it shouldn't be too hard   However, the INSERT function may do what you want - it resorts all the nodes according to the X & Y positions...
« Last Edit: 2010-Jul-24 by MrTAToad »

• Guest
##### Re: Vector Editor
« Reply #5 on: 2010-Jul-23 »
This is an example when using POLYVECTOR

Including is the updated code...

I dont know how many vector graphics can be handled, although, based on Scramble, it should be quite a few...

Now updated to be compatible with V8 - but see my later post

« Last Edit: 2010-Aug-25 by MrTAToad »

#### Bursar

• Mr. Drawsprite
• Posts: 63
##### Re: Vector Editor
« Reply #6 on: 2010-Aug-25 »
I figured I'd give GLB a look now there's a free version, but I've into a problem when trying to compile the code for the Vector Test. I get the following:
Code: (glbasic) [Select]
`GPC - GLBasic Precompiler V.8.044 SN:49df697f - 2D, WIN32"TestVector.gbas"(0) warning : note : TYPE TVector is not declared"TestVector.gbas"(0) warning : note : TYPE TVector is not declared"TestVector.gbas"(0) warning : note : TYPE TVector is not declared"..\VecEdit2\MiscRoutines.gbas"(5) warning : Demo mode: This command would require "GLBasic SDK premium" "TVector.gbas"(107) error : call to undefined function : TVector_GetNextIndex`
The offending line is:
Code: (glbasic) [Select]
`n%=TVector_GetNextIndex(loop%,size%)`in the function TVector_Display%

I can compile the code forthe vector editor with no problem, but the test app won't compile. The .exe version of it runs OK and displays the test vector. Not sure if there's an issue with compatibility with v8 of GLB, or it's something to do with me only running the free versio. Ofcourse I might just need to do something else before the code will compile.

• Guest
##### Re: Vector Editor
« Reply #7 on: 2010-Aug-25 »
Those are just warning messages - hopefully they will be removed soon-ish.

I've updated and re-posted the original code, so grab that again and it should work.

« Last Edit: 2010-Aug-25 by MrTAToad »

#### Bursar

• Mr. Drawsprite
• Posts: 63
##### Re: Vector Editor
« Reply #8 on: 2010-Aug-25 »
Thanks, I'll give it a go later on.

#### Bursar

• Mr. Drawsprite
• Posts: 63
##### Re: Vector Editor
« Reply #9 on: 2010-Aug-25 »
Still get some warnings, but it compiles and runs great now