 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
babak gh Guest
|
Posted: Wed Aug 24, 2005 11:59 am Post subject: tips on writing a cad program! |
|
|
Hi....
i think lots of newbie questions!!
i was developing a cad program that i came across lots of problems and i saw
wow there are lots of things i do not know!
i need some tips on changing my code or/and making it better for further
customizations and so!
-i used gdi which is very slow when there are more than 50 objects, changing
canvas.pen.color or similar thigns really slows down drawings.i find
graphics32 library on net; is it a lot faster or not!also i am planning in
future to make it 3d maybe i should switch to opengl?
-when zooming and panning i do redraw all objects, is this a correct way of
doing this or not?or any faster way to implement?
- i saw somewhere here that someone suggested using x,y,z as floting
points...so how can i draw them ?
-also i think i have to use antialiasing becouse it looks really nice....but
i read somewhere with graphics32 it slows down my process?does opengl
support this too?or that will be enough for around 500 objects?also there
are no circles or eliipse functions..should i implement them?
-does using multiple layers on graphics32 slow down my program?
-when using graphics32 how can fill a pattern...as i saw there is no brush!
and anyplace i can learn more about doing cad programing and also some other
graphical algorithms and meanings!
(i think it might be funny but i dont know what alpha blenging is or.....?)
regards
|
|
| Back to top |
|
 |
Anders Isaksson Guest
|
Posted: Wed Aug 24, 2005 6:52 pm Post subject: Re: tips on writing a cad program! |
|
|
You can always take a look at my BlockCAD program (building with Lego on the
computer). The source is available from the link in my signatuer (below).
It supports (among other things) rotating, translating and zooming of the
model. There is also a kind of 'antialiasing' that can be switched on -
drawing in double size and downsampling.
It's only using GDI and some 'homemade' routines for polygon filling and
alpha blending, and definitely manages more than 50 objects :-)
The largest construction I've seen made with it contains 55615 blocks, but
then it certainly is very slow!
Warning: I started making the program when Delphi 1.0 came out, and it has
grown during the years (together with my knowledge of Delphi), so it's not
the best, most well structured, code you can find. But it may still give you
some ideas.
--
Anders Isaksson, Sweden
BlockCAD: http://web.telia.com/~u16122508/proglego.htm
Gallery: http://web.telia.com/~u16122508/gallery/index.htm
|
|
| Back to top |
|
 |
dd Guest
|
Posted: Thu Aug 25, 2005 3:06 am Post subject: Re: tips on writing a cad program! |
|
|
Anders Isaksson wrote:
| Quote: | You can always take a look at my BlockCAD program (building with Lego on the
computer). The source is available from the link in my signatuer (below).
|
This is a very cool program.
Great job!
|
|
| Back to top |
|
 |
