Vector Editor

Previous topic - Next topic

MrTAToad

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...



[attachment deleted by admin]

Wampus

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.  :nw:

MrTAToad

#2
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.036

GLOBAL graphic AS TVector

IF graphic.TVector_Load("Media/Test.VEC")=FALSE
DEBUG "Error!"
ENDIF

LOCAL scale=1.0
LOCAL x,y,angle

x=100
y=100
angle=0.0
WHILE 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.25
WEND


Code (glbasic) Select
// --------------------------------- //
// Project: TestVector
// Start: Friday, July 23, 2010
// IDE Version: 8.036
TYPE tCoord
x
y
ENDTYPE

TYPE tGroup
pos[] AS tCoord
ENDTYPE

TYPE tObject
author$
objectName$
handleX%;handleY%
groups[] AS tGroup
ENDTYPE

TYPE 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
ENDFUNCTION
ENDTYPE


This uses just lines for a no-thrills display.  I'll be doing a polyvector version later...

QuoteI 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!

QuoteYou are awesom
That is so true!  =D

[attachment deleted by admin]

Wampus

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.

MrTAToad

#4
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...

MrTAToad

#5
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




[attachment deleted by admin]

Bursar

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.

MrTAToad

#7
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.

[attachment deleted by admin]

Bursar

Thanks, I'll give it a go later on.

Bursar

Still get some warnings, but it compiles and runs great now :)

MrTAToad

The warnings can be ignored.  Glad it works now!