Jump to content
IGNORED

Rotate sprite 90 degrees


pwwit1

Recommended Posts

Hello,

 

I think I know the answer to this, Suzi can mirror and flip, but does anyone know if you can use her to rotate a sprite 90 degrees? 

Something like this:

A B C     C F I

D E F =  B E H

G H I     A D G

 

I could do it with the CPU, kind-of like a matrix transpose. If that is the only way to do it, what would be the best way to approach this (for speed) with a screen sized sprite?

Appreciate any thoughts!

 

 

Link to comment
Share on other sites

Just a thought?.

You could  arrange the palette into 2 * 2bit blocks of a 4 bit color sprite so that both images - the original and one shifted 90degrees-

are together in the sprite data. Then you just turn on the relevant palette pens to display either representations.

Of course it will only work for 4 color sprites.

 

 

 

  • Like 1
Link to comment
Share on other sites

Proposal of an algorithm. Seems to work so far; but not sure, if in any cases:

#!/usr/bin/perl

use warnings;
use strict;

sub printArray {
    my @a = @_;
    my $i;
    for ($i=0; $i<=$#a; $i++) {
        print $a[$i];
        if ($i == $#a) {
            print "\n";
        } else {
            print " ";
        }
    }
}

my @a = qw(A B C D E F G H I);

my $lines          = 3;
my $chars_per_line = 3;

my @b = ();
my $s = $chars_per_line - 1;
my ($i, $u, $x);
for ($i=0; $i<$lines; $i++) {
    $x = 0;
    for ($u=0; $u<$chars_per_line; $u++) {
        push(@b, $a[$s + $x]);
        $x += $chars_per_line;
    }
    $s -= 1;
}

printArray(@a);
printArray(@b);

Link to comment
Share on other sites

 

6 hours ago, Pokeypy said:

Proposal of an algorithm. Seems to work so far; but not sure, if in any cases:

Sprite structures cannot be transposed like that as their data structure is heavily dependent on the bits in the sprite data.

Link to comment
Share on other sites

On 6/20/2021 at 2:42 AM, pwwit1 said:

Hello,

 

I think I know the answer to this, Suzi can mirror and flip, but does anyone know if you can use her to rotate a sprite 90 degrees? 

Something like this:

A B C     C F I

D E F =  B E H

G H I     A D G

 

I could do it with the CPU, kind-of like a matrix transpose. If that is the only way to do it, what would be the best way to approach this (for speed) with a screen sized sprite?

Appreciate any thoughts!

 

 

The card space is huge, so why not store the rotated sprite?

Link to comment
Share on other sites

On 6/22/2021 at 2:04 PM, sage said:

It is only a small patch to to the microcode to enable this feature.

firmware.hex 4.7 kB · 13 downloads

How does this work?

 

On 6/21/2021 at 12:12 PM, 42bs said:

The card space is huge, so why not store the rotated sprite?

I'm generating the image at runtime via suzy!

 

On 6/20/2021 at 12:27 PM, karri said:

I would draw the screen with Suzy in normal position and copy the draw buffer to the display buffer with the cpu in the rotated orientation.

Not really what you wanted. But it works.

This is the approach I've taken. Not sure how fast it will be on real hardware though. Trickier than I first thought because of the pixel packing, but it works. Not optimized at all either!

My code is below:



;
; ====================================
; sys_Copy3DScreenWithRotate
; Copes an area of 72x72 and transposes it
; ====================================
sys_CopyScreenWithRotate
	
	ldx #36; inner loop
	ldy #0  ; outer loop

	stz z_C ;  stores the column

	; backup dst address
	lda z_dst_L
	sta z_AL
	lda z_dst_H
	sta z_AH

	lda #0
	sta z_C

.copyline:

	lda z_C
	and #1
	beq .drawLeft
	
	jsr plotRightPixel
	jmp .endPlot
.drawLeft:
	jsr plotLeftPixel
.endPlot:

	jsr sys_NextDstLine
	jsr sys_NextSrcPixel

	dex
	bne .copyline; 

		; Woo! Completed a line!
	
		; Next destination source
		clc
		lda #44; 
		adc z_src_L
		sta z_src_L
		bcc .L3
		inc z_src_H
		.L3:
	
		ldx #36


		lda z_C
		and #1
		beq .skipY
		iny
	.skipY:
		inc z_C
	
		; reset dest Plus next pixel
		clc
		tya
		adc z_AL
		sta z_dst_L
		lda z_AH
		sta z_dst_H
	
		cpy #36; we only do half the vertical lines
		bne .copyline 
	
    rts

sys_NextDstLine
	clc
	lda #80; Divide by two is because each byte is actually two pixels!! So to offset 160 pixels it's actually 80 bytes
	adc z_dst_L
	sta z_dst_L
	bcc .L0 
	inc z_dst_H
	.L0:
	rts

sys_NextSrcPixel
; Next source pixel(16-bit add)
	inc z_src_L
	bne .L1 
	inc z_src_H
	.L1:
	rts

; Plot 2 horizontal pixels (left)
plotLeftPixel
	lda (z_src)  		
	asl
	asl
	asl
	asl
	sta (z_dst)

	jsr sys_NextDstLine

	; Second pixel
	lda (z_src)  
	asl
	asl
	asl
	asl
	sta (z_dst)
	rts

; Plot 2 horizontal pixels (right)
plotRightPixel
	lda (z_src)  		
	and #%00001111	
	ora (z_dst)
	sta (z_dst)

	jsr sys_NextDstLine

	; Second pixel
	lda (z_src) 
	and #%00001111	
	ora (z_dst)
	sta (z_dst)
	rts

 

  • Like 1
Link to comment
Share on other sites

50 minutes ago, pwwit1 said:

This is the approach I've taken. Not sure how fast it will be on real hardware though. Trickier than I first thought because of the pixel packing, but it works. Not optimized at all either!

I used to do it in the driving school program. Printed all text and then converted it into an literal sprite for easy scrolling.

Link to comment
Share on other sites

On 6/30/2021 at 3:36 AM, solo/ng said:

this!

unless you want to pre-rotate tons of sprites already in assets - I would just add another sprite frame rotated by 90. 

 

I'd love to, but it's rotating a 72x72 buffer that is generated at runtime!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...