Why I Love this forum

Started by 3DzForMe, December 28, 2018, 07:37:32

Previous topic - Next topic

3DzForMe

I was hunting around for a recent thread regarding drawing circles which got the creative cogs nearly grinding into life.

In my searching I came across some code for plotting some points and allowing them to be moved.

I thought it'd be interesting to add the ability to add some more points, or remove them if you felt like it.

[EDIT]

for those of you without a Blitz esque compiler, heres a link to an executable:



circles2.exe  circles2.exe




Here's the code in all it's glory - it'll run in Blitz3D and probably BlitzPlus.....


; Original author Credit:
; https://www.syntaxbomb.com/index.php/topic,2714.msg3703.html#msg3703

; Version 0.2
; Adding mouse cursor info to allow for capture of additional datapoints:
; Completed 28 Dec 18, by 3DZforMe, aka Blitzplotter

; Set the screensize
Graphics 800,600,32,2
SetBuffer BackBuffer()

MaxNumberOfPoints=200
Global CurrentPlotCount=4
Global NextPlotCount=5

; Dimension the pointarray and set startvalues
Dim DataPoint(MaxNumberOfPoints,1)
DataPoint(0,0) = 100 : DataPoint(0,1) = 090
DataPoint(1,0) = 200 : DataPoint(1,1) = 160
DataPoint(2,0) = 300 : DataPoint(2,1) = 300
DataPoint(3,0) = 400 : DataPoint(3,1) = 210
DataPoint(4,0) = 500 : DataPoint(4,1) = 100

    ; Set the clearcolor to red, and select point 0
ClsColor 255,255,255 : Global Selected = 0

    ; Mainloop
While Not KeyDown(1)
Cls ; Clear screen

       ; Userinput (Use [Q] and [W] to select a point,
       ; and Arrowkeys to position the selected point)
If KeyHit(16) And Selected > 0 Then Selected = Selected - 1
If KeyHit(17) And Selected < CurrentPlotCount Then Selected = Selected + 1
If KeyDown(203) Then DataPoint(Selected,0) = DataPoint(Selected,0) - 1
If KeyDown(205) Then DataPoint(Selected,0) = DataPoint(Selected,0) + 1
If KeyDown(200) Then DataPoint(Selected,1) = DataPoint(Selected,1) - 1
If KeyDown(208) Then DataPoint(Selected,1) = DataPoint(Selected,1) + 1

DrawLine(CurrentPlotCount) ; Draw the interpolated line between point 0 and 4

xP=MouseX()
yP=MouseY()

Color 0,0,250

Text 40,1,"Userinput: (Use [Q] and [W] to select a point, and Arrowkeys to Move the selected point"

Color 100,180,0

Text 12,30,"x: "+xP+" y: "+yP+" Points to Draw:"+CurrentPlotCount

;If left click add extra position to current list of points

button$="No"
If MouseDown(1) Then button$="Left"
If MouseDown(2) Then button$="Right"
If MouseDown(3) Then button$="Middle"

Text 400,30, button$ + " mouse button pressed!"

If button$="Left"

DataPoint(NextPlotCount,0) = xP : DataPoint(NextPlotCount,1) = yP
CurrentPlotCount=CurrentPlotCount+1
NextPlotCount=NextPlotCount+1

;Implement a pause to stop NUMEROUS extra points being added in quick succesion

Text 40,60,"Press any key to continue to add your next point"

Flip

WaitKey()

EndIf

If button$="Right"

DataPoint(NextPlotCount,0) = xP : DataPoint(NextPlotCount,1) = yP

If CurrentPlotCount>1

CurrentPlotCount=CurrentPlotCount-1
NextPlotCount=NextPlotCount-1

Text 40,60,"Press any key to continue....."

Flip

WaitKey()

Else

Text 40,60,"Add some more points first please....."

;Implement a pause to stop NUMEROUS extra points being added in quick succesion

Text 40,80,"Press any key to continue....."

Flip

WaitKey()


EndIf


EndIf

If button$="Middle"

Text 200,50,"Congratutaions on 3 buttons...."

EndIf


Flip ; Flip backbuffer to frontbuffer
Wend

End ; End of programm

Function DrawLine(CurrentPlotCount)
       ; Startpoint for the first Line
X = DataPoint(0,0) : Y = DataPoint(0,1) : Color 0,0,0

       ; Draw the interpolyted Line between point 0 and 1
