Hacktoberfest Week 1

This is my first time participating in hacktoberfest! Here’s a small recap of my first PR 🙂

Repo

This year I have been getting into Rust so I used github search to find any issues in a rust repository with the hacktoberfest label. This lea…


This content originally appeared on DEV Community and was authored by Antonio-Bennett

This is my first time participating in hacktoberfest! Here's a small recap of my first PR :)

Repo

This year I have been getting into Rust so I used github search to find any issues in a rust repository with the hacktoberfest label. This lead me to Scion which is a 2d game library written in Rust.

Issue

The problem I had to solve was being able to pivot a rectangle about the center. The relevant issue can be found here

Solution

The first thing I did was the implement the new_with_offset function which creates a new rectangle with the passed offsets. At first I only had 1 offset parameter but that is wrong because a rectangle might have different width and height unlike a square

pub fn new_with_offset(
        width: f32,
        height: f32,
        uvs: Option<[Coordinates; 4]>,
        x_offset: f32,
        y_offset: f32,
    ) -> Self {
        let a = Coordinates::new(0. - x_offset, 0. - y_offset);
        let b = Coordinates::new(a.x(), a.y() + height);
        let c = Coordinates::new(a.x() + width, a.y() + height);
        let d = Coordinates::new(a.x() + width, a.y());
        let uvs_ref = uvs.unwrap_or(default_uvs());
        let contents = [
            TexturedGlVertex::from((&a, &uvs_ref[0])),
            TexturedGlVertex::from((&b, &uvs_ref[1])),
            TexturedGlVertex::from((&c, &uvs_ref[2])),
            TexturedGlVertex::from((&d, &uvs_ref[3])),
        ];
        Self { width, height, vertices: [a, b, c, d], uvs: Some(uvs_ref), contents, dirty: false }
    }

then I called this function from a newly defined pivot function

pub fn pivot(self, pivot: Pivot) -> Self {
        let (x_offset, y_offset) = match pivot {
            Pivot::TopLeft => (0., 0.),
            Pivot::Center => (self.width / 2., self.height / 2.),
        };

        Rectangle::new_with_offset(self.width, self.height, self.uvs, x_offset, y_offset)
    }

I also called use it in the new function

pub fn new(width: f32, height: f32, uvs: Option<[Coordinates; 4]>) -> Self {
        Rectangle::new_with_offset(width, height, uvs, 0., 0.)
    }

The relevant PR can be found here

Thoughts

It was really fun contributing to Scion. I am not really into game development so it was an interesting change of pace to contribute to something I am not familiar with. The experience was fun overall and I am looking forward to contributing to more repos this month :)

Thanks for reading!


This content originally appeared on DEV Community and was authored by Antonio-Bennett


Print Share Comment Cite Upload Translate Updates
APA

Antonio-Bennett | Sciencx (2021-10-08T16:49:29+00:00) Hacktoberfest Week 1. Retrieved from https://www.scien.cx/2021/10/08/hacktoberfest-week-1/

MLA
" » Hacktoberfest Week 1." Antonio-Bennett | Sciencx - Friday October 8, 2021, https://www.scien.cx/2021/10/08/hacktoberfest-week-1/
HARVARD
Antonio-Bennett | Sciencx Friday October 8, 2021 » Hacktoberfest Week 1., viewed ,<https://www.scien.cx/2021/10/08/hacktoberfest-week-1/>
VANCOUVER
Antonio-Bennett | Sciencx - » Hacktoberfest Week 1. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/08/hacktoberfest-week-1/
CHICAGO
" » Hacktoberfest Week 1." Antonio-Bennett | Sciencx - Accessed . https://www.scien.cx/2021/10/08/hacktoberfest-week-1/
IEEE
" » Hacktoberfest Week 1." Antonio-Bennett | Sciencx [Online]. Available: https://www.scien.cx/2021/10/08/hacktoberfest-week-1/. [Accessed: ]
rf:citation
» Hacktoberfest Week 1 | Antonio-Bennett | Sciencx | https://www.scien.cx/2021/10/08/hacktoberfest-week-1/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.