For Programmers: Free Programming Magazines  


Home > Archive > Cobol > January 2006 > Character Based Representation of a cube in 3D









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Character Based Representation of a cube in 3D
Chris

2006-01-11, 6:55 pm

Platform: HP-UX 11i
COBOL: MF SE 4.0 SP2

Does anyone have a clever way to do this, aside from the standard:

_____
/ /|
/ / |
/_____/ |
| | /
| | /
|_____|/


I'm trying to write a character based program that will show a
proportional cube on screen depending on its measurements (returned
from a laser based Cubiscan machine). The users in the warehouse figure
this is a good way to estimate that the machine is in fact measuring
the product they've placed on it, and they only have access to dumb
terminals.

No - this is NOT homework! :)

I've had plenty of experience using line draw characters and such, but
so far as I am aware, there is no "clean" way to represent the
perspective.

Any and all ideas are appreciated.

Thanks in advance,
Chris

Richard

2006-01-11, 6:55 pm

> Does anyone have a clever way to do this, aside from the standard:

If the terminal has downloadable fonts you can create the image as a
bitmap, divide the bitmap up into character font size lumps, identify
the different characters and upoad these patterns as the font. Display
the image by sending a block of characters that invoke the font to set
the complete bitmap.

Michael Wojcik

2006-01-12, 6:55 pm


In article <1137016688.883691.27950@o13g2000cwo.googlegroups.com>, "Chris" <ctaliercio@yahoo.com> writes:
> Platform: HP-UX 11i
> COBOL: MF SE 4.0 SP2
>
> Does anyone have a clever way to do this, aside from the standard:
>
> _____
> / /|
> / / |
> /_____/ |
> | | /
> | | /
> |_____|/
>
>
> I'm trying to write a character based program that will show a
> proportional cube on screen depending on its measurements (returned
> from a laser based Cubiscan machine). The users in the warehouse figure
> this is a good way to estimate that the machine is in fact measuring
> the product they've placed on it, and they only have access to dumb
> terminals.


I'm not clear on what you're looking for - an algorithm to specify
where to place the drawing characters on the terminal screen, or
other ways to indicate the cube, once you know where you want to
draw it?

If it's the former, I can see two approaches. The more general would
be to compute the 2D wireframe representation of the cube using
standard graphics algorithms, with a fixed camera position and
hidden-line removal. Then transform it to the character-terminal
screen by treating it as a very low-res raster device (each position
on the screen is a pixel) with the origin in the top left corner,
then translate appropriately so you convert pixel coordinates to row
and column positions. Then draw, selecting the character for a given
pixel position based on which edge you're drawing.

The simpler alternative would be to compute the corners and draw the
lines accordingly. That's just a matter of scaling precomputed
corners by the size of the cube. That's the way I'd go.

If it's the latter, here's an alternative idea: if the terminal
supports reverse video, then set the character positions corres-
ponding to edges of the cube to reverse video. That way, the cube
will be made of rough blocks, but will be superimposed on whatever
else is on the display - you can continue to display text and so
forth.

--
Michael Wojcik michael.wojcik@microfocus.com

Painful lark, labouring to rise!
The solemn mallet says:
In the grave's slot
he lies. We rot. -- Basil Bunting
James J. Gavan

2006-01-20, 9:55 pm

Chris wrote:
> Platform: HP-UX 11i
> COBOL: MF SE 4.0 SP2
>
> Does anyone have a clever way to do this, aside from the standard:
>
> _____
> / /|
> / / |
> /_____/ |
> | | /
> | | /
> |_____|/
>
>
> I'm trying to write a character based program that will show a
> proportional cube on screen depending on its measurements (returned
> from a laser based Cubiscan machine). The users in the warehouse figure
> this is a good way to estimate that the machine is in fact measuring
> the product they've placed on it, and they only have access to dumb
> terminals.
>
> No - this is NOT homework! :)
>
> I've had plenty of experience using line draw characters and such, but
> so far as I am aware, there is no "clean" way to represent the
> perspective.
>
> Any and all ideas are appreciated.
>
> Thanks in advance,
> Chris
>

Little bit late since your message.

Over 10 years since I did anything with character/screen. Here goes. Had
a look at your on-line manual for SE, (translated from Japanese)-
http://www.microfocus.co.jp/manuals/SE40SP2/uipubb.htm