MX = (DataPoint(0,0) - DataPoint(1,0)) * (-1)
For MU# = 0 To 1.0 Step 0.08
OX = X : OY = Y
Y = CosineInterpolate(DataPoint(0,1),DataPoint(1,1),MU#)
X = MX * MU# + DataPoint(0,0)
Line OX,OY,X,Y
Next

       ; Draw the interpolated line between point 1 and 4
For I = 2 To CurrentPlotCount
MX = (DataPoint(I - 1,0) - DataPoint(I,0)) * (-1)
For MU# = 0 To 1.0 Step 0.08
OX = X : OY = Y
Y = CosineInterpolate(DataPoint(I - 1,1),DataPoint(I,1),MU#) 
X = MX * MU# + DataPoint(I - 1,0)
Line OX,OY,X,Y
Next
Next

       ; Dra the anchor points
Color 255,0,0
For I = 0 To CurrentPlotCount
If Selected = I Then
Color 0,0,255
Else
Color 255,0,0
EndIf
Oval DataPoint(I,0) - 2,DataPoint(I,1) - 2,5,5,1
Next
End Function

    ; Function for cosineinterpolated line
Function CosineInterpolate(Y1#,Y2#,MU#)
Local MU2#
MU2# = (1.0 - Cos(MU# * 180.0))/2.0
Return (Y1# * (1.0 - MU2#) + Y2# * MU2#)
End Function

    ; Function for normal line
Function LinearInterpolate(Y1#,Y2#,MU#)
Return Y1# * (1 - MU#) + Y2# * MU#
End Function



Right, coding done for the day.... off to pack for a cheeky 300 mile drive to Scotland ;)
BLitz3D, IDEal, AGK Studio, BMax, Java Code, Cerberus
Recent Hardware: Dell Laptop
Oldest Hardware: Commodore Amiga 1200 with 1084S Monitor & Blitz Basic 2.1

plenatus

#1
I remember that i have a problem with bb3d exe´s.
I have only a black colored window.
Must i install any feature in windows 10?

DirectPlay is installed.

MagosDomina

Quote from: c0d3r9 on December 28, 2018, 11:09:50
I remember that i have a problem with bb3d exe´s.
I have only a black colored window.
Must i install any feature in windows 10?

DirectPlay is installed.

We need a bit more information to help.
Can you run the code within the example folder from the IDE without issue?
Does compiling the same code into an .exe produce the same result?
Do you have the full installation of DX9c on your system? Windows 10 does not come with it standard.
Multiple monitors will cause issues with Blitz. Unless the program ran is displayed on your primary screen it will show up blank/blackscreen but still function in the background.
Lastly do you have any global settings on your 3D card? I would have it set for "application preference" or whatever is equivalent to your card.

plenatus

I just start the .exe
In past (a few month ago i tried some codes with bb3d) i have the same problem.
Sometimes it go well sometime not.
Dx9c is installed.
Driver up2date, nothing special configured in the settings.

I start the exe and it opens a normal bordered window with a black background...thats all.
But not very important that i must this issue solve now ;)

MagosDomina

Do 2d examples always work? Meaning its only the 3D examples that give you this issue?

I have noticed on Windows 7 sometimes at random when I build an .exe it does not link everything together correctly, resulting in a "missing library" error. Recompiling until it works solves the issue.

Please let me know what code you are attempting to run.


3DzForMe

#5
Sorry to hear your trouble with the executable, just downloaded it to my dad's laptop in Scotland, not that the country should matter much, it's a windows10 box, sure it needed .  ....   Gotta go for my yea, it worked after installing directplay though ;)
BLitz3D, IDEal, AGK Studio, BMax, Java Code, Cerberus
Recent Hardware: Dell Laptop
Oldest Hardware: Commodore Amiga 1200 with 1084S Monitor & Blitz Basic 2.1

plenatus

I only wanted to run the exe.There is no reason for me to play around with bb3d.
But that demonstrates that bb3d is sometimes just to old.

3DzForMe

I suspect it's compatibility lssues with your 3d card, I was surprised it ran on my dad's old laptop, and I didn't need to install Blitz3D for the exe to work, even though the screen grab shows otherwise. I was just intrigued to see if my dad's clunky computer could compile blitz stuff. Sorry it didn't work for you though.
BLitz3D, IDEal, AGK Studio, BMax, Java Code, Cerberus
Recent Hardware: Dell Laptop
Oldest Hardware: Commodore Amiga 1200 with 1084S Monitor & Blitz Basic 2.1

plenatus

its no problem.
that issue is only with bb3d´s builds.

MagosDomina

Quote from: c0d3r9 on December 28, 2018, 20:50:33
I only wanted to run the exe.There is no reason for me to play around with bb3d.
But that demonstrates that bb3d is sometimes just to old.

I'm going to guess and say that English isn't your first language? I was under the impression you were trying to compile the code yourself. The problem you're having is not Blitz related but likely your hardware or something else specific to your system.

plenatus

Right ;)
And i start only circles2.exe
Maybe its hardware related that my chipset doesn´t allow the dx7 emulated things.I don´t know.Its not important.

3DzForMe

I'm jealous of folks with 64 bit hardware, all my Dev machines are only (only....!) 32 bit so aren't Cerberus compatible. I'm also an advocate of MonkeyX despite the fact the forums vanished. On my dad's W10 computer (I've only got W7, tbh it's like today's XP OS), it was taking for EVER to locate directplay, nearly gave up and went hunting on the web.... But it eventually found it. Was the only hiccup, I'd be surprised if he's got older DirectX versions but you never know!
BLitz3D, IDEal, AGK Studio, BMax, Java Code, Cerberus
Recent Hardware: Dell Laptop
Oldest Hardware: Commodore Amiga 1200 with 1084S Monitor & Blitz Basic 2.1

MagosDomina

#12
There is a way to strip a Blitz exe of the direct-play requirement. I found it on a German based Blitz website and archived it on a drive. If I remember correctly the direct play requirement is only for the multiplayer compatibility. So if your app doesn't use any of those functions you can strip out request for the .dll thus removing the need for Windows 10 to install this legacy component.


*edit*

Here is what you do, open runtime.dll in the blitz3d\bin folder into a hex editor. Search for Dplayx.dll and replace it with Dinput.dll and save it.
This only works with Blitz3d and lets you run your code without direct play.

3DzForMe

#13
Great piece of advice, thanks for sharing!

I think I recall Blitz3D may need a dedicated graphics card to run, some of the on motherboard graphics cards may not be up to the job .
BLitz3D, IDEal, AGK Studio, BMax, Java Code, Cerberus
Recent Hardware: Dell Laptop
Oldest Hardware: Commodore Amiga 1200 with 1084S Monitor & Blitz Basic 2.1

RemiD

#14
Quote
I think I recall Blitz3D may need a dedicated graphics card to run
what are you talking about ? how do you know that ? i have run blitz3d (3d) programs on many different laptops / desktops without having ever noticed this !!!


maybe consider that your code is the problem ?