Dark Bit Factory & Gravity

PROGRAMMING => General coding questions => Topic started by: Clyde on October 14, 2006

Title: Copying And Rotating 3D Points in a 2D routine.
Post by: Clyde on October 14, 2006
Here's the scenario, I am trying to make a routine to build a 3D object with 2D commands.

And the problem I have come to is that I need and want to be able to Copy a set of Points (PosX(amount), Dim PosY(amount), PosZ(amount) ); for arguments sake call it 12 in total. And then have them Rotated to new positions, as the shape that the points are forming are all identical; I just need to have them placed around. Think of the initial points as a Shape / serperate mesh.

for getting the new 3D positions for the rotating and setting into the new position; I will be using a For x / y loop based around a circle. for instance For y=0 to 4, For y=0 to 5. So if my brain is slightly working right, that'll be total points of 4*5*12

real sorry for the lack of code, it's just that I left my feeble attempt at home along with my brain cell. And I came across a brick wall with trying to Copy and rotate a set of co-ordinates.

Many thanks for your assistance,
Clyde.

Title: Re: Copying And Rotating 3D Points in a 2D routine.
Post by: Shockwave on October 16, 2006
If I'm reading this right you could keep the object simple and use a bezier routine to adjust the detail?
Title: Re: Copying And Rotating 3D Points in a 2D routine.
Post by: Clyde on October 18, 2006
Im not really sure what is meant by a bezier routine mate, and as for coding one im clueless.
I got the idea to build objects made from points, from looking at some Blitz 3D examples that use RotateMesh * AddMesh, but with only needing the points xyz positions.
Title: Re: Copying And Rotating 3D Points in a 2D routine.
Post by: Shockwave on October 18, 2006
Here you go;

http://dbfinteractive.com/index.php?topic=632.0

Try changing the step size in the "for t=" loop to adjust the detail.
Title: Re: Copying And Rotating 3D Points in a 2D routine.
Post by: Clyde on October 18, 2006
Ta mate, will have a look.
Title: Re: Copying And Rotating 3D Points in a 2D routine.
Post by: Clyde on October 18, 2006
Thats a great routine and thanks.

What I want to do, is copy a range of points that are allready defined, and place them at intervals going around at specified new places. I'll post up a small B3D example that should help; but it's a 2D question.
Title: Re: Copying And Rotating 3D Points in a 2D routine.
Post by: Shockwave on October 18, 2006
Ok :)
Title: Re: Copying And Rotating 3D Points in a 2D routine.
Post by: Clyde on October 18, 2006
Here's an example in B3D of the gist of what im trying to do. Maybe there's a real simple way via a function/sub in FB and in 2D stuff that Im overlooking.
(btw, the code is for demonstrating what im after, it wont work properlly as i've missed out the vertex building )

Code: [Select]
;
; Copying points to new positions example.
;

Graphics3D 640,480
SetBuffer BackBuffer()

CreateCamera 0,0,-5

Global MainObject

Const Points=180

Dim ObjectX#( Points ), ObjectY#( Points ), ObjectZ#( Points )


Function CreateSegments()

MainObject=CreateMesh()

MainPoints =SetupPoints( 12 ) ;Number of points in the range.

;
; Add multiple instances of the tentacle to the octopus.
;
For y = 0 To 5
For x = 0 To 4
RotateMesh MainPoints, 0, intX * 360 / 4, intY * 360 / 5
AddMesh( MainPoints, MainObject )
Next
Next

FreeEntity MainPoints

End Function



Function SetupPoints( PointsRange )

Local Angle#=4

For intX = 0 To PointsRange-1

ObjectX(a) = Float PointsRange - a
ObjectY(a) = Float a / PointsRange
ObjectZ(a) = Cos( angle*a*24) * (1 - Float a/PointsRange) * 4


Next

End Function

Cheers Clyde.
Title: Re: Copying And Rotating 3D Points in a 2D routine.
Post by: Shockwave on October 18, 2006
I can't get it to run, but looking at the code it seems to do this.. Say you had an object;

+-----+-----+

Where + are the points

You want to be able to create;

+-+-+-+-+-+-+

Something like that out of defining only a few points?

If so, the bezier is a good way of doing it.
Title: Re: Copying And Rotating 3D Points in a 2D routine.
Post by: Clyde on October 18, 2006
Basically what Im trying to do is an object like an Octopusses Tentacles. Where the other arms of the octopus are exactly the same as the original points, but just positioned at different intervals, and don't join on from the last set of points.

\|/
/|\
Title: Re: Copying And Rotating 3D Points in a 2D routine.
Post by: relsoft on October 20, 2006
You could abuse GL's stack for that and do heirarchal transforms. 

Code: [Select]
pushmatrix

for i = 0 to tentacles-1
  pushmatrix
   for j = 0 to segments-1
      transform(translate, rotate, etc)
   next j
  popmatrix
next i

popmatrix

Here's the delphi code made by Jan Horn of sulaco of a tentacle. I ported it to FB if you want to see.
http://www.sulaco.co.za/opengl_project_biohazard-optimize_2001_megademo.htm

(http://www.sulaco.co.za/opengl/biohazard.jpg)

It's not that hard to do with your own matrix routines too. All you have to do is dim enough matrix to hold each segment's orientation.
Title: Re: Copying And Rotating 3D Points in a 2D routine.
Post by: Clyde on October 20, 2006
Thanks for that dude. Looks awesome.
I have got code for a Blitz3D one, that at some stage I'll put together for a Blitz demo.

I am wanting to do it without the need for OGL, and just Dim's in Tinyptc.
All I need is a way of copying and rotating the initial points at intervals.