Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6866399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:10:43+00:00 2026-05-27T03:10:43+00:00

I have a program that prints the cube and which can be rotated. Here’s

  • 0

I have a program that prints the cube and which can be rotated. Here’s the code.

public partial class ProjectorForm : Form
{
    Projector projector;
    Cube cube;
    float deltaRot;           



    public ProjectorForm()
    {            
        InitializeComponent();

    }

    private void ProjectorForm_Load(object sender, EventArgs e)
    {

        deltaRot = 0.01f;

        projector = new Projector();
        cube = new Cube(Vector3.UnitZ * 20*10, 10*10, 10*10, 15*10);

        updateTimer.Start();
    }

    private void updateTimer_Tick(object sender, EventArgs e)
    {
        if (rotXBox.Checked)
            cube.RotateX(deltaRot);
        if (rotYBox.Checked)
            cube.RotateY(deltaRot);
        if (rotZBox.Checked)
            cube.RotateZ(deltaRot);



        doubleBufferedPanel1.Invalidate();
    }



    private void doubleBufferedPanel1_Paint(object sender, PaintEventArgs e)
    {

        e.Graphics.Clear(Color.White);
        cube.Draw(projector, Color.Black, doubleBufferedPanel1.ClientSize.Width, doubleBufferedPanel1.ClientSize.Height, e.Graphics);


    }

    private void button1_Click(object sender, EventArgs e)
    {
        deltaRot = float.Parse(deltaRotBox.Text);
    }




}

class Projector
{
    public Vector3 cameraPosition;
    public float planeDistance;
    ProjectorForm n = new ProjectorForm();





    public Projector()
    {
        cameraPosition = Vector3.Zero;
        planeDistance = 256; //Here, multiply by 2 and the scaled cube, how to make that scale when you press the button.

    }

    public PointF Project(Vector3 point, float width, float height)
    {
        float x = cameraPosition.X + ((cameraPosition.Z + planeDistance) / (point.Z - cameraPosition.Z)) * (point.X - cameraPosition.X) + width / 2;
        float y = cameraPosition.Y + ((cameraPosition.Z + planeDistance) / (point.Z - cameraPosition.Z)) * (point.Y - cameraPosition.Y) + height / 2;
        return new PointF(x, y);
    }

    public void DrawLine(Color color, Vector3 p1, Vector3 p2, float width, float height, Graphics g)
    {
        g.DrawLine(new Pen(color), Project(p1, width, height), Project(p2, width, height));
    }

    public void FillPolygon(Color color, Vector3[] vertices, float width, float height, Graphics g)
    {
        PointF[] points = new PointF[vertices.Length];
        for (int i = 0; i < points.Length; i++)
            points[i] = Project(vertices[i], width, height);
        g.FillPolygon(new SolidBrush(color), points);
    }
}

How to make a cube can be scaled by pressing a button. I found the variable planeDistance in the class Projector, when it increased by 2 times the cube is scaled, but I do not know how it can be increased by means of a button.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:10:44+00:00Added an answer on May 27, 2026 at 3:10 am

    The field planeDistance is public, so you can change it from outside the class. i.e. just add something like the following to the event handler of a button:

    projector.planeDistance += 10; // Change 10 as appropriate
    

    It’s worth noting that this doesn’t change the size of the cube, it changes how far away the camera is from it. So, while the cube appears to be changing in size, that’s just because the camera is moving closer / further away.


    To actually change the size of the cube you would have to change fields in the cube class.
    Since the size is defined by the vectors created in the constructor you don’t really have an easy way of changing them once the cube is created.

    1. You could create a new cube whenever you want to change the size (keep track of the size in another variable on the form).
    2. You could add a method to the cube class that creates new vectors that define the new size (it would look a bit like the constructor, only populating the arrays, not creating them).
    3. You could add a size field to your cube, always create a unit cube (1, 1, 1) then when rendering multiply each vector by your size.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a (java) program that prints a line of hex numbers to stdout
Hi here is my problem. I have a program that calulcates the averages of
I have a Java program that creates a file and prints a bunch of
I have a program that prints out the location of commas in a paragraph
I have a terribly uncomplicated test program that prints out the following numbers. i.e.
I have a program that executes various shell commands via system() and occasionally prints
I have a simple program that takes an ID number and prints information for
I have this small program that reads a line of input & prints the
I have a C program that prints every environmental variable, whose name is given
I have created a program that prints results on command line. (It is server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.