Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

3D cude Image problem with sprites ? please help :)

Status
Not open for further replies.

00755

Programmer
Mar 31, 2005
6
0
0
GB
hi this my first time playing around with lingo and am using some code out of a book to create a 3d cude with images wrap around it. the problem is that it only using the first 6 sprites for images. and my images are on sprites 27,28,29,30,31,32. does any one no how to change it to read from the vaules i have the images on?? please find code below !!


global gCorners, gCenter, gRectList, gRotate, gPlane

on startMovie
-- initialize lists for a cube
initBox
end

on frameScript
-- add to rotation based on mouse location
gRotate = gRotate - (float(the mouseH-320)/30)*pi()/100

-- calc plane tilt based on mouse location
gPlane = - (float(the mouseV-240)/30)*pi()/20
drawSides
end

on initBox
-- list of corners with x, y and z coordinates
gCorners = [[-60,-60,-60],[60,-60,-60],[60,60,-60],\
[-60,60,-60],[-60,-60,60],[60,-60,60],\
[60,60,60],[-60,60,60]]

-- the screen center
gCenter = point(400,300)

-- list of sides
-- each side has four corners
gRectList = [[1,2,3,4],[1,2,6,5],[3,4,8,7],\
[2,3,7,6],[8,5,1,4],[5,6,7,8]]
end

on drawSides
-- generate a list of screen points and depths based on the
-- gCorners list and the transformation to 2d screen coordiantes
list = []
repeat with i = 1 to gCorners.count
temp = plotPoint(gCorners)
add list,temp
end repeat

-- create a quad list that takes four points to display a side of the cube
repeat with i = 1 to gRectList.count

-- get the four corners that make this side
thisRect = gRectList

-- get the four screen points to draw
q = [list[thisRect[1]][2],list[thisRect[2]][2],\
list[thisRect[3]][2],list[thisRect[4]][2]]

-- get the closest (depth) screen point
z = min(list[thisRect[1]][1],list[thisRect[2]][1],\
list[thisRect[3]][1],list[thisRect[4]][1])

-- draw the side
sprite(i).quad = q
sprite(i).locZ = z
end repeat
end




on plotPoint objectInfo
-- get x, y, and z from objectInfo list
x = getAt(objectInfo,1)
y = getAt(objectInfo,2)
z = getAt(objectInfo,3)

-- TRANSFORM BY ROTATION AROUND Z

-- compute the radius
radius = sqrt(x*x+y*y)

-- compute the angle
if x = 0.0 then angle = atan(the maxInteger)
else angle = atan(float(y)/x)
if y < 0 then angle = angle + pi()

-- rotate
set angle = angle+gRotate

-- compute new x, y, and z
realX = radius*cos(angle)
realZ = radius*sin(angle)
realY = Z

-- TRANSFORM BY ROTATION AROUND X

-- compute then radius
radius = sqrt(realY*realY+realZ*realZ)

-- compute the angle
if realZ = 0 then angle = atan(the maxInteger)
else angle = (atan(realY/realZ))
if realZ < 0 then angle = angle + pi()

-- rotate
angle = angle - gPlane

-- compute then new x, y and z
screenX = realX
screenY = radius*sin(angle)
screenZ = radius*cos(angle)

-- return both z, and the x and y point
return [screenZ,point(screenX,screenY)+gCenter]
end
 
If you change these lines:
--
sprite(i).quad = q
sprite(i).locZ = z
--
to:
--
sprite(i + 26).quad = q
sprite(i + 26).locZ = z
--
then it'll use sprite 27 - 32 instead of sprite 1 - 6.

Kenneth Kawamoto
 
cheers for the reply very helpful !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top