Roger Lascelles Guest
|
Posted: Fri Aug 26, 2005 12:06 am Post subject: Re: tips on writing a cad program! |
|
|
"babak gh" <roozbeh3xy (AT) yahoo (DOT) com> wrote
| Quote: | i was developing a cad program that i came across lots of problems and i
saw |
I found that my own initial efforts were basic, but kept on improving, over
18 months of spare time - and I have more work yet !
The way to keep the code alive while at the same time changing it, is to
modularise your program. The drawn items will need to be nicely stored in
some kind of container class, probably as an object for each drawing
primitive or block, with virtual functions for drawing the object. When the
code gets knotty, factorize it - tease it out into separate classes and .pas
files.
| Quote: | -i used gdi which is very slow when there are more than 50 objects,
changing
canvas.pen.color or similar thigns really slows down drawings.i find
graphics32 library on net; is it a lot faster or not!also i am planning in
future to make it 3d maybe i should switch to opengl?
|
I think 2D is a great start.
| Quote: | -when zooming and panning i do redraw all objects, is this a correct way
of
doing this or not?or any faster way to implement?
|
GDI programs can be fast, but there are tricks. For example a move of one
object on screen can mean redrawing only the area of screen which encloses
the start and finish rectangles surrounding the object. You can get an idea
of how fast GDI programs are by trying a commercial product - it is fairly
good. I aim for GDI because it is so user friendly - your program comes up
quickly, it coexists on the screen nicely with other programs - and everyone
can run it. In my experience, OpenGL and DirectX don't act like this.
DirectX is so much faster that you can simply redraw the whole window every
time anything changes.
Panning can involve shifting the image rather than redrawing it. The API
function ScrollWindowEx does this. Zooming involves a complete redraw, I
think.
XOR drawing is one way to get a fast move of a drawing object over the top
of other objects without having to redraw the other objects. The XOR image
colors are not ideal, but it is an easy solution I like.
I recall that Delphi keeps a small cache of pens - once you exceed that,
Delphi has to get Windows to re-create a pen. You can build your own cache
of pens & bushes to extend this. Like all optimisations, this is a pain.
I have stuck to the Delphi TCanvas with some direct GDI calls using the
canvas handle and with some optimisation this has been fast enough for my
needs. However, if I wanted a CAD program with a lot of grunt, I would use
the API calls and manage the device context and pen and brush cache myself.
| Quote: | and anyplace i can learn more about doing cad programing and also some
other
graphical algorithms and meanings!
|
My own effort is VCad - an electronic layout editor available from
http://www.geocities.com/rogerlasau/VCad.html
email me for source code.
If you install my program and load the sample file calibrator1.per you can
select all components and drag them around the screen - 140 components,
consisting of 2000? thousand GDI lines and circles - all apparently
instantaneous on a modern PC and still fast on a 150 MHz Pentium. If you
move a single component there is no flicker apparent, because nothing is
erased - only drawn over the top - and only the components which are
overlapped or adjacent to the changed area get redrawn.
Roger Lascelles
|
|
| Back to top |
|
 |
Francesco Savastano Guest
|
Posted: Fri Aug 26, 2005 10:34 pm Post subject: Re: tips on writing a cad program! |
|
|
Hello Roger, very interesting program:) how do you manage the 3d world
without opengl? Do you have your own special rendering engine that recreates
the 3d view on the plane? I also see that you take somehow in account the
direction of light.. this is very interesting to be just a free program:)
| Quote: |
i was developing a cad program that i came across lots of problems and i
saw
I found that my own initial efforts were basic, but kept on improving,
over
18 months of spare time - and I have more work yet !
The way to keep the code alive while at the same time changing it, is to
modularise your program. The drawn items will need to be nicely stored in
some kind of container class, probably as an object for each drawing
primitive or block, with virtual functions for drawing the object. When
the
code gets knotty, factorize it - tease it out into separate classes and
.pas
files.
-i used gdi which is very slow when there are more than 50 objects,
changing
canvas.pen.color or similar thigns really slows down drawings.i find
graphics32 library on net; is it a lot faster or not!also i am planning
in
future to make it 3d maybe i should switch to opengl?
I think 2D is a great start.
-when zooming and panning i do redraw all objects, is this a correct way
of
doing this or not?or any faster way to implement?
GDI programs can be fast, but there are tricks. For example a move of one
object on screen can mean redrawing only the area of screen which encloses
the start and finish rectangles surrounding the object. You can get an
idea
of how fast GDI programs are by trying a commercial product - it is fairly
good. I aim for GDI because it is so user friendly - your program comes
up
quickly, it coexists on the screen nicely with other programs - and
everyone
can run it. In my experience, OpenGL and DirectX don't act like this.
DirectX is so much faster that you can simply redraw the whole window
every
time anything changes.
Panning can involve shifting the image rather than redrawing it. The API
function ScrollWindowEx does this. Zooming involves a complete redraw, I
think.
XOR drawing is one way to get a fast move of a drawing object over the top
of other objects without having to redraw the other objects. The XOR
image
colors are not ideal, but it is an easy solution I like.
I recall that Delphi keeps a small cache of pens - once you exceed that,
Delphi has to get Windows to re-create a pen. You can build your own
cache
of pens & bushes to extend this. Like all optimisations, this is a pain.
I have stuck to the Delphi TCanvas with some direct GDI calls using the
canvas handle and with some optimisation this has been fast enough for my
needs. However, if I wanted a CAD program with a lot of grunt, I would
use
the API calls and manage the device context and pen and brush cache
myself.
and anyplace i can learn more about doing cad programing and also some
other
graphical algorithms and meanings!
My own effort is VCad - an electronic layout editor available from
http://www.geocities.com/rogerlasau/VCad.html
email me for source code.
If you install my program and load the sample file calibrator1.per you can
select all components and drag them around the screen - 140 components,
consisting of 2000? thousand GDI lines and circles - all apparently
instantaneous on a modern PC and still fast on a 150 MHz Pentium. If you
move a single component there is no flicker apparent, because nothing is
erased - only drawn over the top - and only the components which are
overlapped or adjacent to the changed area get redrawn.
Roger Lascelles
|
|
|
| Back to top |
|
 |
