SlideShare a Scribd company logo
An object that moves in a circle
/ A c++ program to check if the given path for a object is circular or not
#include
using namespace std;
// Macros for East, North, South and West
#define N 0
#define E 1
#define S 2
#define W 3
// This function returns true if the given path is circular, else false
bool isCircular(char path[])
{
// Initialize starting point for robot as (0, 0) and starting
// direction as N North
int x = 0, y = 0;
int dir = N;
// Travers the path given for robot
for (int i=0; path[i]; i++)
{
// Find current move
char move = path[i];
// If move is left or right, then change direction
if (move == 'R')
dir = (dir + 1)%4;
else if (move == 'L')
dir = (4 + dir - 1)%4;
// If move is Go, then change x or y according to
// current direction
else // if (move == 'G')
{
if (dir == N)
y++;
else if (dir == E)
x++;
else if (dir == S)
y--;
else // dir == W
x--;
}
}
// If robot comes back to (0, 0), then path is cyclic
return (x == 0 && y == 0);
}
An object that continually rotates
I'm trying to simulate the solar system and need to get the moon to orbit a planet orbiting the sun
i am currently using the following code to rotate the planets
i'm trying to use the code below to make my moon orbit the earth however at the moment all i
can do is rotate around a specific point.
glPushMatrix();
glRotated((GLdouble)(spin*earth.speed), 0.0, 0.0, 1.0);
glTranslated(earth.xPos, earth.yPos, earth.zPos);
earth.draw();
glPopMatrix();
glPushMatrix();
//define one time only start location
bool start = true;
if (start)
{
glTranslated(earthMoon.xPos, earthMoon.yPos, earthMoon.zPos);
start = false;
}
//orbit earths start point
//perfectly fits around earth
glTranslatef(-0.1, -0.1, 0);
glRotatef(spin*10, 0, 0, 1);
glTranslatef(0.1, 0.1, 0);
// need translation vector to follow earth
//glTranslated(earthMoon.xPos, earthMoon.yPos, earthMoon.zPos);
earthMoon.draw();
glPopMatrix();
i think what i need to do is find some way of knowing earths position from the rotatef function.
I have a class for the planets with the following attributes and methods:
float radius;
float xPos;
float yPos;
float zPos;
float speed;
planet(float r, float x, float y, float z, float speed);
~planet();
void draw(void)
{
glPushMatrix();
glColor3f(0.0, 1.0, 1.0);
glutSolidSphere(radius, 20, 10);
glPopMatrix();
}
Solution
An object that moves in a circle
/ A c++ program to check if the given path for a object is circular or not
#include
using namespace std;
// Macros for East, North, South and West
#define N 0
#define E 1
#define S 2
#define W 3
// This function returns true if the given path is circular, else false
bool isCircular(char path[])
{
// Initialize starting point for robot as (0, 0) and starting
// direction as N North
int x = 0, y = 0;
int dir = N;
// Travers the path given for robot
for (int i=0; path[i]; i++)
{
// Find current move
char move = path[i];
// If move is left or right, then change direction
if (move == 'R')
dir = (dir + 1)%4;
else if (move == 'L')
dir = (4 + dir - 1)%4;
// If move is Go, then change x or y according to
// current direction
else // if (move == 'G')
{
if (dir == N)
y++;
else if (dir == E)
x++;
else if (dir == S)
y--;
else // dir == W
x--;
}
}
// If robot comes back to (0, 0), then path is cyclic
return (x == 0 && y == 0);
}
An object that continually rotates
I'm trying to simulate the solar system and need to get the moon to orbit a planet orbiting the sun
i am currently using the following code to rotate the planets
i'm trying to use the code below to make my moon orbit the earth however at the moment all i
can do is rotate around a specific point.
glPushMatrix();
glRotated((GLdouble)(spin*earth.speed), 0.0, 0.0, 1.0);
glTranslated(earth.xPos, earth.yPos, earth.zPos);
earth.draw();
glPopMatrix();
glPushMatrix();
//define one time only start location
bool start = true;
if (start)
{
glTranslated(earthMoon.xPos, earthMoon.yPos, earthMoon.zPos);
start = false;
}
//orbit earths start point
//perfectly fits around earth
glTranslatef(-0.1, -0.1, 0);
glRotatef(spin*10, 0, 0, 1);
glTranslatef(0.1, 0.1, 0);
// need translation vector to follow earth
//glTranslated(earthMoon.xPos, earthMoon.yPos, earthMoon.zPos);
earthMoon.draw();
glPopMatrix();
i think what i need to do is find some way of knowing earths position from the rotatef function.
I have a class for the planets with the following attributes and methods:
float radius;
float xPos;
float yPos;
float zPos;
float speed;
planet(float r, float x, float y, float z, float speed);
~planet();
void draw(void)
{
glPushMatrix();
glColor3f(0.0, 1.0, 1.0);
glutSolidSphere(radius, 20, 10);
glPopMatrix();
}

