Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 3D program, Camera help.
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
copthesaint




PostPosted: Thu Apr 09, 2009 9:59 pm   Post subject: 3D program, Camera help.

Ok so currently this program will create a rectangular prism at a point and using the arrow keys you can move the camera around the object. What I want to do is now is by using the 'a' and 'd' I want to change the spin for the camera to rotate it. Also I want to change the pitch (vertical angle) with the keys 'w' and 's' . But I don't know how to use Sind / Cos.
If some could maybe spend a couple of min. to help teach me what they do that would be great. Thanks.
Also any help for how to improve this would be great.
Sponsor
Sponsor
Sponsor
sponsor
TokenHerbz




PostPosted: Sat Apr 11, 2009 10:51 am   Post subject: RE:3D program, Camera help.

3D coding isn't about programming, its mostly about math, So unless you have a great understanding on math skills needed, (you can read about it online and learn it) I wouldn't bother with this because it'll overwhelm you.

Learn the math first, the coding isn't nearly as time consuming as the time your spend thinking about what your doing.

None the less, I Wouldn't even run any 3D things on Turing, it's way to slow and crap-tastic..

My two cents Smile
saltpro15




PostPosted: Sat Apr 11, 2009 11:27 am   Post subject: RE:3D program, Camera help.

I agree with Tokenherbz, it'll be way too slow in Turing, I recommend doing it in c++ with openGL if you want it to run smoothly
copthesaint




PostPosted: Sun Apr 12, 2009 12:57 am   Post subject: Re: 3D program, Camera help.

saltpro15 wrote:

I agree with Tokenherbz, it'll be way too slow in Turing, I recommend doing it in c++ with openGL if you want it to run smoothly

I DON'T, care if it runs slow. I want to use a basic program that will require a min of required code use to make this program. Again speed is not an issue.

Now does anyone want to try and help me or just criticize me?
I am willing to spend any amount of time and don't post "well why don't you talk to your teachers" because now of them will ever help me at there own time.

Moderator edit: Removed flaming, for the better.
[Gandalf]




PostPosted: Sun Apr 12, 2009 1:28 am   Post subject: RE:3D program, Camera help.

copthesaint, he wasn't trying to insult you. At least if he was, he definitely wasn't doing a good job of it.

It's simply true that making a 3D engine will require as much math as programming skill, if not more. That's not to discourage you or say you will fail, however you should look into the math before moving on. Especially if you don't even know basic trigonometry.

Keep at it, keep reading about trig, matrices, etc and you'll be well on your way.
saltpro15




PostPosted: Sun Apr 12, 2009 8:00 am   Post subject: RE:3D program, Camera help.

haha alright, but when it's running at 2 fps and you're beating your head off the keyboard, well, don't blame me...

http://compsci.ca/v3/viewtopic.php?t=19526&highlight=engine

this'll help
copthesaint




PostPosted: Sun Apr 12, 2009 2:50 pm   Post subject: RE:3D program, Camera help.

Yea it would help if there were comments. I've already looked at this before, but this doesn't help without explaining the code.
zero-impact




PostPosted: Sun Apr 12, 2009 6:25 pm   Post subject: RE:3D program, Camera help.

http://compsci.ca/v3/viewtopic.php?t=20164&highlight=zeroimpact

I made this engine a few months ago.

Eventually DemonWasp stepped in and helped me out a bit. My original versions are rather small and shouldn't be that hard to understand.

Here is a modified version by DemonWasp that has comments in neccesary places.

http://compsci.ca/v3/download.php?id=6246

You can pm me if you have any further questions about it because i may forget about this thread Razz
Sponsor
Sponsor
Sponsor
sponsor
copthesaint




PostPosted: Sun Apr 12, 2009 8:37 pm   Post subject: RE:3D program, Camera help.

Thank you Zero-impact, and I will Pm you for help after I've tried to learn from this. Hopefully after two or so weeks, I will understand the concept of 3D better.
The File (Vector3f.t) is not available. you forgot to upload it with demons 3d engine
zero-impact




PostPosted: Sun Apr 12, 2009 8:47 pm   Post subject: RE:3D program, Camera help.

If you search around on that thread you can find it. Good luck!
copthesaint




