User File #49956245481476145

Upload All User Files

#49956245481476145 - N64 Chameleon Twist Map collision lua script

Chameleon Twist (USA) canvas.lua
753 downloads
Uploaded 9/19/2018 6:37 PM by TASeditor (see all 188)
Some things not displayed correctly, due to scaling, yet.
Also better visualization for polygon heigth and steepness is needed.
size_x = 800
size_y = 800

Xdraw = size_x / 2
Ydraw = size_y / 2

canv = gui.createcanvas(size_x, size_y)
canv.SetTitle("Hitbox viewer")

Zoom = 1;
old_mX = 0
old_mY = 0
memory.usememorydomain("RDRAM")


while true do
	
	canv.Clear("white")
	--Player
	xpos = memory.readfloat(0x174C2C, true)
	ypos = memory.readfloat(0x174C30, true)
	zpos = memory.readfloat(0x174C34, true)
	
	xposprev = memory.readfloat(0x174C38, true)
	yposprev = memory.readfloat(0x174C3C, true)
	zposprev = memory.readfloat(0x174C40, true)

	xspeed = memory.readfloat(0x174C4C, true)
	yspeed = memory.readfloat(0x174C50, true)
	zspeed = memory.readfloat(0x174C54, true)

	yangle = memory.readfloat(0x174C64, true)
	xyspeed = memory.readfloat(0x174C68,true)
	xzacceleration = memory.readfloat(0x174C6C, true) 

	radius = memory.readfloat(0x174C74, true)
	height = memory.readfloat(0x174C78, true) 
	
	--Level objects
	local lvl_obj_list_size = memory.read_u32_be(0x249F20)
	local lvl_obj_list_ptr = 0x8024AAF8
	
	for i = 1, lvl_obj_list_size, 1 do
		
		local addr = memory.read_u32_be(lvl_obj_list_ptr-0x80000000) - 0x80000000
		
		local index = memory.read_u32_be(addr+0)
		local index2 = memory.read_u32_be(addr+4)
		
		local state = memory.read_u32_be(addr+12)

		local x_ = memory.readfloat(addr+24, true)
		local y_ = memory.readfloat(addr+28, true)
		local z_ = memory.readfloat(addr+32, true)
		
		local x = memory.readfloat(addr+48, true)
		local y = memory.readfloat(addr+52, true)
		local z = memory.readfloat(addr+56, true)
		
		local x_scale = memory.readfloat(addr+80, true)
		local y_scale = memory.readfloat(addr+84, true)
		local z_scale = memory.readfloat(addr+88, true)

		--Bounding Box
		local x1 = memory.readfloat(addr+204, true)
		local y1 = memory.readfloat(addr+208, true)
		local z1 = memory.readfloat(addr+212, true)
		local x2 = memory.readfloat(addr+216, true)
		local y2 = memory.readfloat(addr+220, true)
		local z2 = memory.readfloat(addr+224, true)
		
		local col_ptr = memory.read_u32_be(addr+228)
		local ver_ptr = memory.read_u32_be(addr+232)
		
		--local _max = y2
		--local _min = y1
		
		local list_1_size = memory.read_u32_be(ver_ptr - 0x80000000)
		local list_2_size = memory.read_u32_be(ver_ptr+4 - 0x80000000)
		local list_1_start_ptr = memory.read_u32_be(ver_ptr+8 - 0x80000000) 
		local list_2_start_ptr = memory.read_u32_be(ver_ptr+12 - 0x80000000)
		local list_3_start_ptr = memory.read_u32_be(ver_ptr+16 - 0x80000000)
		
		for j = 0, list_2_size-1, 1 do--19-3
		
			local addr1 = (list_1_start_ptr - 0x80000000)
			local addr2 = (list_2_start_ptr - 0x80000000)+(j)*12

			local p1 = addr1 + memory.read_u32_be(addr2+0)*12
			local p2 = addr1 + memory.read_u32_be(addr2+4)*12						
			local p3 = addr1 + memory.read_u32_be(addr2+8)*12
			
			local dx1 = memory.readfloat(p1+0, true)
			local dy1 = memory.readfloat(p1+4, true)
			local dz1 = memory.readfloat(p1+8, true)
			local dx2 = memory.readfloat(p2+0, true)
			local dy2 = memory.readfloat(p2+4, true)
			local dz2 = memory.readfloat(p2+8, true)
			local dx3 = memory.readfloat(p3+0, true)
			local dy3 = memory.readfloat(p3+4, true)
			local dz3 = memory.readfloat(p3+8, true)
			
			local mx=1/3*(dx1+dx2+dx3+3*x)
			local my=1/3*(dy1+dy2+dy3+3*y)
			local mz=1/3*(dz1+dz2+dz3+3*z)
				
			if math.abs(my) < 1000/1
			then red = 80
				 green = math.floor((255/1000/1)*math.abs(my))
				 blue = 255
			else red = 80
				 green = 180
				 blue = math.floor(-(255/1000/1)*math.abs(my)+510)
			end
			
			canv.DrawPolygon({{Xdraw-(xpos-(x+dx1))*Zoom,Ydraw-(zpos-(z+dz1))*Zoom},
						{Xdraw-(xpos-(x+dx2))*Zoom,Ydraw-(zpos-(z+dz2))*Zoom},
						{Xdraw-(xpos-(x+dx3))*Zoom,Ydraw-(zpos-(z+dz3))*Zoom}},0xFF000000, 0x44000000+red*256*256+green*256+blue)					
			canv.DrawAxis(Xdraw-(xpos-mx)*Zoom, Ydraw-(zpos-mz)*Zoom, 2, 0xFF005555)			
								
		end
		
				
		canv.DrawAxis(Xdraw-(xpos-x)*Zoom, Ydraw-(zpos-z)*Zoom, 2, 0xFFFF0000)
		canv.DrawBox(Xdraw-(xpos-x1)*Zoom, Ydraw-(zpos-z1)*Zoom, Xdraw-(xpos-x2)*Zoom, Ydraw-(zpos-z2)*Zoom,0xFFFF0000)--, 0x55550022
		lvl_obj_list_ptr = lvl_obj_list_ptr + 4
	end
		
	--Player
	canv.DrawLine(Xdraw, Ydraw, Xdraw+math.cos(yangle*math.pi/180)*radius*Zoom, Ydraw-math.sin(yangle*math.pi/180)*radius*Zoom, 0xFF550000);
	canv.DrawEllipse(Xdraw-radius*Zoom, Ydraw-radius*Zoom, radius*2*Zoom, radius*2*Zoom, 0xFFFF0000, 0x55FF0000);
	
	--Tounge
	size = memory.read_u32_be(0x1750F0)
	for i = 0, size-1, 1 do
		--TODO
		--local radius = memory.readfloat(0x1750E0, true)
		--local height = memory.readfloat(0x1750E0, true)

		
		local t_relx1 = memory.readfloat(0x175100+4*i, true)
		local t_rely1 = memory.readfloat(0x175188+4*i, true)
		local t_relz1 = memory.readfloat(0x175208+4*i, true)
		
		canv.DrawAxis(Xdraw+t_relx1*Zoom, Ydraw+t_relz1*Zoom, 5)
		--canv.DrawEllipse(Xdraw+(t_relx1-radius)*Zoom, Ydraw+(t_relz1-radius)*Zoom, radius*2*Zoom, radius*2*Zoom)
	end
	
	--Objects
	size = memory.read_u32_be(0x252274)
	for i = 0, size, 1 do
	
		local obj_type = memory.read_u8(0x176AEB+0x174*i)
		
		local obj_xpos = memory.readfloat(0x176B0C+0x174*i, true)
		local obj_ypos = memory.readfloat(0x176B10+0x174*i, true)
		local obj_zpos = memory.readfloat(0x176B14+0x174*i, true)
		      
		local obj_xspeed = memory.readfloat(0x176B18+0x174*i, true)
		local obj_yspeed = memory.readfloat(0x176B1C+0x174*i, true)
		local obj_zspeed = memory.readfloat(0x176B20+0x174*i, true)
		      
		local obj_scalexz = memory.readfloat(0x176B24+0x174*i, true)
		local obj_scaley = memory.readfloat(0x176B28+0x174*i, true)
		      
		local obj_radius = memory.readfloat(0x176B48+0x174*i, true)
		local obj_height = memory.readfloat(0x176B4C+0x174*i, true)
		      
		local obj_yrot = memory.readfloat(0x176B78+0x174*i, true)
	          
		local obj_viewx1 = memory.readfloat(0x176BDC+0x174*i, true)
		local obj_viewx2 = memory.readfloat(0x176BE0+0x174*i, true)
		local obj_viewy1 = memory.readfloat(0x176BE4+0x174*i, true)
		local obj_viewy2 = memory.readfloat(0x176BE8+0x174*i, true)
		local obj_viewz1 = memory.readfloat(0x176BEC+0x174*i, true)
		local obj_viewz2 = memory.readfloat(0x176BF0+0x174*i, true)
		
		local dx = xpos - obj_xpos
		local dz = zpos - obj_zpos
		
		local dx_view1 = xpos - obj_viewx1
		local dx_view2 = xpos - obj_viewx2
		
		local dz_view1 = zpos - obj_viewz1
		local dz_view2 = zpos - obj_viewz2
		
		canv.DrawBox(Xdraw-dx_view1*Zoom, Ydraw-dz_view1*Zoom, Xdraw-dx_view2*Zoom, Ydraw-dz_view2*Zoom, 0xFF00FF00)--+i*0x4973+0x36F4)
		
		
		Xcircle = Xdraw-dx*Zoom-obj_radius*Zoom;
		Ycircle = Ydraw-dz*Zoom-obj_radius*Zoom;
		Diameter =obj_radius*2*Zoom;  
			  	         
		--canv.DrawLine(Xdraw, Ydraw, Xdraw-dx*Zoom, Ydraw-dz*Zoom, 0xFF000000+i*0x4973+0x36F4);
		canv.DrawLine(Xdraw-dx*Zoom, Ydraw-dz*Zoom, Xdraw-(dx*Zoom)+math.sin(obj_yrot*math.pi/180)*obj_radius*Zoom, Ydraw-(dz*Zoom)+math.cos(obj_yrot*math.pi/180)*obj_radius*Zoom, 0xFF00FF00)--+i*0x4973+0x36F4);
		canv.DrawEllipse(Xcircle, Ycircle, Diameter, Diameter, 0xFF00FF00)--+i*0x4973+0x36F4) 

	end

	local mX = canv.GetMouseX()
	local mY = canv.GetMouseY()
	local mButt = input.getmouse()
	
	if mX >= 0 and mX <= size_x and mY >= 0 and mY <= size_y
	then if mButt["Left"]
		 then Xdraw = 400
			  Ydraw = 400
		 elseif mButt["Right"]
			 then dmx = mX - old_mX
				  dmy = mY - old_mY
			  
				  Xdraw = Xdraw + dmx
				  Ydraw = Ydraw + dmy
		 elseif mButt["XButton1"]
			 then Zoom = Zoom*1.10
			 elseif mButt["XButton2"]
				  then Zoom = Zoom*0.90
		 end
	end
	old_mX = mX
	old_mY = mY
	
	canv.Refresh()
	
	emu.yield();
end