More Related Content

More from david16271

The three friends have one apple pieEd eats 12Remaining = 12.pdf
The three friends have one apple pieEd eats 12Remaining = 12.pdfThe three friends have one apple pieEd eats 12Remaining = 12.pdf
The three friends have one apple pieEd eats 12Remaining = 12.pdf
david16271
 
Hg2(OH)2 = Mercury(I) hydroxide [Hg2(OH) is not p.pdf
                     Hg2(OH)2 = Mercury(I) hydroxide [Hg2(OH) is not p.pdf                     Hg2(OH)2 = Mercury(I) hydroxide [Hg2(OH) is not p.pdf
Hg2(OH)2 = Mercury(I) hydroxide [Hg2(OH) is not p.pdf
david16271
 
The Most basic duty is to treat humanity, both in your own person, a.pdf
The Most basic duty is to treat humanity, both in your own person, a.pdfThe Most basic duty is to treat humanity, both in your own person, a.pdf
The Most basic duty is to treat humanity, both in your own person, a.pdf
david16271
 
The answer is main bronchi. The trachea bifurcates into the right an.pdf
The answer is main bronchi. The trachea bifurcates into the right an.pdfThe answer is main bronchi. The trachea bifurcates into the right an.pdf
The answer is main bronchi. The trachea bifurcates into the right an.pdf
david16271
 
The Euclidean four-point model with a line that intersects only one .pdf
The Euclidean four-point model with a line that intersects only one .pdfThe Euclidean four-point model with a line that intersects only one .pdf
The Euclidean four-point model with a line that intersects only one .pdf
david16271
 
Session and Presentation Layers are the two OSI layers are missing f.pdf
Session and Presentation Layers are the two OSI layers are missing f.pdfSession and Presentation Layers are the two OSI layers are missing f.pdf
Session and Presentation Layers are the two OSI layers are missing f.pdf
david16271
 
Given that S is a subset of TThis implies that any element is in S.pdf
Given that S is a subset of TThis implies that any element is in S.pdfGiven that S is a subset of TThis implies that any element is in S.pdf
Given that S is a subset of TThis implies that any element is in S.pdf
david16271
 
Na2so4.10H20is a limiting reagent n is the no.of moles of limiting r.pdf
Na2so4.10H20is a limiting reagent n is the no.of moles of limiting r.pdfNa2so4.10H20is a limiting reagent n is the no.of moles of limiting r.pdf
Na2so4.10H20is a limiting reagent n is the no.of moles of limiting r.pdf
david16271
 
Structure of Each Type of linked listSingly Linked Liststruct .pdf
Structure of Each Type of linked listSingly Linked Liststruct .pdfStructure of Each Type of linked listSingly Linked Liststruct .pdf
Structure of Each Type of linked listSingly Linked Liststruct .pdf
david16271
 
public class Donation {          The Donation Id (intege.pdf
public class Donation {            The Donation Id (intege.pdfpublic class Donation {            The Donation Id (intege.pdf
public class Donation {          The Donation Id (intege.pdf
david16271
 
TFTSolutionTFT.pdf
TFTSolutionTFT.pdfTFTSolutionTFT.pdf
TFTSolutionTFT.pdf
david16271
 
reference articel used in this essayKumar, S., & Preetha, G. (2012.pdf
reference articel used in this essayKumar, S., & Preetha, G. (2012.pdfreference articel used in this essayKumar, S., & Preetha, G. (2012.pdf
reference articel used in this essayKumar, S., & Preetha, G. (2012.pdf
david16271
 
New York house producerDJlabelhead Peter Rauhofer had a taste of c.pdf
New York house producerDJlabelhead Peter Rauhofer had a taste of c.pdfNew York house producerDJlabelhead Peter Rauhofer had a taste of c.pdf
New York house producerDJlabelhead Peter Rauhofer had a taste of c.pdf
david16271
 
Lyme disease is caused by bite of infected tick. The bacteria respon.pdf
Lyme disease is caused by bite of infected tick. The bacteria respon.pdfLyme disease is caused by bite of infected tick. The bacteria respon.pdf
Lyme disease is caused by bite of infected tick. The bacteria respon.pdf
david16271
 
E) I Sol.pdf
                     E) I                                      Sol.pdf                     E) I                                      Sol.pdf
E) I Sol.pdf
david16271
 
deltaT(f)=i.Kf().m K(f)=1.86 for water molality=m.pdf
                     deltaT(f)=i.Kf().m K(f)=1.86 for water molality=m.pdf                     deltaT(f)=i.Kf().m K(f)=1.86 for water molality=m.pdf
deltaT(f)=i.Kf().m K(f)=1.86 for water molality=m.pdf
david16271
 
satellite falling to Earth; a teaspoonful of sugar dissolving in a c.pdf
satellite falling to Earth; a teaspoonful of sugar dissolving in a c.pdfsatellite falling to Earth; a teaspoonful of sugar dissolving in a c.pdf
satellite falling to Earth; a teaspoonful of sugar dissolving in a c.pdf
david16271
 
Microsoft Offices Excel application allows users to store, model a.pdf
Microsoft Offices Excel application allows users to store, model a.pdfMicrosoft Offices Excel application allows users to store, model a.pdf
Microsoft Offices Excel application allows users to store, model a.pdf
david16271
 
Pepsi CoFY2014FY2015FY2016Total Revenue ( In $ Bn)66.686.pdf
Pepsi CoFY2014FY2015FY2016Total Revenue ( In $ Bn)66.686.pdfPepsi CoFY2014FY2015FY2016Total Revenue ( In $ Bn)66.686.pdf
Pepsi CoFY2014FY2015FY2016Total Revenue ( In $ Bn)66.686.pdf
david16271
 
Influenza viruses bind through hemagglutinin onto sialic acid sugars.pdf
Influenza viruses bind through hemagglutinin onto sialic acid sugars.pdfInfluenza viruses bind through hemagglutinin onto sialic acid sugars.pdf
Influenza viruses bind through hemagglutinin onto sialic acid sugars.pdf
david16271
 

More from david16271 (20)

The three friends have one apple pieEd eats 12Remaining = 12.pdf
The three friends have one apple pieEd eats 12Remaining = 12.pdfThe three friends have one apple pieEd eats 12Remaining = 12.pdf
The three friends have one apple pieEd eats 12Remaining = 12.pdf
 
Hg2(OH)2 = Mercury(I) hydroxide [Hg2(OH) is not p.pdf
                     Hg2(OH)2 = Mercury(I) hydroxide [Hg2(OH) is not p.pdf                     Hg2(OH)2 = Mercury(I) hydroxide [Hg2(OH) is not p.pdf
Hg2(OH)2 = Mercury(I) hydroxide [Hg2(OH) is not p.pdf
 
The Most basic duty is to treat humanity, both in your own person, a.pdf
The Most basic duty is to treat humanity, both in your own person, a.pdfThe Most basic duty is to treat humanity, both in your own person, a.pdf
The Most basic duty is to treat humanity, both in your own person, a.pdf
 
The answer is main bronchi. The trachea bifurcates into the right an.pdf
The answer is main bronchi. The trachea bifurcates into the right an.pdfThe answer is main bronchi. The trachea bifurcates into the right an.pdf
The answer is main bronchi. The trachea bifurcates into the right an.pdf
 
The Euclidean four-point model with a line that intersects only one .pdf
The Euclidean four-point model with a line that intersects only one .pdfThe Euclidean four-point model with a line that intersects only one .pdf
The Euclidean four-point model with a line that intersects only one .pdf
 
Session and Presentation Layers are the two OSI layers are missing f.pdf
Session and Presentation Layers are the two OSI layers are missing f.pdfSession and Presentation Layers are the two OSI layers are missing f.pdf
Session and Presentation Layers are the two OSI layers are missing f.pdf
 
Given that S is a subset of TThis implies that any element is in S.pdf
Given that S is a subset of TThis implies that any element is in S.pdfGiven that S is a subset of TThis implies that any element is in S.pdf
Given that S is a subset of TThis implies that any element is in S.pdf
 
Na2so4.10H20is a limiting reagent n is the no.of moles of limiting r.pdf
Na2so4.10H20is a limiting reagent n is the no.of moles of limiting r.pdfNa2so4.10H20is a limiting reagent n is the no.of moles of limiting r.pdf
Na2so4.10H20is a limiting reagent n is the no.of moles of limiting r.pdf
 
Structure of Each Type of linked listSingly Linked Liststruct .pdf
Structure of Each Type of linked listSingly Linked Liststruct .pdfStructure of Each Type of linked listSingly Linked Liststruct .pdf
Structure of Each Type of linked listSingly Linked Liststruct .pdf
 
public class Donation {          The Donation Id (intege.pdf
public class Donation {            The Donation Id (intege.pdfpublic class Donation {            The Donation Id (intege.pdf
public class Donation {          The Donation Id (intege.pdf
 
TFTSolutionTFT.pdf
TFTSolutionTFT.pdfTFTSolutionTFT.pdf
TFTSolutionTFT.pdf
 
reference articel used in this essayKumar, S., & Preetha, G. (2012.pdf
reference articel used in this essayKumar, S., & Preetha, G. (2012.pdfreference articel used in this essayKumar, S., & Preetha, G. (2012.pdf
reference articel used in this essayKumar, S., & Preetha, G. (2012.pdf
 
New York house producerDJlabelhead Peter Rauhofer had a taste of c.pdf
New York house producerDJlabelhead Peter Rauhofer had a taste of c.pdfNew York house producerDJlabelhead Peter Rauhofer had a taste of c.pdf
New York house producerDJlabelhead Peter Rauhofer had a taste of c.pdf
 
Lyme disease is caused by bite of infected tick. The bacteria respon.pdf
Lyme disease is caused by bite of infected tick. The bacteria respon.pdfLyme disease is caused by bite of infected tick. The bacteria respon.pdf
Lyme disease is caused by bite of infected tick. The bacteria respon.pdf
 
E) I Sol.pdf
                     E) I                                      Sol.pdf                     E) I                                      Sol.pdf
E) I Sol.pdf
 
deltaT(f)=i.Kf().m K(f)=1.86 for water molality=m.pdf
                     deltaT(f)=i.Kf().m K(f)=1.86 for water molality=m.pdf                     deltaT(f)=i.Kf().m K(f)=1.86 for water molality=m.pdf
deltaT(f)=i.Kf().m K(f)=1.86 for water molality=m.pdf
 
satellite falling to Earth; a teaspoonful of sugar dissolving in a c.pdf
satellite falling to Earth; a teaspoonful of sugar dissolving in a c.pdfsatellite falling to Earth; a teaspoonful of sugar dissolving in a c.pdf
satellite falling to Earth; a teaspoonful of sugar dissolving in a c.pdf
 
Microsoft Offices Excel application allows users to store, model a.pdf
Microsoft Offices Excel application allows users to store, model a.pdfMicrosoft Offices Excel application allows users to store, model a.pdf
Microsoft Offices Excel application allows users to store, model a.pdf
 
Pepsi CoFY2014FY2015FY2016Total Revenue ( In $ Bn)66.686.pdf
Pepsi CoFY2014FY2015FY2016Total Revenue ( In $ Bn)66.686.pdfPepsi CoFY2014FY2015FY2016Total Revenue ( In $ Bn)66.686.pdf
Pepsi CoFY2014FY2015FY2016Total Revenue ( In $ Bn)66.686.pdf
 
Influenza viruses bind through hemagglutinin onto sialic acid sugars.pdf
Influenza viruses bind through hemagglutinin onto sialic acid sugars.pdfInfluenza viruses bind through hemagglutinin onto sialic acid sugars.pdf
Influenza viruses bind through hemagglutinin onto sialic acid sugars.pdf
 

Recently uploaded

Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 

Recently uploaded (20)

Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 

An object that moves in a circle A c++ program to check if the gi.pdf

  • 1. An object that moves in a circle / A c++ program to check if the given path for a object is circular or not #include using namespace std; // Macros for East, North, South and West #define N 0 #define E 1 #define S 2 #define W 3 // This function returns true if the given path is circular, else false bool isCircular(char path[]) { // Initialize starting point for robot as (0, 0) and starting // direction as N North int x = 0, y = 0; int dir = N; // Travers the path given for robot for (int i=0; path[i]; i++) { // Find current move char move = path[i]; // If move is left or right, then change direction if (move == 'R') dir = (dir + 1)%4; else if (move == 'L') dir = (4 + dir - 1)%4; // If move is Go, then change x or y according to // current direction else // if (move == 'G') { if (dir == N) y++; else if (dir == E) x++; else if (dir == S)
  • 2. y--; else // dir == W x--; } } // If robot comes back to (0, 0), then path is cyclic return (x == 0 && y == 0); } An object that continually rotates I'm trying to simulate the solar system and need to get the moon to orbit a planet orbiting the sun i am currently using the following code to rotate the planets i'm trying to use the code below to make my moon orbit the earth however at the moment all i can do is rotate around a specific point. glPushMatrix(); glRotated((GLdouble)(spin*earth.speed), 0.0, 0.0, 1.0); glTranslated(earth.xPos, earth.yPos, earth.zPos); earth.draw(); glPopMatrix(); glPushMatrix(); //define one time only start location bool start = true; if (start) { glTranslated(earthMoon.xPos, earthMoon.yPos, earthMoon.zPos); start = false; } //orbit earths start point //perfectly fits around earth glTranslatef(-0.1, -0.1, 0); glRotatef(spin*10, 0, 0, 1); glTranslatef(0.1, 0.1, 0); // need translation vector to follow earth //glTranslated(earthMoon.xPos, earthMoon.yPos, earthMoon.zPos); earthMoon.draw(); glPopMatrix(); i think what i need to do is find some way of knowing earths position from the rotatef function.
  • 3. I have a class for the planets with the following attributes and methods: float radius; float xPos; float yPos; float zPos; float speed; planet(float r, float x, float y, float z, float speed); ~planet(); void draw(void) { glPushMatrix(); glColor3f(0.0, 1.0, 1.0); glutSolidSphere(radius, 20, 10); glPopMatrix(); } Solution An object that moves in a circle / A c++ program to check if the given path for a object is circular or not #include using namespace std; // Macros for East, North, South and West #define N 0 #define E 1 #define S 2 #define W 3 // This function returns true if the given path is circular, else false bool isCircular(char path[]) { // Initialize starting point for robot as (0, 0) and starting // direction as N North int x = 0, y = 0; int dir = N; // Travers the path given for robot for (int i=0; path[i]; i++)
  • 4. { // Find current move char move = path[i]; // If move is left or right, then change direction if (move == 'R') dir = (dir + 1)%4; else if (move == 'L') dir = (4 + dir - 1)%4; // If move is Go, then change x or y according to // current direction else // if (move == 'G') { if (dir == N) y++; else if (dir == E) x++; else if (dir == S) y--; else // dir == W x--; } } // If robot comes back to (0, 0), then path is cyclic return (x == 0 && y == 0); } An object that continually rotates I'm trying to simulate the solar system and need to get the moon to orbit a planet orbiting the sun i am currently using the following code to rotate the planets i'm trying to use the code below to make my moon orbit the earth however at the moment all i can do is rotate around a specific point. glPushMatrix(); glRotated((GLdouble)(spin*earth.speed), 0.0, 0.0, 1.0); glTranslated(earth.xPos, earth.yPos, earth.zPos); earth.draw(); glPopMatrix(); glPushMatrix();
  • 5. //define one time only start location bool start = true; if (start) { glTranslated(earthMoon.xPos, earthMoon.yPos, earthMoon.zPos); start = false; } //orbit earths start point //perfectly fits around earth glTranslatef(-0.1, -0.1, 0); glRotatef(spin*10, 0, 0, 1); glTranslatef(0.1, 0.1, 0); // need translation vector to follow earth //glTranslated(earthMoon.xPos, earthMoon.yPos, earthMoon.zPos); earthMoon.draw(); glPopMatrix(); i think what i need to do is find some way of knowing earths position from the rotatef function. I have a class for the planets with the following attributes and methods: float radius; float xPos; float yPos; float zPos; float speed; planet(float r, float x, float y, float z, float speed); ~planet(); void draw(void) { glPushMatrix(); glColor3f(0.0, 1.0, 1.0); glutSolidSphere(radius, 20, 10); glPopMatrix(); }