Jump to content

3D Library (Three Dimensional)


jvanegmond
 Share

Recommended Posts

Does anyone have a faster way of drawing pixels onto the screen? I'm worried that in future when i do Z-mapping and texturing that AutoIt's graphic control will fall in short.

Use GDI dll calls? http://www.autoitscript.com/fileman/users/outeast/files/gdi32.au3

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

Use GDI dll calls? http://www.autoitscript.com/fileman/users/outeast/files/gdi32.au3

Thanks!!! Let's see what we can do with that!!!

#)

Link to comment
Share on other sites

I have changed my example:

_3DExtrude now detects automatically what axis to extend, only $len needs to besupplied insted of an x, y and z value.

I have also added _3DCuboid which uses _3DExtrude

#include <GUIConstants.au3>
#include <..\3D.au3>
#include <misc.au3>
#include <array.au3>

$GUI = GUICreate("_3DExtrude", 400, 400)
GUISetBkColor(0x000000)
$gr = GUICtrlCreateGraphic(0,0)
GUISetState()
_3DSetCenter(200, 300)
Draw()

$Pos = WinGetPos($GUI)
ToolTip("Instead of making shapes using only lines, "& _
@CRLF & "you can extrude them although the base must be drawn first. ", _
$Pos[0]+3,$Pos[1]+22,"This is another example showing _3DExtrude")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
;~    Case 
;~    Case 
;~    Case 
;~    Case 
    EndSwitch
    #include <InputManager.au3>
WEnd

Func Draw()
    GUICtrlDelete($gr)
    $gr = GUICtrlCreateGraphic(0, 0, 400, 400)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff0000)
    $extrudeR = ""
    $extrudeT = ""
    ;rectangular base
    _3dMove(-1, 0, 0, 0)
    ;Create Cuboid
    _3DCuboid(-1, 0, 0, 0, 50, 50, 100)
    ;create diagonal line on top
    _3DMove(-1, 0, 50, 0)
    _3DLine(-1, 50, 50, 100)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00ff00)  
    ;extrude triangular prism from half of cuboid (split by diagonal)
    Dim $extrudeT[3] = ["0,50,0", "0,50,100", "50,50,100"]
    _3DExtrude(-1, $extrudeT, 50)
    ;extrude cuboid from side of triangular prism
    Dim $extrude2[4] = ["0,50,100", "50,50,100", "50,100,100", "0,100,100"]
    _3DExtrude(-1, $extrude2, 20)
    GUICtrlSetGraphic(-1, $GUI_GR_REFRESH)
    Sleep(100)
EndFunc

;===============================================================================
;
; Function Name:   _3DCuboid
; Description::    Creates a 3D cuboid 
; Parameter(s):    $ControlID - The return value of a GUICtrlCreateGraphic
;               $Px - X coordinate in 3D Space
;               $Py - Y coordinate in 3D Space
;               $Pz - Z coordinate in 3D Space
;               $xLen - Length of x-axis on cuboid
;               $yLen - Length of y-axis on cuboid
;               $zLen - Length of z-axis on cuboid
; Requirement(s):  None
; Return Value(s): None
; Author(s):       RazerM
;
;===============================================================================
;
Func _3DCuboid($ControlID, $Px, $Py, $Pz, $xLen, $yLen, $zLen)
    _3DLine($ControlID, $Px, $Py, $Pz)
    _3DLine($ControlID, $Px, $Py, $Pz+$zLen)
    _3DLine($ControlID, $Px+$xLen, $Py, $Pz+$zLen)
    _3DLine($ControlID, $Px+$xLen, $Py, $Pz)
    _3DLine($ControlID, $Px, $Py, $Pz)
    Dim $extrude[4] = [$Px & "," & $Py & "," & $Pz, _
                       $Px & "," & $Py & "," & $Pz+$zLen, _
                       $Px+$xLen & "," & $Py & "," & $Pz+$zLen, _
                       $Px+$xLen & "," & $Py & "," & $Pz]
    _3DExtrude($ControlID, $extrude, $yLen)
