Plotting A 3D Ellipse

Blitz3D Forums/Blitz3D Programming/Plotting A 3D Ellipse

bedhouin(Posted 2005) [#1]
I'm trying to plot an ellipse depicted in three dimensional space. B3D doesn't seem to be able to do this natively (that I can see).

So far what I've theorised is that in order to plot it manually I would have to recursively calculate points on the circumference of the the ellipse and join them together with lines or cylinders. The more iterations I perform the smoother the ellipse should look.

Is there a better solution?

Any suggestions would be appreciated.


Stevie G(Posted 2005) [#2]
Like this? Just threw together ....



Graphics3D 640,480,16,1

Global camera = CreateCamera():PositionEntity camera, 0,0,-10
Global sphere = CreateSphere():ScaleMesh sphere , 2,1,1:EntityAlpha sphere, 0

While Not KeyDown(1)

	TurnEntity sphere , 0 , 1, 0
	RenderWorld()
	SPHEREplot( sphere )
	Flip

Wend


Function SPHEREplot ( entity )

	s = GetSurface( entity , 1 )

	For v = 0 To CountVertices( s) -1
		TFormPoint VertexX( s, v ) , VertexY( s, v ) , VertexZ( s, v ) , entity , 0
		CameraProject Camera , TFormedX(), TFormedY(), TFormedZ()
		Plot ProjectedX(), ProjectedY()
	Next
	
End Function




RGR(Posted 2005) [#3]
Graphics3D 1024,768,32,2
camera=CreateCamera()
PositionEntity camera,0,0,-10
sphere=CreateSphere(32)
ScaleEntity sphere,4,0.01,6,True
RotateEntity sphere,20,40,60
tex=CreateTexture(256,256,4)
SetBuffer TextureBuffer(tex)
;to show the ellipse filled unrem the next line
;ClsColor 0,64,0
Cls
;to show upper side and lower side unrem the next lines
;Color 0,127,0
;Rect 0,0,256,128
;Color 127,0,0
;Rect 0,128,256,128
Color 255,255,0
Rect 0,111,256,32
EntityTexture sphere,tex
EntityFX sphere,17
SetBuffer BackBuffer()
CameraClsColor camera,0,0,127
Repeat
	TurnEntity sphere,1,0.5,0.1,True
	UpdateWorld()
	RenderWorld()
	Flip
Until KeyHit(1)
End
An Ellipse ;-)


RGR(Posted 2005) [#4]
Price Question: Where is the error ?
The TextureFilterFlag is set to masked - means (as stated in in the docu) color 0,0,0 will not be displayed - but when I added CameraClsColor it shows that this is not true in this example ... it should display the ring only

If I make an image and use
tex=LoadTexture("EllipseTex.png",4)

it works as expected
So whats wrong with CreateTexture ?


bedhouin(Posted 2005) [#5]
Thanks guys very snazzy!

Just to give you a bit of background, I'm trying to draw ellipses to show the orbital path of planets. So the ellipses will be an outline that has to be calculated with fixed major/minor axes and eccentricity values.

RaGR:
The end result of your code is exactly what I was looking for. But I can't see which part of it let's me alter the major and minor axes to change eccentricity?

Stevie G:

That's a cool little demo, I can think I can apply that for some neat effects. But I should have mentioned that I need something to show elliptical orbits, an ellipsoid won't show that.


RGR(Posted 2005) [#6]
ScaleEntity sphere x and z to match major and minor axis
PositionEntity where the mass point is calculated
RotateEntity to match pitch and yaw and if such things exist in planets orbits roll.

But Spheres waste too many (unseen) vertices anyway. What you need are rings made of quads, where vertices are placed where your formula calculates them.


Stevie G(Posted 2005) [#7]
To be honest I didn't think this was what you meant.

Create texture automatically assumes full alpha on each pixel in the texture you have to go through the texture and set the alpha bit to 0 to mask it. See Ross C's code in the archives.

This is the kind of thing you want .. at least it'll get oyu on the right track.

Graphics3D 640,480,16,1

Global Camera = CreateCamera():PositionEntity Camera, 0,100,-200
Global Ellipse = CreateEllipse( 50 , 45 ):ScaleEntity Ellipse , 1,1,2
PointEntity Camera, Ellipse

While Not KeyDown(1)

	TurnEntity Ellipse ,1, 1, 0
	RenderWorld()
	Flip

Wend

;=========================================
;=========================================
;=========================================

Function CreateEllipse( r1# , r2# )

	mesh = CreateMesh()
	s = CreateSurface( mesh )

	For a1 = 0 To 359
		a2 = ( a1+1) Mod 360
		v0 = AddVertex( s, r1*Cos( a1 ) , 0 , r1*Sin( a1 ) ) 
		v1 = AddVertex( s, r1*Cos( a2 ) , 0, r1*Sin( a2 ) )
		v2 = AddVertex( s, r2*Cos( a2 ) , 0, r2*Sin( a2 ) )
		v3 = AddVertex( s, r2*Cos( a1 ), 0 , r2*Sin( a1 ) )
		AddTriangle s,v2,v1,v0
		AddTriangle s,v0,v3,v2
	Next

	EntityFX mesh , 16+1
	EntityAlpha mesh,.5
	Return mesh
		
End Function		
		




bedhouin(Posted 2005) [#8]
RaGR/Stevie G:

Thanks guys, that's a great help.


RGR(Posted 2005) [#9]
Thank you Stevie G. That's why it loads the Image as Texture and works; while just clearing Texture as active Buffer doesn't. What makes sense... otherwise clearing the screen to a black background would probably make it transparent as well?!
Learning every day...


Ross C(Posted 2005) [#10]
Setting pixels to black in blitz doesn't write any alpha information. When texture are loaded, depending on the flag used, blitz will write black as transparent.

http://www.blitzbasic.com/codearcs/codearcs.php?code=1013

Might help you...


RGR(Posted 2005) [#11]
Thanks Ross C - I saw that before
The misinterpretation was caused by the fact, that I created a Texture with CreateTexture(x,y,4). So I believed that setting the maskflag would make clear to Blitz that 0,0,0 is the mask (as its stated in the docu) and that its Blitzs turn to do the right thing. Otherwise what is it worth to set a Flag if it has no effect? And the effect appears only when you LoadTexture? If it can do it while Loading why can't it doing it at Creating?
This causes irritation!
Loading a 24Bit colored Texture creates the mask automatic if the Flag is set - Creating a 24Bit colored Texture does it not although the Flag is set.
Maybe or obviously the Flag is only a signal to display it masked... but one still expects that rather the same action causes the same behavior - in this case ORs $ff000000 to a created Texture as its done to a loaded one.

(Edited) And this shows again, that Blitz3D urgently needs a major update - some little things here - some bigger things there!
For instance to solve problems like the one above: Color r,g,b[,a] ClsColor r,g,b[,a] and so on and on and 100s of other things out of the 1000s that have been suggested...

BMax killed B3D ;-(
(Correction) It didn't kill it - it's still alive - but its starving and gets isolated without attention ;-|