Looks similar to NE - so presumably following should work. To get it
figured out I did a 20 x 50 Table in MS Word.

Others viewing it may be able to fine tune it for you.

Jimmy, Calgary AB

*>----------------------------------------------------------
*> Net Express V 3.1

Program-id. Screen-Box.

*
* ____w1____
* / /| h = 10
* L1 / L2 / |h3 L = 24
* / / | w = 28
* /____w2___/ |
* | |h2 /
* |h1 | / L3
* |____w3___| /
*
WORKING-STORAGE SECTION.

*> Assume following inputs as shown :-

*>01 In-Height pic 9(03) value 10.
*>01 In-Length pic 9(03) value 24.
*>01 In-Width pic 9(03) value 28.

*>01 In-Height pic 9(03) value 15.
*>01 In-Length pic 9(03) value 36.
*>01 In-Width pic 9(03) value 42.

01 In-Height pic 9(03)v9(02) value 30.5.
01 In-Length pic 9(03)v9(02) value 36.7.
01 In-Width pic 9(03)v9(02) value 64.2.

*>01 In-Height pic 9(03)v9(02) value 45.5.
*>01 In-Length pic 9(03)v9(02) value 58.7.
*>01 In-Width pic 9(03)v9(02) value 83.2.

01 ws-Height pic 9(03).
01 ws-Length pic 9(03).
01 ws-Width pic 9(03).

01 aChar pic x.
01 Num pic 9(03).

78 MaxLines value 20.
78 MaxColumns value 50.

*> Table Header (2 blank lines), Footer (3 blank lines)
*> and margins 15 each, giving an array 20
*> rows/lines x 50 columns

01 aTable.
05 occurs MaxLines.
10 occurs MaxColumns.
15 Charx pic x.

01 PositionTable.
05 occurs 9.
10 C1 pic 9(03).
10 C2 pic 9(03).
10 L1 pic 9(03).
10 L2 pic 9(03).

01 C pic 9(03).
01 L pic 9(03).

SCREEN SECTION.
01 ScreenBox.
05 blank screen.
05 line 3 col 14.
05 occurs MaxLines.
10 occurs MaxColumns.
15 pic x using Charx.
15 col + 1.
10 Line + 1 col - MaxColumns.

PROCEDURE DIVISION.

*> Initialize aTable, PositionTable
*> perform TEST-IT
*> perform DISPLAY-IT

compute ws-Height Rounded = In-Height
compute ws-Length Rounded = In-Length
compute ws-Width Rounded = In-Width

perform CONVERT-MEASUREMENTS
Initialize aTable, PositionTable

*> Commented results are for the first set of inputs

*> h1
compute C1(1) = 1 *> 1
compute L1(1) = MaxLines - (ws-Height - 1) *> 16
compute L2(1) = MaxLines *> 20

*> h2
compute C1(2) = ws-Width *> 14
compute L1(2) = L1(1) *> 16
compute L2(2) = MaxLines *> 20

*> h3
compute C1(3) = ws-Length + (ws-Width - 1) *> 25
compute L1(3) = MaxLines - (ws-Height + ws-Length - 2) *> 5
compute L2(3) = L1(3) + (ws-Height - 1) *> 9

*> w1
compute L1(4) = L1(3) *> 5
compute C1(4) = ws-Length *> 12
compute C2(4) = C1(4) + (ws-Width - 1) *> 25

*> w2
compute L1(5) = Maxlines - (ws-Height - 1) *> 16
compute C1(5) = 1 *> 1
compute C2(5) = ws-Width *> 14

*> w3
compute L1(6)= MaxLines *> 20
compute C1(6) = 1 *> 1
compute C2(6) = ws-Width *> 14

*> L1
compute C1(7) = ws-Length + 1 *> 13
compute L1(7) = L1(3) *> 5
compute L2(7) = L1(1) *> 16

*> L2
compute C1(8) = C1(7) + ws-Width - 1 *> 26
compute L1(8) = MaxLines - (ws-Height + ws-Length - 2) *> 5
compute L2(8) = L1(1) *> 16

*> L3
compute C1(9) = C1(8) *> 26
compute L1(9) = L1(8) + (ws-Height - 1) *> 9
compute L2(9) = MaxLines *> 20

perform varying Num from 1 by 1 until Num > 3
perform HEIGHT
End-perform
*>perform DISPLAY-IT