PostPosted: Mon Apr 13, 2009 9:48 pm   Post subject: RE:3D program, Camera help.

Ok. How would I rotate a 2d square? (Don't be "funny" and say Pic.Rotate.) I want to have it so that the square or polygon, Is actually rotating, AND still staying at its same point. I realized that to make a 3d program, the object will have to rotate at it's x,y, and z axis. doing this you can see all the faces of the shape. Help would be nice :p and thank you to who ever helps me!

I have been tring different things and had in ways some success, but As this is the 4th time typing this post , I cant explain what I've done...
zero-impact




PostPosted: Mon Apr 13, 2009 10:01 pm   Post subject: RE:3D program, Camera help.

Google is your friend Smile

http://www.google.ca/search?q=2d+rotation
copthesaint




PostPosted: Tue Apr 14, 2009 1:18 pm   Post subject: Re: 3D program, Camera help.

Ok I want my square to accually spin. But the square it's self just moves in a circle.
Can someone explain what I have to do to get the sqare to stay in one spot but still rotate?
Turing:
/** Declaration
 *Variables, Types, and Constants
 */

type Camera :
    record
        Dis, X, Y : real
    end record
var C : Camera
C.Dis := 600

/** Functions List
 *Get Radius
 *RotateX
 *RotateY
 *Distance
 *To3D
 */

fcn GetRadius (X1, Y1, X2, Y2 : real) : real
    result sqrt ((((X2 - X1) / 2) ** 2) + (((Y2 - Y1) / 2) ** 2))
end GetRadius

fcn RotateX (Degree, Radius : real) : real
    result ((cos (Degree mod 360) * Radius) - (sin (Degree mod 360) * Radius))
end RotateX

fcn RotateY (Degree, Radius : real) : real
    result ((sin (Degree mod 360) * Radius) + (cos (Degree mod 360) * Radius))
end RotateY

fcn Distance : real
    result C.Dis
end Distance

fcn To3D (V, Z : real) : int
    result round ((V) - (V / (Distance / Z)))
end To3D
/** Procedures
 *Cube
 */

proc Cube (FX1, FX2, FY1, FY2, FZ1, FZ2 : real, Color : int, Pitch, Roll, Spin : real)
    var Radius : real := GetRadius (To3D (FX1, FZ1), To3D (FY1, FZ1), To3D (FX2, FZ1), To3D (FY2, FZ1))div 2
    drawline (To3D (FX1, FZ1) + round (RotateX (Roll, Radius)), To3D (FY1, FZ1) + round (RotateY (Roll, Radius)), To3D (FX1, FZ1) + round (RotateX (Roll, Radius)), To3D (FY2, FZ1) +
        round (RotateY (Roll, Radius)), Color)
    drawline (To3D (FX2, FZ1) + round (RotateX (Roll, Radius)), To3D (FY1, FZ1) + round (RotateY (Roll, Radius)), To3D (FX2, FZ1) + round (RotateX (Roll, Radius)), To3D (FY2, FZ1) +
        round (RotateY (Roll, Radius)), Color)
    drawline (To3D (FX1, FZ1) + round (RotateX (Roll, Radius)), To3D (FY1, FZ1) + round (RotateY (Roll, Radius)), To3D (FX2, FZ1) + round (RotateX (Roll, Radius)), To3D (FY1, FZ1) +
        round (RotateY (Roll, Radius)), Color)
    drawline (To3D (FX1, FZ1) + round (RotateX (Roll, Radius)), To3D (FY2, FZ1) + round (RotateY (Roll, Radius)), To3D (FX2, FZ1) + round (RotateX (Roll, Radius)), To3D (FY2, FZ1) +
        round (RotateY (Roll, Radius)), Color)
end Cube
View.Set ("offscreenonly")
var i : real := 0
loop
    i += 0.1
    Cube (50, 100, 50, 100, 500, 4, red, i, i, i)
    View.Update
    cls
    delay (50)
end loop
Homer_simpson




PostPosted: Wed Apr 15, 2009 1:22 am   Post subject: Re: 3D program, Camera help.

you must rotate every vertex in your cube around the center of the cube and you calculate the center of your cube by getting the average of every coordinate like so
centerx= (x1+x2+x3+x4+x5)/5

and so on
copthesaint




PostPosted: Thu May 21, 2009 1:34 pm   Post subject: Re: 3D program, Camera help.

Well Ive kept trying for a while but just recently we started laerning trig. The following code does creat a '3d' shape, but I would like to know what to do next to rotate.

Turing:
            module Shape
    export ClearData, Prism, Move, Sketch
    const ShapeID := 100000
    const MaxShapes := 10000 %max number of shapes you can have.

    type NfoShape : %Shapes Info to be set for each var.
        record
            Type, Sides, ID : int
            X, Y, Z, Length, Width, Height : real
        end record
    var S : array 1 .. MaxShapes of NfoShape

    proc ClearData
        for i : 1 .. MaxShapes
            S (i).ID := 100000
            S (i).X := 0
            S (i).Y := 0
            S (i).Z := 0
            S (i).Length := 0
            S (i).Width := 0
            S (i).Height := 0
            S (i).Sides := 0
            S (i).Type := 0
        end for
    end ClearData

    fcn IDGet : int %Gets The ID of the Shape
        for i : 1 .. MaxShapes %Max Number of shapes Allowed
            if S (i).ID not= ShapeID then
                if i = MaxShapes then
                    quit %If this Quit is run then you have to many shapes
                end if
            elsif S (i).ID = ShapeID then
                result ShapeID + i
            end if
        end for
    end IDGet

    fcn IDSave (Num : int) : boolean
        if S (Num).ID not= ShapeID then
            result false
        elsif S (Num).ID = ShapeID then
            S (Num).ID := ShapeID + Num
            result true
        end if
    end IDSave

    fcn Prism (Length, Width, Height : real, Sides : int) : int
        var Num : int := IDGet
        if IDSave (Num - ShapeID) = true then
            S (Num - ShapeID).Length := Length
            S (Num - ShapeID).Width := Width
            S (Num - ShapeID).Height := Height
            S (Num - ShapeID).Sides := Sides
            S (Num - ShapeID).Type := 2
            result Num
        end if
    end Prism

    proc Move (var Shape : int, X, Y, Z : real)
        S (Shape - ShapeID).X := X
        S (Shape - ShapeID).Y := Y
        S (Shape - ShapeID).Z := Z
    end Move

    proc Sketch (var Shape : int, Color : int)
        for z : -180 .. 180 by (360 div S (Shape - ShapeID).Sides) %even angle for the number of sides
            for o : 1 .. S (Shape - ShapeID).Sides %for the number of sides
                %drawline (round (S (Shape - ShapeID).X + (cosd ((o * (360 / S (Shape - ShapeID).Sides))) * ((z * (S (Shape - ShapeID).Width / 360))))), % if you uncomment this a line will be drawn
                    %round (S (Shape - ShapeID).Y + (sind (o * (360 / S (Shape - ShapeID).Sides)) * (z * (S (Shape - ShapeID).Length / 360)))), % from each point to the next
                    %round (S (Shape - ShapeID).X + (cosd ((o * (360 / S (Shape - ShapeID).Sides))) * (((z + (360 / S (Shape - ShapeID).Sides)) * (S (Shape - ShapeID).Width / 360))))),
                    %round (S (Shape - ShapeID).Y + (sind (o * (360 / S (Shape - ShapeID).Sides)) * ((z + (360 / S (Shape - ShapeID).Sides)) * (S (Shape - ShapeID).Length / 360)))), Color)
                    drawfilloval (round (S (Shape - ShapeID).X + (cosd ((o * (360 / S (Shape - ShapeID).Sides))) * ((z * (S (Shape - ShapeID).Width / 360))))),
                    round (S (Shape - ShapeID).Y + (sind (o * (360 / S (Shape - ShapeID).Sides)) * (z * (S (Shape - ShapeID).Length / 360)))),
                    1,1, Color)
delay (1)
            end for
        end for
    end Sketch
end Shape
Shape.ClearData
var cube : int := Shape.Prism (250, 250, 50,45)%the last value changes the sides, max 360 min 1
Shape.Move (cube, maxx / 2, maxy / 2, 0)
Shape.Sketch (cube, brightblue)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: