violet's picture

Draw a star and planet by OPENTK

Project:OpenTK.Text
Component:Code
Category:task
Priority:critical
Assigned:violet
Status:open
Description

Can any body help me for the code to create a star, and a planet that rotates around the star when a user enters the keyboard key R.
Give the star a different color than the planet. Make sure the rotation is not too slow and not too fast.
Use the techniques (Projection matrix, Modelview matrix, GL.PushMatrix(), GL.PopMatrix(), Gl.Rotate(), GL.Translate(), GL.Scale()).
I need help so quickly


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
violet's picture

#1

please I need help quickly

jrwatts's picture

#2

Sorry, but it sounds like you're asking someone to write your homework assignment for you. Perhaps if you asked for help in the specific areas you're having trouble?

flopoloco's picture

#3

I had created this solar system example a couple of months ago for learning purposes. It's not exactly what you wanted but it will give you an 80% boost in your work.

using System;
using System.Drawing;
using OpenTK;
using OpenTK.Graphics.OpenGL;
using OpenTK.Input;
 
namespace HelloOpenTK
{
	public class Program : GameWindow
	{
		#region Camera
 
		Matrix4 matrixProjection, matrixModelview;
 
		#endregion
 
		#region Animation
 
		float orbitDegrees;
		float timeHour, timeDay;
		float animationIncrement = 24;
 
		#endregion
 
		protected override void OnLoad(EventArgs e)
		{
			GL.ClearColor(Color.Black);
			GL.Enable(EnableCap.DepthTest);
			Keyboard.KeyDown += new EventHandler<KeyboardKeyEventArgs>(Keyboard_KeyDown);
		}
 
		void Keyboard_KeyDown(object sender, KeyboardKeyEventArgs e)
		{
			switch (e.Key)
			{
				case Key.Escape:
					Exit();
					break;
 
				case Key.Up:
					animationIncrement *= 2f;
					break;
 
				case Key.Down:
					animationIncrement *= 0.5f;
					break;
			}
		}
 
		protected override void OnResize(EventArgs e)
		{
			GL.Viewport(0, 0, Width, Height);
			matrixProjection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, Width / (float)Height, 1f, 1000f);
			GL.MatrixMode(MatrixMode.Projection);
			GL.LoadMatrix(ref matrixProjection);
		}
 
		protected override void OnUpdateFrame(FrameEventArgs e)
		{
			orbitDegrees += animationIncrement * (float)e.Time;
			if (orbitDegrees > 365f)
				orbitDegrees = 0f;
		}
 
		protected override void OnRenderFrame(FrameEventArgs e)
		{
			GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
 
			#region Camera
 
			matrixModelview = Matrix4.LookAt(0f, 30f, -30f, 0f, 0f, 0f, 0f, 1f, 0f);
			GL.MatrixMode(MatrixMode.Modelview);
			GL.LoadMatrix(ref matrixModelview);
 
			#endregion
 
			#region Draw Sun
 
			GL.Color3(Color.Yellow);
			DrawCube();
 
			#endregion
 
			#region Draw Earth
 
			GL.Rotate(360f * orbitDegrees / 365f, Vector3.UnitY);
			GL.Translate(10f, 0f, 0f);
 
			GL.PushMatrix();
				GL.Rotate(360f * orbitDegrees / 24f, Vector3.UnitY);
				GL.Color3(Color.Blue);
				DrawCube();
			GL.PopMatrix();
 
			#endregion
 
			#region Draw Moon
 
			GL.Rotate(360f * 12f * orbitDegrees / 365f, Vector3.UnitY);
			GL.Translate(5f, 0f, 0f);
			GL.Color3(Color.Silver);
			DrawCube();
 
			#endregion
 
			SwapBuffers();
		}
 
		private void DrawCube()
		{
			GL.Begin(BeginMode.Quads);
 
			GL.Vertex3(-1.0f, -1.0f, -1.0f);
			GL.Vertex3(-1.0f, 1.0f, -1.0f);
			GL.Vertex3(1.0f, 1.0f, -1.0f);
			GL.Vertex3(1.0f, -1.0f, -1.0f);
 
			GL.Vertex3(-1.0f, -1.0f, -1.0f);
			GL.Vertex3(1.0f, -1.0f, -1.0f);
			GL.Vertex3(1.0f, -1.0f, 1.0f);
			GL.Vertex3(-1.0f, -1.0f, 1.0f);
 
			GL.Vertex3(-1.0f, -1.0f, -1.0f);
			GL.Vertex3(-1.0f, -1.0f, 1.0f);
			GL.Vertex3(-1.0f, 1.0f, 1.0f);
			GL.Vertex3(-1.0f, 1.0f, -1.0f);
 
			GL.Vertex3(-1.0f, -1.0f, 1.0f);
			GL.Vertex3(1.0f, -1.0f, 1.0f);
			GL.Vertex3(1.0f, 1.0f, 1.0f);
			GL.Vertex3(-1.0f, 1.0f, 1.0f);
 
			GL.Vertex3(-1.0f, 1.0f, -1.0f);
			GL.Vertex3(-1.0f, 1.0f, 1.0f);
			GL.Vertex3(1.0f, 1.0f, 1.0f);
			GL.Vertex3(1.0f, 1.0f, -1.0f);
 
			GL.Vertex3(1.0f, -1.0f, -1.0f);
			GL.Vertex3(1.0f, 1.0f, -1.0f);
			GL.Vertex3(1.0f, 1.0f, 1.0f);
			GL.Vertex3(1.0f, -1.0f, 1.0f);
 
			GL.End();
		}
 
		[STAThread]
		public static void Main()
		{
			using (Program p = new Program())
			{
				p.Run(80f);
			}
		}
	}
}

Cheers.

violet's picture

#4

jrwatts :actually i tried to do it by my self but I got many errors....
flopoloco :thanks I hope it give me clear idea to solve my problems