perform varying Num from 4 by 1 until Num > 6
perform WIDTH
End-perform
*>perform DISPLAY-IT

perform varying Num from 7 by 1 until Num > 9
perform THE-LENGTH
End-perform

perform DISPLAY-IT
STOP RUN.
Chris

2006-01-23, 6:55 pm

Thanks Jimmy!

I'm going to take a look at this. While the users were dead set against
the line drawing, the representation using "dots" might work better for
them.

Thanks,
Chris


James J. Gavan wrote:
> Chris wrote:
> Little bit late since your message.
>
> Over 10 years since I did anything with character/screen. Here goes. Had
> a look at your on-line manual for SE, (translated from Japanese)-
> http://www.microfocus.co.jp/manuals/SE40SP2/uipubb.htm
>
> Looks similar to NE - so presumably following should work. To get it
> figured out I did a 20 x 50 Table in MS Word.
>
> Others viewing it may be able to fine tune it for you.
>
> Jimmy, Calgary AB
>
> *>----------------------------------------------------------
> *> Net Express V 3.1
>
> Program-id. Screen-Box.
>
> *
> * ____w1____
> * / /| h = 10
> * L1 / L2 / |h3 L = 24
> * / / | w = 28
> * /____w2___/ |
> * | |h2 /
> * |h1 | / L3
> * |____w3___| /
> *
> WORKING-STORAGE SECTION.
>
> *> Assume following inputs as shown :-
>
> *>01 In-Height pic 9(03) value 10.
> *>01 In-Length pic 9(03) value 24.
> *>01 In-Width pic 9(03) value 28.
>
> *>01 In-Height pic 9(03) value 15.
> *>01 In-Length pic 9(03) value 36.
> *>01 In-Width pic 9(03) value 42.
>
> 01 In-Height pic 9(03)v9(02) value 30.5.
> 01 In-Length pic 9(03)v9(02) value 36.7.
> 01 In-Width pic 9(03)v9(02) value 64.2.
>
> *>01 In-Height pic 9(03)v9(02) value 45.5.
> *>01 In-Length pic 9(03)v9(02) value 58.7.
> *>01 In-Width pic 9(03)v9(02) value 83.2.
>
> 01 ws-Height pic 9(03).
> 01 ws-Length pic 9(03).
> 01 ws-Width pic 9(03).
>
> 01 aChar pic x.
> 01 Num pic 9(03).
>
> 78 MaxLines value 20.
> 78 MaxColumns value 50.
>
> *> Table Header (2 blank lines), Footer (3 blank lines)
> *> and margins 15 each, giving an array 20
> *> rows/lines x 50 columns
>
> 01 aTable.
> 05 occurs MaxLines.
> 10 occurs MaxColumns.
> 15 Charx pic x.
>
> 01 PositionTable.
> 05 occurs 9.
> 10 C1 pic 9(03).
> 10 C2 pic 9(03).
> 10 L1 pic 9(03).
> 10 L2 pic 9(03).
>
> 01 C pic 9(03).
> 01 L pic 9(03).
>
> SCREEN SECTION.
> 01 ScreenBox.
> 05 blank screen.
> 05 line 3 col 14.
> 05 occurs MaxLines.
> 10 occurs MaxColumns.
> 15 pic x using Charx.
> 15 col + 1.
> 10 Line + 1 col - MaxColumns.
>
> PROCEDURE DIVISION.
>
> *> Initialize aTable, PositionTable
> *> perform TEST-IT
> *> perform DISPLAY-IT
>
> compute ws-Height Rounded = In-Height
> compute ws-Length Rounded = In-Length
> compute ws-Width Rounded = In-Width
>
> perform CONVERT-MEASUREMENTS
> Initialize aTable, PositionTable
>
> *> Commented results are for the first set of inputs
>
> *> h1
> compute C1(1) = 1 *> 1
> compute L1(1) = MaxLines - (ws-Height - 1) *> 16
> compute L2(1) = MaxLines *> 20
>
> *> h2
> compute C1(2) = ws-Width *> 14
> compute L1(2) = L1(1) *> 16
> compute L2(2) = MaxLines *> 20
>
> *> h3
> compute C1(3) = ws-Length + (ws-Width - 1) *> 25
> compute L1(3) = MaxLines - (ws-Height + ws-Length - 2) *> 5
> compute L2(3) = L1(3) + (ws-Height - 1) *> 9
>
> *> w1
> compute L1(4) = L1(3) *> 5
> compute C1(4) = ws-Length *> 12
> compute C2(4) = C1(4) + (ws-Width - 1) *> 25
>
> *> w2
> compute L1(5) = Maxlines - (ws-Height - 1) *> 16
> compute C1(5) = 1 *> 1
> compute C2(5) = ws-Width *> 14
>
> *> w3
> compute L1(6)= MaxLines *> 20
> compute C1(6) = 1 *> 1
> compute C2(6) = ws-Width *> 14
>
> *> L1
> compute C1(7) = ws-Length + 1 *> 13
> compute L1(7) = L1(3) *> 5
> compute L2(7) = L1(1) *> 16
>
> *> L2
> compute C1(8) = C1(7) + ws-Width - 1 *> 26
> compute L1(8) = MaxLines - (ws-Height + ws-Length - 2) *> 5
> compute L2(8) = L1(1) *> 16
>
> *> L3
> compute C1(9) = C1(8) *> 26
> compute L1(9) = L1(8) + (ws-Height - 1) *> 9
> compute L2(9) = MaxLines *> 20
>
> perform varying Num from 1 by 1 until Num > 3
> perform HEIGHT
> End-perform
> *>perform DISPLAY-IT
>
> perform varying Num from 4 by 1 until Num > 6
> perform WIDTH
> End-perform
> *>perform DISPLAY-IT
>
> perform varying Num from 7 by 1 until Num > 9
> perform THE-LENGTH
> End-perform
>
> perform DISPLAY-IT
> STOP RUN.
> .
>
> CONVERT-MEASUREMENTS.
>
> compute L = ws-Height + ws-Length
> compute C = ws-Width
>
> if L > MaxLines or C > MaxColumns
> compute ws-Height Rounded = ws-Height / 2
> compute ws-Length Rounded = ws-Length / 2
> compute ws-Width Rounded = ws-Width / 2
> go to CONVERT-MEASUREMENTS.
> .
> DISPLAY-IT.
>
> display ScreenBox
> accept aChar Line 25 col 1
> .
> HEIGHT.
>
> perform varying L from L1(Num) by 1 until L > L2(Num)
> move "." to charx (L,C1(Num))
> End-perform
> .
>
> TEST-IT.
>
> *> This will give a 20 x 50 Table of "+'s"
>
> perform varying L from 1 by 1 until L > MaxLines
> perform varying C from 1 by 1 until C > MaxColumns
> move "+" to charx(L,C)
> End-perform
> End-perform
> .
> THE-LENGTH. *> 9 and 20
>
> perform varying L from L1(Num) by 1 until L > L2(Num)
> subtract 1 from C1(Num)
> move "." to charx, (L,C1(Num))
> End-perform
> .
>
> WIDTH.
>
> perform varying C from C1(Num) by 1 until C > C2(Num)
> move "." to charx (L1(num),C)
> End-perform
> .
> *>----------------------------------------------------------
> *>
> *> Above should give you a box like the following
> *>
> *> ................
> *> . ..
> *> . . .
> *> . . .
> *> . . .
> *> . . .
> *> . . .
> *> . . .
> *> . . .
> *> ................ .
> *> . . .
> *> . . .
> *> . . .
> *> . . .
> *> . . .
> *> . ..
> *> ................
> *>
> *>----------------------------------------------------------


peter

2006-01-24, 7:55 am


Chris wrote:
> Thanks Jimmy!
>
> I'm going to take a look at this. While the users were dead set against
> the line drawing, the representation using "dots" might work better for
> them.
>
> Thanks,
> Chris


Well done indeed. Next challence is of course built-in compensation for
the optical illusion that the box appears to widen towards te back.

James J. Gavan

2006-01-24, 6:55 pm

peter wrote:
> Chris wrote:
>
>
>
> Well done indeed. Next challence is of course built-in compensation for
> the optical illusion that the box appears to widen towards te back.
>

It's character mode not APIs. How about the horizontal (width) ? I'm
sure like me, when you were but seven years of age, from Art 101 you
learned that if you can see two sides of a box then you can't have a 90
degree horizontal. Besides which he is stuck with a 45 degree angle for
lengths, even though he does have facilities for designing specific
character shapes. :-)

Jimmy
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com