1. Заголовок темы должен быть информативным. В противном случае тема удаляется ... 2. Все тексты программ должны помещаться в теги [code=pas] ... [/code]. 3. Прежде чем задавать вопрос, см. "FAQ", если там не нашли ответа, воспользуйтесь ПОИСКОМ, возможно такую задачу уже решали! 4. Не предлагайте свои решения на других языках, кроме Паскаля (исключение - только с согласия модератора). 5. НЕ используйте форум для личного общения, все что не относится к обсуждению темы - на PM! 6. Одна тема - один вопрос (задача) 7.Проверяйте программы перед тем, как разместить их на форуме!!! 8.Спрашивайте и отвечайте четко и по существу!!!
Прошу помощи. Мне задали сделать тор крутящийся вокруг осей X, Y, Z. Я прочитал статью по 3д графике Altair'а и сделал, но вот проблема - у меня не только тор крутится, но и оси. То есть после поворотов по оси Z и к примеру Y, начинаешь крутить по Х, то он уже крутит под каким-то углом... Объяснить, как то очень сложно. Я говорил с Altair'ом по ICQ, он понял но так ничего и не выслал и не подсказал. Ещё раз прошу помощи, реально закон жизни и смерти, без этого курсовика мне не закрыть сессию.
Сама прога:
Program RotateTor;
uses Crt, Graph, Obj;
var GraphicDriver, GraphicMode, ErrorCode: Integer; rotate_x, rotate_y, rotate_z: Integer; Xan, Yan, Zan: Real; key: Char; Tor: TTor;
begin GraphicDriver:=InstallUserDriver('EGAVGA', @GraphicDriver); GraphicMode:=1; InitGraph(GraphicDriver, GraphicMode, ''); ErrorCode:=GraphResult; if ErrorCode <> grOk then begin Writeln('Graphics error:'); Writeln(GraphErrorMsg(ErrorCode)); Writeln('Program aborted...'); Halt(1); end; rotate_x:=0; rotate_y:=0; rotate_z:=0; Xan:=0; Yan:=0; Zan:=0; Tor.Create(GetMaxX div 2, GetMaxY div 2, 0, 80, 20); Tor.Draw(0,0,0); Flip; repeat if keypressed then begin key:=readkey; if key='z' then begin if rotate_z=0 then rotate_z:=-1; if rotate_z=1 then rotate_z:=0; end; if key='a' then begin if rotate_z=0 then rotate_z:=1; if rotate_z=-1 then rotate_z:=0; end; if key=#0 then begin key:=ReadKey; if key=#75 then begin if rotate_y=0 then rotate_y:=-1; if rotate_y=1 then rotate_y:=0; end; if key=#77 then begin if rotate_y=0 then rotate_y:=1; if rotate_y=-1 then rotate_y:=0; end; if key=#72 then begin if rotate_x=0 then rotate_x:=-1; if rotate_x=1 then rotate_x:=0; end; if key=#80 then begin if rotate_x=0 then rotate_x:=1; if rotate_x=-1 then rotate_x:=0; end; end; end; if rotate_y=-1 then if (Yan > 0) and (Yan <= 360) then Yan:=Yan-10 else Yan:=350; if rotate_y=1 then if (Yan >= 0) and (Yan < 350) then Yan:=Yan+10 else Yan:=0; if rotate_x=-1 then if (Xan > 0) and (Xan <= 360) then Xan:=Xan-10 else Xan:=350; if rotate_x=1 then if (Xan >= 0) and (Xan < 350) then Xan:=Xan+10 else Xan:=0; if rotate_z=-1 then if (Zan > 0) and (Zan <= 360) then Zan:=Zan-10 else Zan:=350; if rotate_z=1 then if (Zan >= 0) and (Zan < 350) then Zan:=Zan+10 else Zan:=0; Tor.Draw(Xan, Yan, Zan); OutTextXY(5, 5, 'To rotate on x press up, down cursor key. X Angle: '+IntToStr(Xan)); OutTextXY(5, 20, 'To rotate on y press left, right cursor key. Y Angle: '+IntToStr(Yan)); OutTextXY(5, 35, 'To rotate on z press "a", "z" key button. Z Angle: '+IntToStr(Zan)); Flip; delay(3000); until key=#13; closegraph; end.
Модуль Obj:
unit Obj;
interface
uses Graph;
const Rad=Pi/180; Page: Word=0;
function IntToStr(I: Real): String; procedure Flip;
type TPixel = object private x, y, z: Integer; screen_x, screen_y, screen_z: Real; public constructor Create(x_, y_, z_: Integer); destructor Destroy; virtual;
procedure TTor.Draw; var i, Angle: Integer; r_temp: Real; begin ClearDevice; r_temp:=(r-r_center); for Angle:=0 to 90 do begin screen_x:=r_temp*(cos(Angle*4*Rad)-sin(Angle*4*Rad)); screen_y:=r_temp*(sin(Angle*4*Rad)+cos(Angle*4*Rad)); screen_z:=z; Calc(Xan, Yan, Zan); SetColor(5); circle(x+round(screen_x), y+round(screen_y), round(r_temp/2)); end; end;