Francesco Savastano Guest
|
Posted: Fri Aug 26, 2005 10:36 pm Post subject: Re: tips on writing a cad program! |
|
|
another comment, sorry I couldnt resist:
....Sometimes we wonder how egypthians built pyramids...
the answer with much time and work:)
|
|
| Back to top |
|
 |
Roger Lascelles Guest
|
Posted: Sat Aug 27, 2005 9:57 am Post subject: Re: tips on writing a cad program! |
|
|
"Francesco Savastano" <francosavastano (AT) TakeThisOutFromAddress (DOT) virgilio.it>
wrote in message news:430f98b3 (AT) newsgroups (DOT) borland.com...
| Quote: |
Hello Roger, very interesting program:) how do you manage the 3d world
without opengl? Do you have your own special rendering engine that
recreates
the 3d view on the plane? I also see that you take somehow in account the
direction of light.. this is very interesting to be just a free program:)
|
My program (VCad) is 2D only. !
I'm guessing you are are looking at BlockCAD - and Anders Isaksson is the
author. Perhaps he will answer.
Roger Lascelles
|
|
| Back to top |
|
 |
Francesco Savastano Guest
|
Posted: Sat Aug 27, 2005 5:22 pm Post subject: Re: tips on writing a cad program! |
|
|
oops,
I was so amazed by the screenshot of blockcad that i even didn't realize
well which poster was the author:)..
But really it's facinating that he wrote blockcad using just gdi and without
opengl: he must now have a very good experience on writing cad programs . I
remember I had an interview and they asked if I could do someth like that
and I regret I couldnt answer "yes I already did it". Anders would surely
have got that job..
| Quote: | My program (VCad) is 2D only. !
I'm guessing you are are looking at BlockCAD - and Anders Isaksson is the
author. Perhaps he will answer.
Roger Lascelles
|
|
|
| Back to top |
|
 |