EndFunc

;===============================================================================
;
; Function Name:   _3DExtrude
; Description::    Extrude a shape a certain length
; Parameter(s):    $ControlID - The return value of a GUICtrlCreateGraphic
;               $arPoints - An array of points forming the base shape each in the format x,y,z
;               $len - How far to extrude shape
;               $sDelim - The delimiter for each set of points in the array 
; Requirement(s):  None
; Return Value(s): On Error: @error = 1 and returns 0
; Author(s):       RazerM
;
;===============================================================================
;
Func _3DExtrude($ControlID, $arPoints, $len, $sDelim = ",")
    Dim $x = 0, $y = 0, $z = 0
    $iUBound = UBound($arPoints)
    Dim $points[$iUBound]
    Dim $pX[$iUBound]
    Dim $pY[$iUBound]
    Dim $pZ[$iUBound]
    For $i = 0 To $iUBound-1
        $points = StringSplit($arPoints[$i], $sDelim)
        $pX[$i] = $points[1]
        $pY[$i] = $points[2]
        $pZ[$i] = $points[3]
    Next
    If _AxisDetermine($pX) = 0 Then
        $x = $len
    ElseIf _AxisDetermine($pY) = 0 Then
        $y = $len
    ElseIf _AxisDetermine($pZ) = 0 Then
        $z = $len
    Else
        Return SetError(1, 0, 0)
    EndIf
    For $i = 0 To $iUBound-1
        _3DMove($ControlID, $pX[$i], $pY[$i], $pZ[$i])
        _3DLine($ControlID, $pX[$i]+$x, $pY[$i]+$y, $pZ[$i]+$z)
        If $i <> $iUBound-1 Then _3DLine($ControlID, $pX[$i+1]+$x, $pY[$i+1]+$y, $pZ[$i+1]+$z)
        If $i = $iUBound-1 Then _3DLine($ControlID, $pX[0]+$x, $pY[0]+$y, $pZ[0]+$z)
    Next
EndFunc

;helper for _3DExtrude
Func _AxisDetermine($avArray)
    $test = $avArray[0]
    For $i = 0 To UBound($avArray)-1
        If $avArray[$i] <> $test Then Return 1
    Next
    Return 0
EndFunc
Edited by RazerM
My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

Very very nice :D

--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Link to comment
Share on other sites

Nice Razer, saves me trouble :D hehe.

I just found out Windows Vista is going to include a '3D Control'. I'm not sure what this is going to be, but if it is what i think it is - this won't really have much of a point. Yet, it's fun to do and if we get this faster, it might be good solution for those without Vista, ehh?

Link to comment
Share on other sites

  • 5 weeks later...

After a long while of silence, I figured it was time for another script. I've worked quite a while on this, and I can't say I am anywhere near completion. I do feel however, that this is ready for public use, and another reason i'm throwing this out is because i can really use a bit of help from the regulars. For now, the inputmanager requires beta. 3D.au3 contains the library.

I'd also like to thank nfwu a lot for the initial idea.

Anyway, just download the .zip, extract and play with it.

Edit: I also have a new best friend, Pythagoras. Developing the 3Dto2D() function was Hard!

Interesting start :-)

I used arjan staring's program

http://www.autoitscript.com/forum/index.php?showtopic=30045

But I think I found some strange behavior (for the Z axe)

this is my axe.3dp

[coordinates]
0=3
1=0,0,0-0,0,20-0x0000FF
2=0,0,0-0,20,0-0x008000
3=0,0,0-20,0,0-0xFF0000
[center]
x=200
y=200

the X axe is red

the Y axe is green

and the Z axe is blue

but when I load and play with it I found that your coordinate system

put X axe left to right

put Y axe bottom to top

put the Z axe going from the screen to the back ... ???

(Using a lefthand set of coordinate)

You should have put the Z axe in the other direction to have a normal set of coordinate.

(righthand set of coordinate)

I make life simpler for importing polygons ...

:-)

Edited by JoeCool
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...