0 Members and 1 Guest are viewing this topic.
function TheGame:timer() local xDif = math.abs(self.movingCardPos[1]-self.defPos[1]) local yDif = math.abs(self.movingCardPos[2]-self.defPos[2]) local dirX = xDif/(self.movingCardPos[1]-self.defPos[1]) if xDif<5 and yDif<5 then timer.stop() table.insert(self.pack, self.movingCard) self.movingCard = nil self.movingCardPos = nil else local tan = math.atan2( yDif, xDif ) if dirX>0 then self.movingCardPos[1] = self.movingCardPos[1]-4*math.cos(tan) else self.movingCardPos[1] = self.movingCardPos[1]+4*math.cos(tan) end self.movingCardPos[2] = self.movingCardPos[2]-4*math.sin(tan) platform.window:invalidate() endend
does math.atan() give the same on calc ?
Also, calling the nspire's math engine gives the same (just for testing, it's way too slow to use for real while in calculations, I guess) ?
local tan = math.atan2(yDif, xDif)local tan = math.atan(yDif/xDif)local tan = tonumber(math.eval(""..math.atan2(yDif,xDif)))local tan = tonumber(math.eval(""..math.atan(yDif/xDif)))
platform.apilevel = '1.0'x = 160y = 120function on.paint(gc) gc:setFont("sansserif","b","8") gc:drawString(math.floor(math.atan2(y,x)*100)/100,0,0,"top") gc:drawString(math.floor(math.atan(y/x)*100)/100,50,0,"top") gc:drawString(x,0,10,"top") gc:drawString(y,0,20,"top")end
function TheGame:timer() local xDif = math.abs(self.movingCardPos[1]-self.defPos[1]) local yDif = math.abs(self.movingCardPos[2]-self.defPos[2]) local dirX = xDif/(self.movingCardPos[1]-self.defPos[1]) if xDif<5 and yDif<5 then timer.stop() table.insert(self.pack, self.movingCard) self.movingCard = nil self.movingCardPos = nil else local tan = math.atan2( yDif, xDif ) --local tan = tonumber(math.eval("arctan("..yDif/xDif..")"),10) if dirX>0 then self.movingCardPos[1] = self.movingCardPos[1]-4*math.cos(tan) else self.movingCardPos[1] = self.movingCardPos[1]+4*math.cos(tan) end self.movingCardPos[2] = self.movingCardPos[2]-4*math.sin(tan) --paintPart(self.movingCardPos[1]-5, self.movingCardPos[2]-5, 60, 90) paint() endendfunction TheGame:paint(gc) if self.movingCard ~= nil then local xDif = math.abs(self.movingCardPos[1]-self.defPos[1]) local yDif = math.abs(self.movingCardPos[2]-self.defPos[2]) local tan = math.atan2( yDif, xDif ) --local tan = math.atan( yDif/xDif ) --local tan = tonumber(math.eval("arctan("..yDif/xDif..")"),10) gc:setFont("sansserif","b","8") gc:drawString(tan,0,0,"top") gc:drawString(self.movingCardPos[1],0,10,"top") gc:drawString(self.movingCardPos[2],0,20,"top") end local img = image.new(Cards[1][1]) for i=1,1 do self.players[i]:paint(gc, i) end self.pack[#self.pack]:paint(gc, (getWidth()-image.width(img))/2, (getHeight()-image.height(img))/3) if self.movingCard ~= nil then self.movingCard:paint(gc, self.movingCardPos[1], self.movingCardPos[2]) endend