Anders Isaksson Guest
|
Posted: Sat Aug 27, 2005 6:32 pm Post subject: Re: tips on writing a cad program! |
|
|
Francesco Savastano wrote:
| Quote: | Hello Roger, very interesting program:) how do you manage the 3d world
without opengl? Do you have your own special rendering engine that
recreates the 3d view on the plane? I also see that you take somehow
in account the direction of light.. this is very interesting to be
just a free program:)
|
It looks like you're talking about my program, BlockCAD :-)
Yes, there is a 'special rendering engine', taking advantage of the limited
variation of the Lego blocks. Most standard blocks are not 3D at all! They
are faked with 3 2D-polygons, differently shaded. The studs are also drawn
in the 2D view, not in real 3D, so they are only transformed once, the rest
is translations. That was the only way to get acceptable speed when I
started with plain GDI drawing in Delphi 1.0 on my 486/50 back in 1996-97.
The biggest speed boost was when I found a polygon drawing routine in
Graphical Gems and ported that. This means that the only thing I use GDI for
now is blitting a bitmap from memory to screen.
Later I've added 'real' 3D blocks, defined by their surfaces, but the
'primitive' in the system is still the block, which means I can't draw
convex blocks very good, and definitely not draw a block positioned in the
convex portion/hole of another (They can be placed, but the drawing doesn't
work).
The lighting is also mostly fake (especially for standard blocks, as they
have no 3D surfaces): As the blocks have very limited geometry I just have
to calculate a table with a small number of intensities once when the light
direction is set, the code does the rest, using a fixed index for each side.
Also, as I don't know the inside from the outside (there are no back faces)
the effect is the same as if two, diametrically opposed, lights are shining
on the object. The lighting is applied to each block in the same way, so you
can see lighted surfaces inside a house, for example. There are no real
shadows.
So, all in all, there are more tricks than plain 3D rendering, but the final
result is good enough, and fast enough. Actually, I think it's the fastest
Lego building program you can find (and also the most limited).
<off-topic>
Other free Lego building programs:
LDRAW - www.ldraw.org - DOS, the one that started it all
MLCad - http://www.lm-software.com/mlcad/ - Windows
LeoCAD - http://www.leocad.org/ - Windows, linux
Bricksmith - http://bricksmith.sourceforge.net/ - Mac
BrickDraw3D - http://olson.pair.com/brickdraw3d/ - Mac
LDD - http://www.lego.com/eng/create/digitaldesigner/ - official, Windows,
Mac (In US you can now use this to draw a Lego model of your own, and then
order the parts directly from Lego)
Discuss it all at www.lugnet.com
</off-topic>
Sorry, got a bit carried away there...
--
Anders Isaksson, Sweden
BlockCAD: http://web.telia.com/~u16122508/proglego.htm
Gallery: http://web.telia.com/~u16122508/gallery/index.htm
|
|
| Back to top |
|
 |
Anders Isaksson Guest
|
Posted: Sat Aug 27, 2005 8:45 pm Post subject: Re: tips on writing a cad program! |
|
|
Francesco Savastano wrote:
| Quote: | I remember I had an interview and they asked if I
could do someth like that and I regret I couldnt answer "yes I
already did it". Anders would surely have got that job..
|
Don't be too sure about that!
Actually, BlockCAD *has* helped me get very quickly to a job interview. I
mailed them on a Thursday and they phoned me Friday morning and asked me to
come the same day for a meeting. But in the end I didn't get the job - I was
too expensive (I'm 51 now, been working with programming for 25 years, so
it's much cheaper for employers to hire people fresh out of school - at
least that's what they think...).
--
Anders Isaksson, Sweden
BlockCAD: http://web.telia.com/~u16122508/proglego.htm
Gallery: http://web.telia.com/~u16122508/gallery/index.htm
|
|
| Back to top |
|
 |
Francesco Savastano Guest
|
Posted: Sat Aug 27, 2005 9:21 pm Post subject: Re: tips on writing a cad program! |
|
|
| Quote: | Actually, BlockCAD *has* helped me get very quickly to a job interview. I
mailed them on a Thursday and they phoned me Friday morning and asked me
to come the same day for a meeting. But in the end I didn't get the job -
I was too expensive
|
yeah I also was told finally that I was too expensive...after that
interview;)
I am sorry you didn't get the job but what can i say this is really a
strange world where we live..
|
|
| Back to top |
|
 |
Jens Gruschel Guest
|
Posted: Sun Aug 28, 2005 12:42 am Post subject: Re: tips on writing a cad program! |
|
|
| Quote: | yeah I also was told finally that I was too expensive...after that
interview;)
|
As I see we all have the same problem. Well, I have a new job (stating
in October), but not as expensive than my last one was.
Jens
--
Jens Gruschel
http://www.pegtop.net
|
|
| Back to top |
|
 |
|
|
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
|
|