Balloon3D problem
David Duke
D.Duke at bath.ac.uk
Tue Jul 2 16:59:00 UTC 2002
Joshua 'Schwa' Gargus wrote:
> On Tue, Jul 02, 2002 at 03:04:27PM +0100, David Duke wrote:
>>Now the problem: I get not one, but two debugger windows opening,
>>neither of which will respond to user input. In fact, the entire squeak
>>application seems to lock up.
> That's probably because it's trying to open a new debugger each time
> the B3DSceneMorph is redrawn, and the system grinds to a halt from the effort. Instead of opening the B3DSceneMorph in
> the world, create an instance in a workspace, but don't open it ('b3d
> _ B3DSceneMorph new'). You can then tell it to draw itself once with
> 'b3d debugDraw', which will allow you to halt and step through the
> code.
Hi Joshua,
Many thanks for your help -- it hadn't occurred to me that the redraws
would be triggered repeatedly even with the debugger active.
I noticed that the geometry I included for the cone (specifically, the
vertex indices in the Faces array) was incorrect; I may have forgotten
to save the image at some point while changing the vertex numbering. In
case anyone is looking at it, an updated version is attached.
I'm still having the segmentation fault; although I can now at least
look more closely at what is going on, I would still be grateful for any
suggestions.
David.
--
Dr. David Duke Email: D.Duke at bath.ac.uk
Department of Computer Science Web: www.bath.ac.uk/~masdad/
University of Bath Tel: +44 1225 323 407
Bath, BA2 7AY U.K. Fax: +44 1225 323 493
-------------- next part --------------
'From Squeak3.2gamma of 15 January 2002 [latest update: #4881] on 2 July 2002 at 5:53:07 pm'!
B3DGeometry subclass: #B3DCone
instanceVariableNames: 'vertices normals bbox '
classVariableNames: 'Colors Faces '
poolDictionaries: ''
category: 'DJD - Balloon3D'!
!B3DCone commentStamp: 'DJD 7/2/2002 14:47' prior: 0!
Build a cone, approximated by a 6-sided pyramid, i.e. 6 triangular faces and a hexagonal base.
Allow the cone to be rendered via Balloon3D.
Instance variables:
vertices Array of B3DVector3 -- 7 vertices of the cone, 1-6 around the base, 7 is the apex.
normals Array of B3DVector3 -- 7 normal vectors, one per face.
bbox Rectangle -- bounding box for the cone.
Class variables:
Faces Array of Array of Number -- per-face indexes into vertex array
Colors Array of Color -- per-face color.
Construction:
B3DCone radius: R height: H builds cone with base inscribed in a circle of radius R, and with height H.
Note:
Class variables (Faces and Colors) need to be initialized. This is done in the class method "initialize". Q: who invokes this?
!
!B3DCone methodsFor: 'as yet unclassified' stamp: 'DJD 7/2/2002 13:01'!
boundingBox
^ bbox! !
!B3DCone methodsFor: 'as yet unclassified' stamp: 'DJD 7/2/2002 14:32'!
buildWithRadius: r height: h
"Make a 6-sided cone with base radius r and height h. The base is in the x-y plane, the apex is
along the positive z-axis."
vertices _ Array new: 7.
"Define the vertices for the base - vertex numbers 1-6"
1 to: 6 do: [:i |
vertices at: i put: B3DVector3 new.
(vertices at: i) x: (r * ((i * Float pi / 3.0) cos)) y: (r * ((i * Float pi / 3.0) sin)) z: 0.0.
].
"Cone apex is vertex 7."
vertices at: 7 put: B3DVector3 new.
(vertices at: 7) x: 0.0 y: 0.0 z: h.
"Calculate normals for the triangular sides."
normals _ Array new: 7.
1 to: 6 do: [:i | | vecA vecB |
vecA _ (vertices at: ((Faces at: i) at: 1)) - (vertices at: ((Faces at: i) at: 2)).
vecB _ (vertices at: ((Faces at: i) at: 1)) - (vertices at: ((Faces at: i) at: 3)).
normals at: i put: (vecA cross: vecB) normalized.
].
"Base normal is unit vector along negative z axis."
normals at: 7 put: B3DVector3 new.
(normals at: 7) x: 0.0 y: 0.0 z: (1.0 negated).
"Calculate bounding box for the cone. In fact, the box returned is slightly larger
than required."
bbox _ Rectangle origin: (r @ r @ 0) corner: ((r negated) @ (r negated) @ h).
! !
!B3DCone methodsFor: 'as yet unclassified' stamp: 'DJD 7/2/2002 14:35'!
renderOn: aRenderer
"Render the cone using aRenderer; code based on B3DBox>>renderOn."
"Render the triangular sides."
1 to: 6 do: [:i |
aRenderer
trackEmissionColor: true;
normal: (normals at: i);
color: (Colors at: i);
drawPolygonAfter: [
1 to: 3 do: [:v |
aRenderer
vertex: (vertices
at: ((Faces at: i) at: v)).
]
]
].
"Render the base."
aRenderer
trackEmissionColor: true;
color: (Colors at: 7);
drawPolygonAfter: [
1 to: 6 do: [:v | aRenderer vertex: (vertices at: ((Faces at: 7) at: v)) ]
].
! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
B3DCone class
instanceVariableNames: ''!
!B3DCone class methodsFor: 'as yet unclassified' stamp: 'DJD 7/2/2002 17:24'!
initialize
"B3DCone initialize"
Faces _ #((1 2 7) (2 3 7) (3 4 7) (4 5 7) (5 6 7) (6 1 7) (1 2 3 4 5 6)).
Colors _ #(red green blue yellow gray cyan white) collect: [:s | (Color perform: s) alpha: 0.5].! !
!B3DCone class methodsFor: 'as yet unclassified' stamp: 'DJD 7/1/2002 17:03'!
radius: rad height: ht
"Create a cone with the given height and radius."
^self new buildWithRadius: rad height: ht.
! !
B3DCone initialize!
More information about the Squeak-dev
mailing list
|